Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/commands.py @ 2331:953dbfb2824c
diff: allow to use -rA:B syntax as well as -rA -rB
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Sun, 21 May 2006 23:07:19 -0700 |
parents | b30aa02c85e7 |
children | f0680b2d1d64 |
comparison
equal
deleted
inserted
replaced
2330:b30aa02c85e7 | 2331:953dbfb2824c |
---|---|
177 yield 'iter', rev, None | 177 yield 'iter', rev, None |
178 return iterate(), getchange, matchfn | 178 return iterate(), getchange, matchfn |
179 | 179 |
180 revrangesep = ':' | 180 revrangesep = ':' |
181 | 181 |
182 def revrange(ui, repo, revs, revlog=None): | 182 def revfix(repo, val, defval): |
183 '''turn user-level id of changeset into rev number. | |
184 user-level id can be tag, changeset, rev number, or negative rev | |
185 number relative to number of revs (-1 is tip, etc).''' | |
186 if not val: | |
187 return defval | |
188 try: | |
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: | |
199 try: | |
200 num = repo.changelog.rev(repo.lookup(val)) | |
201 except KeyError: | |
202 raise util.Abort(_('invalid revision identifier %s'), val) | |
203 return num | |
204 | |
205 def revpair(ui, repo, revs): | |
206 '''return pair of nodes, given list of revisions. second item can | |
207 be None, meaning use working dir.''' | |
208 if not revs: | |
209 return repo.dirstate.parents()[0], None | |
210 end = None | |
211 if len(revs) == 1: | |
212 start = revs[0] | |
213 if revrangesep in start: | |
214 start, end = start.split(revrangesep, 1) | |
215 start = revfix(repo, start, 0) | |
216 end = revfix(repo, end, repo.changelog.count() - 1) | |
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): | |
183 """Yield revision as strings from a list of revision specifications.""" | 230 """Yield revision as strings from a list of revision specifications.""" |
184 if revlog is None: | |
185 revlog = repo.changelog | |
186 revcount = revlog.count() | |
187 def fix(val, defval): | |
188 if not val: | |
189 return defval | |
190 try: | |
191 num = int(val) | |
192 if str(num) != val: | |
193 raise ValueError | |
194 if num < 0: | |
195 num += revcount | |
196 if num < 0: | |
197 num = 0 | |
198 elif num >= revcount: | |
199 raise ValueError | |
200 except ValueError: | |
201 try: | |
202 num = repo.changelog.rev(repo.lookup(val)) | |
203 except KeyError: | |
204 try: | |
205 num = revlog.rev(revlog.lookup(val)) | |
206 except KeyError: | |
207 raise util.Abort(_('invalid revision identifier %s'), val) | |
208 return num | |
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, revcount - 1) | 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: |
218 continue | 240 continue |
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 |
226 yield str(rev) | 248 yield str(rev) |
227 | 249 |
1359 | 1381 |
1360 Without the -a option, diff will avoid generating diffs of files | 1382 Without the -a option, diff will avoid generating diffs of files |
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 = None, None | 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 |
1376 dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, | 1390 dodiff(sys.stdout, ui, repo, node1, node2, fns, match=matchfn, |
1377 text=opts['text'], opts=opts) | 1391 text=opts['text'], opts=opts) |