Commits

Augie Fackler committed 2ee4c53

revsets: add pushed() and upstream() convenience revsets

pushed() returns the set of revsions known as pushed to any remote
repository by remotebranches. upstream() returns the set of revisions
that have been pushed to paths marked as "upstream" by listing them in
the remotebranches.upstream config field.

  • Participants
  • Parent commits 7ac1cc2

Comments (0)

Files changed (2)

File hg_remotebranches.py

 from mercurial import url
 from mercurial import util
 
+try:
+    from mercurial import revset
+    # force demandimport to load revset
+    revset.methods
+except ImportError:
+   revset = None
+
 from hgext import schemes
 
 def reposetup(ui, repo):
             f.close()
 
     repo.__class__ = remotebranchesrepo
+
+def upstream_revs(filt, repo, subset, x):
+    nodes = [node.hex(n) for name, n in
+             repo._remotebranches.iteritems() if filt(name)]
+    if not nodes: []
+    upstream = reduce(lambda x, y: x.update(y) or x,
+                      map(lambda x: set(revset.ancestors(repo, subset, x)),
+                          [('string', n) for n in nodes]),
+                      set())
+    return [r for r in subset if r in upstream]
+
+def upstream(repo, subset, x):
+    '''``upstream()``
+    Select changesets in an upstream repository according to remotebranches.
+    '''
+    args = revset.getargs(x, 0, 0, "upstream takes no arguments")
+    upstream_names = [s + '/' for s in
+                      repo.ui.configlist('remotebranches', 'upstream')]
+    if not upstream_names:
+        filt = lambda x: True
+    else:
+        filt = lambda name: any(map(name.startswith, upstream_names))
+    return upstream_revs(filt, repo, subset, x)
+
+def pushed(repo, subset, x):
+    '''``pushed()``
+    Select changesets in any remote repository according to remotebranches.
+    '''
+    args = revset.getargs(x, 0, 0, "pushed takes no arguments")
+    return upstream_revs(lambda x: True, repo, subset, x)
+
+if revset is not None:
+    revset.symbols.update({'upstream': upstream,
+                           'pushed': pushed})

File tests/test-remotebranches.t

   
 
 make sure bogus revisions in .hg/remotebranches do not break hg
-  $ echo deadbeefdeadbeefdeadbeefdeadbeefdeadbeef default/default > \
+  $ echo deadbeefdeadbeefdeadbeefdeadbeefdeadbeef default/default >> \
   > .hg/remotebranches
   $ hg parents
   changeset:   6:ce61ec32ee23
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     merging stable
   
+Verify that the revsets operate as expected:
+  $ hg log --graph -r 'not pushed()'
+  @    changeset:   6:ce61ec32ee23
+  |\   tag:         tip
+  | |  parent:      5:6d6442577283
+  | |  parent:      4:8948da77173b
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     merging stable
+  | |
+  | o  changeset:   5:6d6442577283
+  | |  parent:      3:78f83396d79e
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     add e
+  | |
+
+Upstream without configuration is synonymous with pushed():
+  $ hg log --graph -r 'not upstream()'
+  @    changeset:   6:ce61ec32ee23
+  |\   tag:         tip
+  | |  parent:      5:6d6442577283
+  | |  parent:      4:8948da77173b
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     merging stable
+  | |
+  | o  changeset:   5:6d6442577283
+  | |  parent:      3:78f83396d79e
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     add e
+  | |
+
+but configured, it'll do the expected thing:
+  $ echo '[remotebranches]' >> .hg/hgrc
+  $ echo 'upstream=alpha' >> .hg/hgrc
+  $ hg log --graph -r 'not upstream()'
+  @    changeset:   6:ce61ec32ee23
+  |\   tag:         tip
+  | |  parent:      5:6d6442577283
+  | |  parent:      4:8948da77173b
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     merging stable
+  | |
+  | o  changeset:   5:6d6442577283
+  | |  parent:      3:78f83396d79e
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     add e
+  | |
+  o |  changeset:   4:8948da77173b
+  |\|  branch:      stable
+  | |  tag:         beta/stable
+  | |  parent:      2:95cb4ab9fe1d
+  | |  parent:      3:78f83396d79e
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     merged
+  | |
+  | o  changeset:   3:78f83396d79e
+  | |  tag:         beta/default
+  | |  parent:      1:7c3bad9141dc
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     add d
+  | |