mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
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.
This commit is contained in:
parent
11cde56154
commit
20a3702adc
6
Makefile
6
Makefile
@ -25,8 +25,8 @@ tests-%:
|
||||
# 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
|
||||
|
@ -141,7 +141,6 @@ 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
|
||||
|
@ -28,6 +28,7 @@ from mercurial import extensions
|
||||
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 @@ if getattr(hg, 'addbranchrevs', False):
|
||||
|
||||
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 @@ except AttributeError:
|
||||
# 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']
|
||||
|
@ -58,6 +58,21 @@ 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'
|
||||
|
||||
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
|
||||
-----------
|
||||
|
||||
|
@ -48,3 +48,7 @@ hg add gamma
|
||||
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)"
|
||||
|
@ -5,3 +5,7 @@ importing git objects into hg
|
||||
2 a9da0c7c9bb7574b0f3139ab65cabac7468d6b8d a9da0c7c9bb7
|
||||
1 7bcd915dc873c654b822f01b0a39269b2739e86d 7bcd915dc873 9497a4ee62e16ee641860d7677cdb2589ea15554 9497a4ee62e1
|
||||
0 3442585be8a60c6cd476bbc4e45755339f2a23ef 3442585be8a6 7eeab2ea75ec1ac0ff3d500b5b6f8a3447dd7c03 7eeab2ea75ec
|
||||
fromgit 0
|
||||
fromgit 1
|
||||
gitnode_existsA 1
|
||||
gitnode_existsB 0
|
||||
|
Loading…
Reference in New Issue
Block a user