# HG changeset patch # User liscju # Date 2015-08-20 15:19:32 # Node ID 5618858dce2675a441733d49d79c5f389b8aaa34 # Parent 5706d130ec1688d984857d26eef39944613cece1 revsets: makes follow() supports file patterns (issue4757) (BC) Before this patch, follow only supports full, exact filenames. This patch makes follow argument to be treated like file pattern same way like log treats their arguments. It preserves current behaviour of follow() matching paths relative to the repository root by default. diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -1039,34 +1039,37 @@ def first(repo, subset, x): return limit(repo, subset, x) def _follow(repo, subset, x, name, followfirst=False): - l = getargs(x, 0, 1, _("%s takes no arguments or a filename") % name) + l = getargs(x, 0, 1, _("%s takes no arguments or a pattern") % name) c = repo['.'] if l: - x = getstring(l[0], _("%s expected a filename") % name) - if x in c: - cx = c[x] - s = set(ctx.rev() for ctx in cx.ancestors(followfirst=followfirst)) - # include the revision responsible for the most recent version - s.add(cx.introrev()) - else: - return baseset() + x = getstring(l[0], _("%s expected a pattern") % name) + matcher = matchmod.match(repo.root, repo.getcwd(), [x], + ctx=repo[None], default='path') + + s = set() + for fname in c: + if matcher(fname): + fctx = c[fname] + s = s.union(set(c.rev() for c in fctx.ancestors(followfirst))) + # include the revision responsible for the most recent version + s.add(fctx.introrev()) else: s = _revancestors(repo, baseset([c.rev()]), followfirst) return subset & s def follow(repo, subset, x): - """``follow([file])`` + """``follow([pattern])`` An alias for ``::.`` (ancestors of the working directory's first parent). - If a filename is specified, the history of the given file is followed, - including copies. + If pattern is specified, the histories of files matching given + pattern is followed, including copies. """ return _follow(repo, subset, x, 'follow') def _followfirst(repo, subset, x): - # ``followfirst([file])`` - # Like ``follow([file])`` but follows only the first parent of - # every revision or file revision. + # ``followfirst([pattern])`` + # Like ``follow([pattern])`` but follows only the first parent of + # every revisions or files revisions. return _follow(repo, subset, x, '_followfirst', followfirst=True) def getall(repo, subset, x): diff --git a/tests/test-log.t b/tests/test-log.t --- a/tests/test-log.t +++ b/tests/test-log.t @@ -620,6 +620,21 @@ log --follow tests $ hg up -C 1 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ echo b1 > b1 + +log -r "follow('set:clean()')" + + $ hg log -r "follow('set:clean()')" + changeset: 0:67e992f2c4f3 + user: test + date: Thu Jan 01 00:00:01 1970 +0000 + summary: base + + changeset: 1:3d5bf5654eda + user: test + date: Thu Jan 01 00:00:01 1970 +0000 + summary: r1 + + $ hg ci -Amb1 -d '1 0' adding b1 created new head @@ -646,7 +661,26 @@ log -f summary: base +log -r follow('glob:b*') + $ hg log -r "follow('glob:b*')" + changeset: 0:67e992f2c4f3 + user: test + date: Thu Jan 01 00:00:01 1970 +0000 + summary: base + + changeset: 1:3d5bf5654eda + user: test + date: Thu Jan 01 00:00:01 1970 +0000 + summary: r1 + + changeset: 3:e62f78d544b4 + tag: tip + parent: 1:3d5bf5654eda + user: test + date: Thu Jan 01 00:00:01 1970 +0000 + summary: b1 + log -f -r '1 + 4' $ hg up -C 0 @@ -673,6 +707,16 @@ log -f -r '1 + 4' date: Thu Jan 01 00:00:01 1970 +0000 summary: base +log -r "follow('set:grep(b2)')" + + $ hg log -r "follow('set:grep(b2)')" + changeset: 4:ddb82e70d1a1 + tag: tip + parent: 0:67e992f2c4f3 + user: test + date: Thu Jan 01 00:00:01 1970 +0000 + summary: b2 + log -f -r null $ hg log -f -r null