[PATCH 0 of 4] add templatekw/revset support

25 views
Skip to first unread message

David Carr

unread,
Aug 23, 2012, 12:08:13 AM8/23/12
to hg-...@googlegroups.com
This series of patches adds additional help to Hg-Git, adds support for a
templating keyword, and adds support for two revset selectors.

If you have difficulty with how the patches come through via mail, the
changesets are also available at the following public repository:
https://bitbucket.org/davidmc24/hg-git

David Carr

unread,
Aug 23, 2012, 12:08:14 AM8/23/12
to hg-...@googlegroups.com
# HG changeset patch
# User David M. Carr <da...@carrclan.us>
# Date 1345693185 14400
# Node ID c88e8a88c5f6b9d9f95595a02196bd133d5927d1
# Parent 03d8e33bf7761526048576c5374cb89735268d49
makefile: document all-version-tests intentions

diff -r 03d8e33bf776 -r c88e8a88c5f6 Makefile
--- a/Makefile Mon Aug 13 18:56:27 2012 +0200
+++ b/Makefile Wed Aug 22 23:39:45 2012 -0400
@@ -20,6 +20,11 @@
(cd $(CREW) ; $(MAKE) clean ) && \
cd tests && $(PYTHON) $(CREW)/tests/run-tests.py $(TESTFLAGS)

+# This is intended to be the authoritative list of Hg versions that this
+# extension is tested with. Versions prior to the version that ships in the
+# 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

David Carr

unread,
Aug 23, 2012, 12:08:15 AM8/23/12
to hg-...@googlegroups.com
# HG changeset patch
# User David M. Carr <da...@carrclan.us>
# Date 1345693185 14400
# Node ID 89ec6678d33ae4cb24e525d289f53739cfa77350
# Parent c88e8a88c5f6b9d9f95595a02196bd133d5927d1
help: add additional help topics

diff -r c88e8a88c5f6 -r 89ec6678d33a README.md
--- a/README.md Wed Aug 22 23:39:45 2012 -0400
+++ b/README.md Wed Aug 22 23:39:45 2012 -0400
@@ -30,13 +30,13 @@
Usage
=====

-You can clone a Git repository from Hg by running `hg clone [url]`. For
+You can clone a Git repository from Hg by running `hg clone <url> [dest]`. For
example, if you were to run

$ hg clone git://github.com/schacon/hg-git.git

-hg-git would clone the repository down into the directory 'munger.git', then
-convert it to an Hg repository for you.
+Hg-Git would clone the repository and convert it to an Hg repository
+for you.

If you want to clone a github repository for later pushing (or any
other repository you access via ssh), you need to convert the ssh url
@@ -55,16 +55,16 @@

$ hg clone git+ssh://g...@github.com/schacon/hg-git.git

-If you are starting from an existing Hg repository, you have to setup
-a Git repository somewhere that you have push access to, add it as
-default path or default-push path in your .hg/hgrc and then run `hg
-push` from within your project. For example:
+If you are starting from an existing Hg repository, you have to set up
+a Git repository somewhere that you have push access to, add a path entry
+for it in your .hg/hgrc file, and then run `hg push [name]` from within
+your repository. For example:

$ cd hg-git # (an Hg repository)
$ # edit .hg/hgrc and add the target git url in the paths section
$ hg push

-This will convert all your Hg data into Git objects and push them up to the Git server.
+This will convert all your Hg data into Git objects and push them to the Git server.

Now that you have an Hg repository that can push/pull to/from a Git
repository, you can fetch updates with `hg pull`.
@@ -140,6 +140,17 @@
That will enable the Hg-Git extension for you. The bookmarks section
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
+ * 1.9.3
+ * 2.0.2
+ * 2.1.2
+ * 2.2.3
+ * 2.3
+
Configuration
=============

diff -r c88e8a88c5f6 -r 89ec6678d33a hggit/__init__.py
--- a/hggit/__init__.py Wed Aug 22 23:39:45 2012 -0400
+++ b/hggit/__init__.py Wed Aug 22 23:39:45 2012 -0400
@@ -13,8 +13,11 @@
project that is in Git. A bridger of worlds, this plugin be.

Try hg clone git:// or hg clone git+ssh://
+
+For more information and instructions, see :hg:`help git`
'''

+from bisect import insort
import inspect
import os

@@ -22,6 +25,7 @@
from mercurial import commands
from mercurial import demandimport
from mercurial import extensions
+from mercurial import help
from mercurial import hg
from mercurial import localrepo
from mercurial import util as hgutil
@@ -87,6 +91,16 @@
if getattr(hg, 'addbranchrevs', False):
extensions.wrapfunction(hg, 'addbranchrevs', safebranchrevs)

+def extsetup():
+ helpdir = os.path.join(os.path.dirname(__file__), 'help')
+ entry = (['git'], _("Working with Git Repositories"),
+ lambda: open(os.path.join(helpdir, 'git.rst')).read())
+ # in 1.6 and earler the help table is a tuple
+ if getattr(help.helptable, 'extend', None):
+ insort(help.helptable, entry)
+ else:
+ help.helptable = help.helptable + (entry,)
+
def reposetup(ui, repo):
if not isinstance(repo, gitrepo.gitrepo):
klass = hgrepo.generate_repo_subclass(repo.__class__)
diff -r c88e8a88c5f6 -r 89ec6678d33a hggit/help/git.rst
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hggit/help/git.rst Wed Aug 22 23:39:45 2012 -0400
@@ -0,0 +1,54 @@
+Basic Use
+---------
+
+You can clone a Git repository from Hg by running `hg clone <url> [dest]`.
+For example, if you were to run::
+
+ $ hg clone git://github.com/schacon/hg-git.git
+
+Hg-Git would clone the repository and convert it to an Hg repository for
+you. There are a number of different protocols that can be used for Git
+repositories. Examples of Git repository URLs include::
+
+ https://github.com/schacon/hg-git.git
+ http://code.google.com/p/guava-libraries
+ ssh://g...@github.com:schacon/hg-git.git
+ git://github.com/schacon/hg-git.git
+
+For protocols other than git://, it isn't clear whether these should be
+interpreted as Mercurial or Git URLs. Thus, to specify that a URL should
+use Git, prepend the URL with "git+". For example, an HTTPS URL would
+start with "git+https://". Also, note that Git doesn't require the
+specification of the protocol for SSH, but Mercurial does.
+
+If you are starting from an existing Hg repository, you have to set up a
+Git repository somewhere that you have push access to, add a path entry
+for it in your .hg/hgrc file, and then run `hg push [name]` from within
+your repository. For example::
+
+ $ cd hg-git # (an Hg repository)
+ $ # edit .hg/hgrc and add the target Git URL in the paths section
+ $ hg push
+
+This will convert all your Hg data into Git objects and push them to the
+Git server.
+
+Pulling new revisions into a repository is the same as from any other
+Mercurial source. Within the earlier examples, the following commands are
+all equivalent::
+
+ $ hg pull
+ $ hg pull default
+ $ hg pull git://github.com/schacon/hg-git.git
+
+Git branches are exposed in Hg as bookmarks, while Git remotes are exposed
+as Hg local tags. See `hg help bookmarks` and `hg help tags` for further
+information.
+
+Limitations
+-----------
+
+- Cloning/pushing/pulling local Git repositories is not supported (due to
+ lack of support in Dulwich)
+- The `hg incoming` and `hg outgoing` commands are not currently
+ supported.
\ No newline at end of file
diff -r c88e8a88c5f6 -r 89ec6678d33a tests/test-help
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-help Wed Aug 22 23:39:45 2012 -0400
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+# Tests that the various help files are properly registered
+
+echo "[extensions]" >> $HGRCPATH
+echo "hggit=$(echo $(dirname $(dirname $0)))/hggit" >> $HGRCPATH
+
+hg help | grep 'git' | sed 's/ */ /g'
+hg help hggit | grep 'help git' | sed 's/:hg:`help git`/"hg help git"/g'
+hg help git | grep 'Working with Git Repositories'
diff -r c88e8a88c5f6 -r 89ec6678d33a tests/test-help.out
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-help.out Wed Aug 22 23:39:45 2012 -0400
@@ -0,0 +1,4 @@
+ hggit push and pull from a Git server
+ git Working with Git Repositories
+For more information and instructions, see "hg help git"
+Working with Git Repositories

David Carr

unread,
Aug 23, 2012, 12:08:16 AM8/23/12
to hg-...@googlegroups.com
# HG changeset patch
# User David M. Carr <da...@carrclan.us>
# Date 1345693185 14400
# Node ID 6ec78087a26118e520876c195bc6dfccc8f8040c
# Parent 89ec6678d33ae4cb24e525d289f53739cfa77350
templatekw: add support for gitnode template keyword

diff -r 89ec6678d33a -r 6ec78087a261 hggit/__init__.py
--- a/hggit/__init__.py Wed Aug 22 23:39:45 2012 -0400
+++ b/hggit/__init__.py Wed Aug 22 23:39:45 2012 -0400
@@ -28,6 +28,7 @@
from mercurial import help
from mercurial import hg
from mercurial import localrepo
+from mercurial import templatekw
from mercurial import util as hgutil
from mercurial import url
from mercurial.i18n import _
@@ -92,6 +93,7 @@
extensions.wrapfunction(hg, 'addbranchrevs', safebranchrevs)

def extsetup():
+ templatekw.keywords.update({'gitnode': gitnodekw})
helpdir = os.path.join(os.path.dirname(__file__), 'help')
entry = (['git'], _("Working with Git Repositories"),
lambda: open(os.path.join(helpdir, 'git.rst')).read())
@@ -175,6 +177,16 @@
# 1.7+
pass

+def gitnodekw(**args):
+ """:gitnode: String. The Git changeset identification hash, as a 40 hexadecimal digit string."""
+ node = args['ctx']
+ repo = args['repo']
+ git = GitHandler(repo, repo.ui)
+ gitnode = git.map_git_get(node.hex())
+ if gitnode is None:
+ gitnode = ''
+ return gitnode
+
cmdtable = {
"gimport":
(gimport, [], _('hg gimport')),
diff -r 89ec6678d33a -r 6ec78087a261 hggit/help/git.rst
--- a/hggit/help/git.rst Wed Aug 22 23:39:45 2012 -0400
+++ b/hggit/help/git.rst Wed Aug 22 23:39:45 2012 -0400
@@ -45,6 +45,19 @@
as Hg local tags. See `hg help bookmarks` and `hg help tags` for further
information.

+Finding and displaying Git revisions
+------------------------------------
+
+For displaying the Git revision ID, Hg-Git provides a template keyword:
+
+ :gitnode: String. The Git changeset identification hash, as a 40 hexadecimal
+ digit string.
+
+For example::
+
+ $ 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'
+
Limitations
-----------

diff -r 89ec6678d33a -r 6ec78087a261 tests/test-keywords
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-keywords Wed Aug 22 23:39:45 2012 -0400
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+# Fails for some reason, need to investigate
+# "$TESTDIR/hghave" git || exit 80
+
+# bail if the user does not have dulwich
+python -c 'import dulwich, dulwich.repo' || exit 80
+
+# bail early if the user is already running git-daemon
+echo hi | nc localhost 9418 2>/dev/null && exit 80
+
+echo "[extensions]" >> $HGRCPATH
+echo "hggit=$(echo $(dirname $(dirname $0)))/hggit" >> $HGRCPATH
+echo 'hgext.bookmarks =' >> $HGRCPATH
+
+GIT_AUTHOR_NAME='test'; export GIT_AUTHOR_NAME
+GIT_AUTHOR_EMAIL='te...@example.org'; export GIT_AUTHOR_EMAIL
+GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0000"; export GIT_AUTHOR_DATE
+GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME"; export GIT_COMMITTER_NAME
+GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"; export GIT_COMMITTER_EMAIL
+GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"; export GIT_COMMITTER_DATE
+
+count=10
+commit()
+{
+ GIT_AUTHOR_DATE="2007-01-01 00:00:$count +0000"
+ GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
+ git commit "$@" >/dev/null 2>/dev/null || echo "git commit error"
+ count=`expr $count + 1`
+}
+
+mkdir gitrepo
+cd gitrepo
+git init | python -c "import sys; print sys.stdin.read().replace('$(dirname $(pwd))/', '')"
+echo alpha > alpha
+git add alpha
+commit -m 'add alpha'
+echo beta > beta
+git add beta
+commit -m 'add beta'
+
+cd ..
+
+hg clone gitrepo hgrepo | grep -v '^updating'
+cd hgrepo
+echo gamma > gamma
+hg add gamma
+hg commit -m 'add gamma'
+
+hg log --template "{rev} {node} {node|short} {gitnode} {gitnode|short}\n"
diff -r 89ec6678d33a -r 6ec78087a261 tests/test-keywords.out
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-keywords.out Wed Aug 22 23:39:45 2012 -0400
@@ -0,0 +1,7 @@
+Initialized empty Git repository in gitrepo/.git/
+
+importing git objects into hg
+2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+2 a9da0c7c9bb7574b0f3139ab65cabac7468d6b8d a9da0c7c9bb7
+1 7bcd915dc873c654b822f01b0a39269b2739e86d 7bcd915dc873 9497a4ee62e16ee641860d7677cdb2589ea15554 9497a4ee62e1
+0 3442585be8a60c6cd476bbc4e45755339f2a23ef 3442585be8a6 7eeab2ea75ec1ac0ff3d500b5b6f8a3447dd7c03 7eeab2ea75ec

David Carr

unread,
Aug 23, 2012, 12:08:17 AM8/23/12
to hg-...@googlegroups.com
# HG changeset patch
# User David M. Carr <da...@carrclan.us>
# Date 1345693185 14400
# Node ID 88301b9daed73dc932fd89e9309cdcd02dffc909
# Parent 6ec78087a26118e520876c195bc6dfccc8f8040c
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 -r 6ec78087a261 -r 88301b9daed7 Makefile
--- a/Makefile Wed Aug 22 23:39:45 2012 -0400
+++ b/Makefile Wed Aug 22 23:39:45 2012 -0400
@@ -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 -r 6ec78087a261 -r 88301b9daed7 README.md
--- a/README.md Wed Aug 22 23:39:45 2012 -0400
+++ b/README.md Wed Aug 22 23:39:45 2012 -0400
@@ -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 -r 6ec78087a261 -r 88301b9daed7 hggit/__init__.py
--- a/hggit/__init__.py Wed Aug 22 23:39:45 2012 -0400
+++ b/hggit/__init__.py Wed Aug 22 23:39:45 2012 -0400
@@ -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 -r 6ec78087a261 -r 88301b9daed7 hggit/help/git.rst
--- a/hggit/help/git.rst Wed Aug 22 23:39:45 2012 -0400
+++ b/hggit/help/git.rst Wed Aug 22 23:39:45 2012 -0400
@@ -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 -r 6ec78087a261 -r 88301b9daed7 tests/test-keywords
--- a/tests/test-keywords Wed Aug 22 23:39:45 2012 -0400
+++ b/tests/test-keywords Wed Aug 22 23:39:45 2012 -0400
@@ -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 -r 6ec78087a261 -r 88301b9daed7 tests/test-keywords.out
--- a/tests/test-keywords.out Wed Aug 22 23:39:45 2012 -0400
+++ b/tests/test-keywords.out Wed Aug 22 23:39:45 2012 -0400
@@ -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

Augie Fackler

unread,
Aug 28, 2012, 10:17:49 AM8/28/12
to hg-...@googlegroups.com
This one needs to touch setup.py, otherwise the bundles on pypi won't include the help.
> --
> You received this message because you are subscribed to the Google Groups "hg-git" group.
> To post to this group, send email to hg-...@googlegroups.com.
> To unsubscribe from this group, send email to hg-git+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/hg-git?hl=en.
>

Augie Fackler

unread,
Aug 28, 2012, 10:18:00 AM8/28/12
to hg-...@googlegroups.com
queued this one for next

On Aug 22, 2012, at 11:08 PM, David Carr wrote:

Augie Fackler

unread,
Aug 28, 2012, 10:18:30 AM8/28/12
to hg-...@googlegroups.com
Er, master. Sigh.

Augie Fackler

unread,
Aug 28, 2012, 10:20:30 AM8/28/12
to hg-...@googlegroups.com
Looks good, but dropping until the previous one is in.
On Aug 22, 2012, at 11:08 PM, David Carr wrote:

Augie Fackler

unread,
Aug 28, 2012, 10:20:40 AM8/28/12
to hg-...@googlegroups.com
same as previous

On Aug 22, 2012, at 11:08 PM, David Carr wrote:

David M. Carr

unread,
Aug 28, 2012, 11:49:58 AM8/28/12
to hg-...@googlegroups.com
Thanks for the review. I'll look into this and re-submit.

--
David M. Carr
davi...@gmail.com

David Carr

unread,
Aug 28, 2012, 11:07:37 PM8/28/12
to hg-...@googlegroups.com
This series of patches adds additional help to Hg-Git, adds support for a
templating keyword, and adds support for two revset selectors.

The only differences between this send and the previous one are:
* the addition of package_data in setup.py to handle the new help file
* the omission of the first patch, which was accepted

David Carr

unread,
Aug 28, 2012, 11:07:38 PM8/28/12
to hg-...@googlegroups.com
# HG changeset patch
# User David M. Carr <da...@carrclan.us>
# Date 1345693185 14400
# Node ID fea55654058619c423e2540fe497cc5e2694860e
# Parent c88e8a88c5f6b9d9f95595a02196bd133d5927d1
help: add additional help topics

diff -r c88e8a88c5f6 -r fea556540586 README.md
diff -r c88e8a88c5f6 -r fea556540586 hggit/__init__.py
diff -r c88e8a88c5f6 -r fea556540586 hggit/help/git.rst
diff -r c88e8a88c5f6 -r fea556540586 setup.py
--- a/setup.py Wed Aug 22 23:39:45 2012 -0400
+++ b/setup.py Wed Aug 22 23:39:45 2012 -0400
@@ -19,5 +19,6 @@
keywords='hg git mercurial',
license='GPLv2',
packages=['hggit'],
+ package_data={ 'hggit': ['help/git.rst'] },
install_requires=['dulwich>=0.8.0'],
)
diff -r c88e8a88c5f6 -r fea556540586 tests/test-help
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-help Wed Aug 22 23:39:45 2012 -0400
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+# Tests that the various help files are properly registered
+
+echo "[extensions]" >> $HGRCPATH
+echo "hggit=$(echo $(dirname $(dirname $0)))/hggit" >> $HGRCPATH
+
+hg help | grep 'git' | sed 's/ */ /g'
+hg help hggit | grep 'help git' | sed 's/:hg:`help git`/"hg help git"/g'
+hg help git | grep 'Working with Git Repositories'
diff -r c88e8a88c5f6 -r fea556540586 tests/test-help.out

David Carr

unread,
Aug 28, 2012, 11:07:39 PM8/28/12
to hg-...@googlegroups.com
# HG changeset patch
# User David M. Carr <da...@carrclan.us>
# Date 1345693185 14400
# Node ID 270f9fa9241ee3f9fe5356b6046d0c9ae9e00573
# Parent fea55654058619c423e2540fe497cc5e2694860e
templatekw: add support for gitnode template keyword

diff -r fea556540586 -r 270f9fa9241e hggit/__init__.py
--- a/hggit/__init__.py Wed Aug 22 23:39:45 2012 -0400
+++ b/hggit/__init__.py Wed Aug 22 23:39:45 2012 -0400
@@ -28,6 +28,7 @@
from mercurial import help
from mercurial import hg
from mercurial import localrepo
+from mercurial import templatekw
from mercurial import util as hgutil
from mercurial import url
from mercurial.i18n import _
@@ -92,6 +93,7 @@
extensions.wrapfunction(hg, 'addbranchrevs', safebranchrevs)

def extsetup():
+ templatekw.keywords.update({'gitnode': gitnodekw})
helpdir = os.path.join(os.path.dirname(__file__), 'help')
entry = (['git'], _("Working with Git Repositories"),
lambda: open(os.path.join(helpdir, 'git.rst')).read())
@@ -175,6 +177,16 @@
# 1.7+
pass

+def gitnodekw(**args):
+ """:gitnode: String. The Git changeset identification hash, as a 40 hexadecimal digit string."""
+ node = args['ctx']
+ repo = args['repo']
+ git = GitHandler(repo, repo.ui)
+ gitnode = git.map_git_get(node.hex())
+ if gitnode is None:
+ gitnode = ''
+ return gitnode
+
cmdtable = {
"gimport":
(gimport, [], _('hg gimport')),
diff -r fea556540586 -r 270f9fa9241e hggit/help/git.rst
--- a/hggit/help/git.rst Wed Aug 22 23:39:45 2012 -0400
+++ b/hggit/help/git.rst Wed Aug 22 23:39:45 2012 -0400
@@ -45,6 +45,19 @@
as Hg local tags. See `hg help bookmarks` and `hg help tags` for further
information.

+Finding and displaying Git revisions
+------------------------------------
+
+For displaying the Git revision ID, Hg-Git provides a template keyword:
+
+ :gitnode: String. The Git changeset identification hash, as a 40 hexadecimal
+ digit string.
+
+For example::
+
+ $ 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'
+
Limitations
-----------

diff -r fea556540586 -r 270f9fa9241e tests/test-keywords
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-keywords Wed Aug 22 23:39:45 2012 -0400
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+# Fails for some reason, need to investigate
+# "$TESTDIR/hghave" git || exit 80
+
+# bail if the user does not have dulwich
+python -c 'import dulwich, dulwich.repo' || exit 80
+
+# bail early if the user is already running git-daemon
+echo hi | nc localhost 9418 2>/dev/null && exit 80
+
+echo "[extensions]" >> $HGRCPATH
+echo "hggit=$(echo $(dirname $(dirname $0)))/hggit" >> $HGRCPATH
+hg log --template "{rev} {node} {node|short} {gitnode} {gitnode|short}\n"
diff -r fea556540586 -r 270f9fa9241e tests/test-keywords.out
--- /dev/null Thu Jan 01 00:00:00 1970 +0000

David Carr

unread,
Aug 28, 2012, 11:07:40 PM8/28/12
to hg-...@googlegroups.com
# HG changeset patch
# User David M. Carr <da...@carrclan.us>
# Date 1345693185 14400
# Node ID 6a2a8d2cef95e30fe87c6008f7120c5f9de92b4a
# Parent 270f9fa9241ee3f9fe5356b6046d0c9ae9e00573
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 -r 270f9fa9241e -r 6a2a8d2cef95 Makefile
--- a/Makefile Wed Aug 22 23:39:45 2012 -0400
+++ b/Makefile Wed Aug 22 23:39:45 2012 -0400
@@ -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 -r 270f9fa9241e -r 6a2a8d2cef95 README.md
--- a/README.md Wed Aug 22 23:39:45 2012 -0400
+++ b/README.md Wed Aug 22 23:39:45 2012 -0400
@@ -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 -r 270f9fa9241e -r 6a2a8d2cef95 hggit/__init__.py
--- a/hggit/__init__.py Wed Aug 22 23:39:45 2012 -0400
+++ b/hggit/__init__.py Wed Aug 22 23:39:45 2012 -0400
@@ -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 -r 270f9fa9241e -r 6a2a8d2cef95 hggit/help/git.rst
--- a/hggit/help/git.rst Wed Aug 22 23:39:45 2012 -0400
+++ b/hggit/help/git.rst Wed Aug 22 23:39:45 2012 -0400
@@ -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 -r 270f9fa9241e -r 6a2a8d2cef95 tests/test-keywords
--- a/tests/test-keywords Wed Aug 22 23:39:45 2012 -0400
+++ b/tests/test-keywords Wed Aug 22 23:39:45 2012 -0400
@@ -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 -r 270f9fa9241e -r 6a2a8d2cef95 tests/test-keywords.out
--- a/tests/test-keywords.out Wed Aug 22 23:39:45 2012 -0400
+++ b/tests/test-keywords.out Wed Aug 22 23:39:45 2012 -0400

Augie Fackler

unread,
Aug 29, 2012, 11:18:13 PM8/29/12
to hg-...@googlegroups.com
queued all of these, though in the future I'd like to see dropping a version and then adding features that depend on such dropping as discrete changes.

Thanks!

David M. Carr

unread,
Aug 29, 2012, 11:56:02 PM8/29/12
to hg-...@googlegroups.com
I'll keep that in mind for the future. Thanks for the feedback.
Reply all
Reply to author
Forward
0 new messages