Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(470)

Side by Side Diff: hgreview/__init__.py

Issue 5517062: hgreview: Add support for mercurial < 1.9 (tested on 1.6) (Closed)
Patch Set: Created 13 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This file is part of hgreview. The COPYRIGHT file at the top level of this 1 # This file is part of hgreview. The COPYRIGHT file at the top level of this
2 # repository contains the full copyright notices and license terms. 2 # repository contains the full copyright notices and license terms.
3 3
4 import os 4 import os
5 import re 5 import re
6 import sys 6 import sys
7 import formatter 7 import formatter
8 import htmllib 8 import htmllib
9 import urllib 9 import urllib
10 from hashlib import md5 10 from hashlib import md5
11 11
12 from mercurial import scmutil, patch, mdiff, copies, node, commands 12 from mercurial.__version__ import version as mercurial_version
13 from mercurial import patch, mdiff, copies, node, commands
14
15 try:
16 test = map(int, mercurial_version.split('.')) >= [1, 9]
17 except ValueError:
18 test = True
19 if test:
20 from mercurial.scmutil import revpair, matchfiles
21 else:
22 from mercurial.cmdutil import revpair, matchfiles
23
13 24
14 from rietveld import (GetEmail, GetRpcServer, CheckReviewer, MAX_UPLOAD_SIZE, 25 from rietveld import (GetEmail, GetRpcServer, CheckReviewer, MAX_UPLOAD_SIZE,
15 EncodeMultipartFormData, UploadSeparatePatches, UploadBaseFiles) 26 EncodeMultipartFormData, UploadSeparatePatches, UploadBaseFiles)
16 27
17 28
18 RAW_PATCH_HREF = re.compile('.*/issue[0-9]+_([0-9])+.diff$') 29 RAW_PATCH_HREF = re.compile('.*/issue[0-9]+_([0-9])+.diff$')
19 30
20 31
21 class CodereviewParser(htmllib.HTMLParser): 32 class CodereviewParser(htmllib.HTMLParser):
22 33
(...skipping 25 matching lines...) Expand all
48 issue_file = _get_issue_file(repo) 59 issue_file = _get_issue_file(repo)
49 if os.path.isfile(issue_file): 60 if os.path.isfile(issue_file):
50 return open(issue_file, 'r').read().strip() 61 return open(issue_file, 'r').read().strip()
51 62
52 def _get_server(ui): 63 def _get_server(ui):
53 return ui.config('review', 'server', 64 return ui.config('review', 'server',
54 default='http://codereview.appspot.com') 65 default='http://codereview.appspot.com')
55 66
56 def review(ui, repo, *args, **opts): 67 def review(ui, repo, *args, **opts):
57 revs = [opts['rev']] if opts['rev'] else [] 68 revs = [opts['rev']] if opts['rev'] else []
58 node1, node2 = scmutil.revpair(repo, revs) 69 node1, node2 = revpair(repo, revs)
59 modified, added, removed, deleted, unknown, ignored, clean = \ 70 modified, added, removed, deleted, unknown, ignored, clean = \
60 repo.status(node1, node2, unknown=True) 71 repo.status(node1, node2, unknown=True)
61 if opts['fetch']: 72 if opts['fetch']:
62 if modified or added or removed or deleted or unknown: 73 if modified or added or removed or deleted or unknown:
63 ui.warn('The repository is not clean.', '\n') 74 ui.warn('The repository is not clean.', '\n')
64 sys.exit(1) 75 sys.exit(1)
65 if not opts.get('issue'): 76 if not opts.get('issue'):
66 issue_id = _get_issue_id(repo) 77 issue_id = _get_issue_id(repo)
67 if not issue_id: 78 if not issue_id:
68 ui.status('No .hg/review_id found', '\n') 79 ui.status('No .hg/review_id found', '\n')
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 143
133 # getting informations about copied/moved files 144 # getting informations about copied/moved files
134 copymove_info = copies.copies(repo, base_rev, current_rev, null_rev)[0] 145 copymove_info = copies.copies(repo, base_rev, current_rev, null_rev)[0]
135 for newname, oldname in copymove_info.items(): 146 for newname, oldname in copymove_info.items():
136 oldcontent = base_rev[oldname].data() 147 oldcontent = base_rev[oldname].data()
137 newcontent = current_rev[newname].data() 148 newcontent = current_rev[newname].data()
138 is_binary = "\0" in oldcontent or "\0" in newcontent 149 is_binary = "\0" in oldcontent or "\0" in newcontent
139 files[newname] = (oldcontent, newcontent, is_binary, 'M') 150 files[newname] = (oldcontent, newcontent, is_binary, 'M')
140 151
141 # modified files 152 # modified files
142 for filename in scmutil.matchfiles(repo, modified): 153 for filename in matchfiles(repo, modified):
143 oldcontent = base_rev[filename].data() 154 oldcontent = base_rev[filename].data()
144 newcontent = current_rev[filename].data() 155 newcontent = current_rev[filename].data()
145 is_binary = "\0" in oldcontent or "\0" in newcontent 156 is_binary = "\0" in oldcontent or "\0" in newcontent
146 files[filename] = (oldcontent, newcontent, is_binary, 'M') 157 files[filename] = (oldcontent, newcontent, is_binary, 'M')
147 158
148 # added files 159 # added files
149 for filename in scmutil.matchfiles(repo, added): 160 for filename in matchfiles(repo, added):
150 oldcontent = '' 161 oldcontent = ''
151 newcontent = current_rev[filename].data() 162 newcontent = current_rev[filename].data()
152 is_binary = "\0" in newcontent 163 is_binary = "\0" in newcontent
153 files[filename] = (oldcontent, newcontent, is_binary, 'A') 164 files[filename] = (oldcontent, newcontent, is_binary, 'A')
154 165
155 # removed files 166 # removed files
156 for filename in scmutil.matchfiles(repo, removed): 167 for filename in matchfiles(repo, removed):
157 if filename in copymove_info.values(): 168 if filename in copymove_info.values():
158 # file has been moved or copied 169 # file has been moved or copied
159 continue 170 continue
160 oldcontent = base_rev[filename].data() 171 oldcontent = base_rev[filename].data()
161 newcontent = '' 172 newcontent = ''
162 is_binary = "\0" in oldcontent 173 is_binary = "\0" in oldcontent
163 files[filename] = (oldcontent, newcontent, is_binary, 'R') 174 files[filename] = (oldcontent, newcontent, is_binary, 'R')
164 175
165 server = _get_server(ui) 176 server = _get_server(ui)
166 ui.status('Server used %s' % server, '\n') 177 ui.status('Server used %s' % server, '\n')
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 ('r', 'reviewers', [], 'Add reviewers'), 259 ('r', 'reviewers', [], 'Add reviewers'),
249 ('i', 'issue', '', 'Issue number. Defaults to new issue'), 260 ('i', 'issue', '', 'Issue number. Defaults to new issue'),
250 ('m', 'message', '', 'Codereview message'), 261 ('m', 'message', '', 'Codereview message'),
251 ('', 'rev', '', 'Revision number to diff against'), 262 ('', 'rev', '', 'Revision number to diff against'),
252 ('', 'send_email', None, 'Send notification email to reviewers'), 263 ('', 'send_email', None, 'Send notification email to reviewers'),
253 ('', 'id', None, 'ouput issue id'), 264 ('', 'id', None, 'ouput issue id'),
254 ('', 'url', None, 'ouput issue URL'), 265 ('', 'url', None, 'ouput issue URL'),
255 ('', 'fetch', None, 'Fetch patch and apply to repository'), 266 ('', 'fetch', None, 'Fetch patch and apply to repository'),
256 ], "hg review [options]"), 267 ], "hg review [options]"),
257 } 268 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b