15 from mercurial.cmdutil import show_changeset |
15 from mercurial.cmdutil import show_changeset |
16 from mercurial.commands import templateopts |
16 from mercurial.commands import templateopts |
17 from mercurial.i18n import _ |
17 from mercurial.i18n import _ |
18 from mercurial.node import nullrev |
18 from mercurial.node import nullrev |
19 from mercurial import cmdutil, commands, extensions, scmutil |
19 from mercurial import cmdutil, commands, extensions, scmutil |
20 from mercurial import hg, util, graphmod, templatekw |
20 from mercurial import hg, util, graphmod, templatekw, revset |
21 from mercurial import revset as revsetmod |
|
22 |
21 |
23 cmdtable = {} |
22 cmdtable = {} |
24 command = cmdutil.command(cmdtable) |
23 command = cmdutil.command(cmdtable) |
25 |
24 |
26 ASCIIDATA = 'ASC' |
25 ASCIIDATA = 'ASC' |
241 for op in ["newest_first"]: |
240 for op in ["newest_first"]: |
242 if op in opts and opts[op]: |
241 if op in opts and opts[op]: |
243 raise util.Abort(_("-G/--graph option is incompatible with --%s") |
242 raise util.Abort(_("-G/--graph option is incompatible with --%s") |
244 % op.replace("_", "-")) |
243 % op.replace("_", "-")) |
245 |
244 |
246 def makefilematcher(repo, pats, followfirst): |
245 def _makefilematcher(repo, pats, followfirst): |
247 # When displaying a revision with --patch --follow FILE, we have |
246 # When displaying a revision with --patch --follow FILE, we have |
248 # to know which file of the revision must be diffed. With |
247 # to know which file of the revision must be diffed. With |
249 # --follow, we want the names of the ancestors of FILE in the |
248 # --follow, we want the names of the ancestors of FILE in the |
250 # revision, stored in "fcache". "fcache" is populated by |
249 # revision, stored in "fcache". "fcache" is populated by |
251 # reproducing the graph traversal already done by --follow revset |
250 # reproducing the graph traversal already done by --follow revset |
371 opts['_patslog'] = list(pats) |
370 opts['_patslog'] = list(pats) |
372 |
371 |
373 filematcher = None |
372 filematcher = None |
374 if opts.get('patch') or opts.get('stat'): |
373 if opts.get('patch') or opts.get('stat'): |
375 if follow: |
374 if follow: |
376 filematcher = makefilematcher(repo, pats, followfirst) |
375 filematcher = _makefilematcher(repo, pats, followfirst) |
377 else: |
376 else: |
378 filematcher = lambda rev: match |
377 filematcher = lambda rev: match |
379 |
378 |
380 revset = [] |
379 expr = [] |
381 for op, val in opts.iteritems(): |
380 for op, val in opts.iteritems(): |
382 if not val: |
381 if not val: |
383 continue |
382 continue |
384 if op not in opt2revset: |
383 if op not in opt2revset: |
385 continue |
384 continue |
386 revop, andor = opt2revset[op] |
385 revop, andor = opt2revset[op] |
387 if '%(val)' not in revop: |
386 if '%(val)' not in revop: |
388 revset.append(revop) |
387 expr.append(revop) |
389 else: |
388 else: |
390 if not isinstance(val, list): |
389 if not isinstance(val, list): |
391 expr = revop % {'val': val} |
390 e = revop % {'val': val} |
392 else: |
391 else: |
393 expr = '(' + andor.join((revop % {'val': v}) for v in val) + ')' |
392 e = '(' + andor.join((revop % {'val': v}) for v in val) + ')' |
394 revset.append(expr) |
393 expr.append(e) |
395 |
394 |
396 if revset: |
395 if expr: |
397 revset = '(' + ' and '.join(revset) + ')' |
396 expr = '(' + ' and '.join(expr) + ')' |
398 else: |
397 else: |
399 revset = None |
398 expr = None |
400 return revset, filematcher |
399 return expr, filematcher |
401 |
400 |
402 def getlogrevs(repo, pats, opts): |
401 def getlogrevs(repo, pats, opts): |
403 """Return (revs, expr, filematcher) where revs is a list of |
402 """Return (revs, expr, filematcher) where revs is a list of |
404 revision numbers, expr is a revset string built from log options |
403 revision numbers, expr is a revset string built from log options |
405 and file patterns or None, and used to filter 'revs'. If --stat or |
404 and file patterns or None, and used to filter 'revs'. If --stat or |
424 expr, filematcher = _makelogrevset(repo, pats, opts, revs) |
423 expr, filematcher = _makelogrevset(repo, pats, opts, revs) |
425 if expr: |
424 if expr: |
426 # Evaluate revisions in changelog order for performance |
425 # Evaluate revisions in changelog order for performance |
427 # reasons but preserve the original sequence order in the |
426 # reasons but preserve the original sequence order in the |
428 # filtered result. |
427 # filtered result. |
429 matched = set(revsetmod.match(repo.ui, expr)(repo, sorted(revs))) |
428 matched = set(revset.match(repo.ui, expr)(repo, sorted(revs))) |
430 revs = [r for r in revs if r in matched] |
429 revs = [r for r in revs if r in matched] |
431 return revs, expr, filematcher |
430 return revs, expr, filematcher |
432 |
431 |
433 def generate(ui, dag, displayer, showparents, edgefn, getrenamed=None, |
432 def generate(ui, dag, displayer, showparents, edgefn, getrenamed=None, |
434 filematcher=None): |
433 filematcher=None): |