Show More
@@ -179,39 +179,61 b' def walkchangerevs(ui, repo, pats, opts)' | |||||
179 |
|
179 | |||
180 | revrangesep = ':' |
|
180 | revrangesep = ':' | |
181 |
|
181 | |||
182 |
def rev |
|
182 | def revfix(repo, val, defval): | |
183 | """Yield revision as strings from a list of revision specifications.""" |
|
183 | '''turn user-level id of changeset into rev number. | |
184 | if revlog is None: |
|
184 | user-level id can be tag, changeset, rev number, or negative rev | |
185 | revlog = repo.changelog |
|
185 | number relative to number of revs (-1 is tip, etc).''' | |
186 | revcount = revlog.count() |
|
186 | if not val: | |
187 | def fix(val, defval): |
|
187 | return defval | |
188 | if not val: |
|
188 | try: | |
189 | return defval |
|
189 | num = int(val) | |
|
190 | if str(num) != val: | |||
|
191 | raise ValueError | |||
|
192 | if num < 0: | |||
|
193 | num += repo.changelog.count() | |||
|
194 | if num < 0: | |||
|
195 | num = 0 | |||
|
196 | elif num >= repo.changelog.count(): | |||
|
197 | raise ValueError | |||
|
198 | except ValueError: | |||
190 | try: |
|
199 | try: | |
191 |
num = |
|
200 | num = repo.changelog.rev(repo.lookup(val)) | |
192 | if str(num) != val: |
|
201 | except KeyError: | |
193 | raise ValueError |
|
202 | raise util.Abort(_('invalid revision identifier %s'), val) | |
194 | if num < 0: |
|
203 | return num | |
195 | num += revcount |
|
204 | ||
196 | if num < 0: |
|
205 | def revpair(ui, repo, revs): | |
197 | num = 0 |
|
206 | '''return pair of nodes, given list of revisions. second item can | |
198 | elif num >= revcount: |
|
207 | be None, meaning use working dir.''' | |
199 | raise ValueError |
|
208 | if not revs: | |
200 | except ValueError: |
|
209 | return repo.dirstate.parents()[0], None | |
201 | try: |
|
210 | end = None | |
202 | num = repo.changelog.rev(repo.lookup(val)) |
|
211 | if len(revs) == 1: | |
203 | except KeyError: |
|
212 | start = revs[0] | |
204 | try: |
|
213 | if revrangesep in start: | |
205 | num = revlog.rev(revlog.lookup(val)) |
|
214 | start, end = start.split(revrangesep, 1) | |
206 | except KeyError: |
|
215 | start = revfix(repo, start, 0) | |
207 | raise util.Abort(_('invalid revision identifier %s'), val) |
|
216 | end = revfix(repo, end, repo.changelog.count() - 1) | |
208 | return num |
|
217 | else: | |
|
218 | start = revfix(repo, start, None) | |||
|
219 | elif len(revs) == 2: | |||
|
220 | if revrangesep in revs[0] or revrangesep in revs[1]: | |||
|
221 | raise util.Abort(_('too many revisions specified')) | |||
|
222 | start = revfix(repo, revs[0], None) | |||
|
223 | end = revfix(repo, revs[1], None) | |||
|
224 | else: | |||
|
225 | raise util.Abort(_('too many revisions specified')) | |||
|
226 | if end is not None: end = repo.lookup(str(end)) | |||
|
227 | return repo.lookup(str(start)), end | |||
|
228 | ||||
|
229 | def revrange(ui, repo, revs): | |||
|
230 | """Yield revision as strings from a list of revision specifications.""" | |||
209 | seen = {} |
|
231 | seen = {} | |
210 | for spec in revs: |
|
232 | for spec in revs: | |
211 | if spec.find(revrangesep) >= 0: |
|
233 | if spec.find(revrangesep) >= 0: | |
212 | start, end = spec.split(revrangesep, 1) |
|
234 | start, end = spec.split(revrangesep, 1) | |
213 | start = fix(start, 0) |
|
235 | start = revfix(repo, start, 0) | |
214 |
end = fix(end, re |
|
236 | end = revfix(repo, end, repo.changelog.count() - 1) | |
215 | step = start > end and -1 or 1 |
|
237 | step = start > end and -1 or 1 | |
216 | for rev in xrange(start, end+step, step): |
|
238 | for rev in xrange(start, end+step, step): | |
217 | if rev in seen: |
|
239 | if rev in seen: | |
@@ -219,7 +241,7 b' def revrange(ui, repo, revs, revlog=None' | |||||
219 | seen[rev] = 1 |
|
241 | seen[rev] = 1 | |
220 | yield str(rev) |
|
242 | yield str(rev) | |
221 | else: |
|
243 | else: | |
222 | rev = fix(spec, None) |
|
244 | rev = revfix(repo, spec, None) | |
223 | if rev in seen: |
|
245 | if rev in seen: | |
224 | continue |
|
246 | continue | |
225 | seen[rev] = 1 |
|
247 | seen[rev] = 1 | |
@@ -1361,15 +1383,7 b' def diff(ui, repo, *pats, **opts):' | |||||
1361 | it detects as binary. With -a, diff will generate a diff anyway, |
|
1383 | it detects as binary. With -a, diff will generate a diff anyway, | |
1362 | probably with undesirable results. |
|
1384 | probably with undesirable results. | |
1363 | """ |
|
1385 | """ | |
1364 |
node1, node2 = |
|
1386 | node1, node2 = revpair(ui, repo, opts['rev']) | |
1365 | revs = [repo.lookup(x) for x in opts['rev']] |
|
|||
1366 |
|
||||
1367 | if len(revs) > 0: |
|
|||
1368 | node1 = revs[0] |
|
|||
1369 | if len(revs) > 1: |
|
|||
1370 | node2 = revs[1] |
|
|||
1371 | if len(revs) > 2: |
|
|||
1372 | raise util.Abort(_("too many revisions to diff")) |
|
|||
1373 |
|
1387 | |||
1374 | fns, matchfn, anypats = matchpats(repo, pats, opts) |
|
1388 | fns, matchfn, anypats = matchpats(repo, pats, opts) | |
1375 |
|
1389 |
General Comments 0
You need to be logged in to leave comments.
Login now