Review Board

beta

Patch: Enable support for paths with spaces in Mercurial (hg) diff parser

Updated 4 months, 3 weeks ago

Derek Slager Reviewers
reviewboard
541
None Review Board SVN
Enables the Mercurial diff parser to handle file paths with spaces.

I don't know Python, and was therefore "coding by Google", so please expect to find some issues.

Update: diff #2 comes with proposed changes generously applied by bboissin (via http://code.google.com/p/reviewboard/issues/detail?id=541)
Tested locally on Debian with various changesets that do and do not include paths with spaces.

Diff revision 2 (Latest)

1 2
1 2

  1. trunk/reviewboard/scmtools/hg.py: 7 changes [ 1 2 3 4 5 6 7 ]
trunk/reviewboard/scmtools/hg.py
Revision 1414 New Change
38
    This class is able to extract Mercurial changeset ids, and
38
    This class is able to extract Mercurial changeset ids, and
39
    replaces /dev/null with a useful name
39
    replaces /dev/null with a useful name
40
    """
40
    """
41
41
42
    def parse_special_header(self, linenum, info):
42
    def parse_special_header(self, linenum, info):
43
        # XXX: does not handle git style diffs
43
        if self.lines[linenum].startswith("diff -r"):
44
        if self.lines[linenum].startswith("diff -r"):
44
            # should contain "diff -r aaa [-r bbb] filename"
45
            # diff between two revisions are in the following form:
46
            #  "diff -r abcdef123456 -r 123456abcdef filename"
47
            # diff between a revision and the working copy are like:
48
            #  "diff -r abcdef123456 filename"
45
            diffLine = self.lines[linenum].split()
49
            diffLine = self.lines[linenum].split()
46
            try:
50
            try:
47
                # hg is file based, so new file always == old file
51
                # hg is file based, so new file always == old file
48
                info['newFile'] = info['origFile'] = diffLine[-1]
52
                isCommitted = len(diffLine) > 4 and diffLine[3] == '-r'
49
                info['origInfo'] = diffLine[2]
53
                if isCommitted:
50
                if len(diffLine) <= 4:
54
                    nameStartIndex = 5
51
                    info['newInfo'] = "Uncommitted"
52
                else:
53
                    info['newInfo'] = diffLine[4]
55
                    info['newInfo'] = diffLine[4]
56
                else:
57
                    nameStartIndex = 3
58
                    info['newInfo'] = "Uncommitted"
59
                info['newFile'] = info['origFile'] = \
60
                    ' '.join(diffLine[nameStartIndex:])
61
                info['origInfo'] = diffLine[2]
54
            except ValueError:
62
            except ValueError:
55
                raise DiffParserError("The diff file is missing revision information",
63
                raise DiffParserError("The diff file is missing revision information",
56
                                      linenum)
64
                                      linenum)
57
            linenum += 1;
65
            linenum += 1;
58
66
88
        try:
96
        try:
89
            passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
97
            passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
90
            passman.add_password(None, self.url, self.username, self.password)
98
            passman.add_password(None, self.url, self.username, self.password)
91
            authhandler = urllib2.HTTPBasicAuthHandler(passman)
99
            authhandler = urllib2.HTTPBasicAuthHandler(passman)
92
            opener = urllib2.build_opener(authhandler)
100
            opener = urllib2.build_opener(authhandler)
93
            f = opener.open('%s/raw-file/%s/%s' % (self.url, rev, path))
101
            f = opener.open('%s/raw-file/%s/%s' % (self.url, rev, urllib.quote(path)))
94
            return f.read()
102
            return f.read()
95
        except Exception, e:
103
        except Exception, e:
96
            raise FileNotFoundError(path, rev, str(e))
104
            raise FileNotFoundError(path, rev, str(e))
97
105
98
    def get_filenames(self, rev):
106
    def get_filenames(self, rev):
  1. trunk/reviewboard/scmtools/hg.py: 7 changes [ 1 2 3 4 5 6 7 ]