# HG changeset patch # User David M. Carr # Date 1345693185 14400 # Node ID d2caea2696703a711f250f0ba79da5096ed3f419 # Parent 00d591868a2ffd126f9abc46f616e1e64b191398 revsets: add fromgit and gitnode selectors Support for Hg 1.5.4 was removed, as it doesn't support revsets and is older than the earliest version we want to put special effort into supporting. diff --git a/Makefile b/Makefile --- a/Makefile +++ b/Makefile @@ -25,8 +25,8 @@ # latest Ubuntu LTS release (2.0.2 for 12.04 LTS) may be dropped if they # interfere with new development. The latest released minor version should be # listed for each major version; earlier minor versions are not needed. -all-version-tests: tests-1.5.4 tests-1.6.4 tests-1.7.5 tests-1.8.4 \ - tests-1.9.3 tests-2.0.2 tests-2.1.2 tests-2.2.3 \ - tests-2.3 tests-tip +all-version-tests: tests-1.6.4 tests-1.7.5 tests-1.8.4 tests-1.9.3 \ + tests-2.0.2 tests-2.1.2 tests-2.2.3 tests-2.3 \ + tests-tip .PHONY: tests all-version-tests diff --git a/README.md b/README.md --- a/README.md +++ b/README.md @@ -141,7 +141,6 @@ is not compulsory, but it makes some things a bit nicer for you. This plugin is currently tested against the following Mercurial versions: - * 1.5.4 * 1.6.4 * 1.7.5 * 1.8.4 diff --git a/hggit/__init__.py b/hggit/__init__.py --- a/hggit/__init__.py +++ b/hggit/__init__.py @@ -28,6 +28,7 @@ from mercurial import help from mercurial import hg from mercurial import localrepo +from mercurial import revset from mercurial import templatekw from mercurial import util as hgutil from mercurial import url @@ -94,6 +95,9 @@ def extsetup(): templatekw.keywords.update({'gitnode': gitnodekw}) + revset.symbols.update({ + 'fromgit': revset_fromgit, 'gitnode': revset_gitnode + }) helpdir = os.path.join(os.path.dirname(__file__), 'help') entry = (['git'], _("Working with Git Repositories"), lambda: open(os.path.join(helpdir, 'git.rst')).read()) @@ -177,6 +181,29 @@ # 1.7+ pass +def revset_fromgit(repo, subset, x): + '''``fromgit()`` + Select changesets that originate from Git. + ''' + args = revset.getargs(x, 0, 0, "fromgit takes no arguments") + git = GitHandler(repo, repo.ui) + return [r for r in subset if git.map_git_get(repo[r].hex()) is not None] + +def revset_gitnode(repo, subset, x): + '''``gitnode(hash)`` + Select changesets that originate in the given Git revision. + ''' + args = revset.getargs(x, 1, 1, "gitnode takes one argument") + rev = revset.getstring(args[0], + "the argument to gitnode() must be a hash") + git = GitHandler(repo, repo.ui) + def matches(r): + gitnode = git.map_git_get(repo[r].hex()) + if gitnode is None: + return False + return rev in [gitnode, gitnode[:12]] + return [r for r in subset if matches(r)] + def gitnodekw(**args): """:gitnode: String. The Git changeset identification hash, as a 40 hexadecimal digit string.""" node = args['ctx'] diff --git a/hggit/help/git.rst b/hggit/help/git.rst --- a/hggit/help/git.rst +++ b/hggit/help/git.rst @@ -58,6 +58,21 @@ $ hg log --template='{rev}:{node|short}:{gitnode|short} {desc}\n' $ hg log --template='hg: {node}\ngit: {gitnode}\n{date|isodate} {author}\n{desc}\n\n' +For finding changesets from Git, Hg-Git extends revsets to provide two new +selectors: + + :fromgit: Select changesets that originate from Git. Takes no arguments. + :gitnode: Select changesets that originate in a specific Git revision. Takes + a revision argument. + +For example:: + + $ hg log -r 'fromgit()' + $ hg log -r 'gitnode(84f75b909fc3)' + +Revsets are accepted by several Mercurial commands for specifying revisions. +See ``hg help revsets`` for details. + Limitations ----------- diff --git a/tests/test-keywords b/tests/test-keywords --- a/tests/test-keywords +++ b/tests/test-keywords @@ -48,3 +48,7 @@ hg commit -m 'add gamma' hg log --template "{rev} {node} {node|short} {gitnode} {gitnode|short}\n" +hg log --template "fromgit {rev}\n" --rev "fromgit()" +hg log --template "gitnode_existsA {rev}\n" --rev "gitnode(9497a4ee62e16ee641860d7677cdb2589ea15554)" +hg log --template "gitnode_existsB {rev}\n" --rev "gitnode(7eeab2ea75ec)" +hg log --template "gitnode_notexists {rev}\n" --rev "gitnode(1234567890ab)" diff --git a/tests/test-keywords.out b/tests/test-keywords.out --- a/tests/test-keywords.out +++ b/tests/test-keywords.out @@ -5,3 +5,7 @@ 2 a9da0c7c9bb7574b0f3139ab65cabac7468d6b8d a9da0c7c9bb7 1 7bcd915dc873c654b822f01b0a39269b2739e86d 7bcd915dc873 9497a4ee62e16ee641860d7677cdb2589ea15554 9497a4ee62e1 0 3442585be8a60c6cd476bbc4e45755339f2a23ef 3442585be8a6 7eeab2ea75ec1ac0ff3d500b5b6f8a3447dd7c03 7eeab2ea75ec +fromgit 0 +fromgit 1 +gitnode_existsA 1 +gitnode_existsB 0