Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.

Commit e200cec

Browse files
committed
Adapt to changes in Mercurial 4.6
Starting with Mercurial 4.6 repo.lookup() no longer accepts raw hashes for lookups.
1 parent 51d5f89 commit e200cec

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ first time.
2727
System Requirements
2828
-------------------
2929

30-
This project depends on Python 2.7 and the Python mercurial package.
31-
If Python is not installed, install it before proceeding. The
32-
mercurial package can be installed with `pip install mercurial`.
30+
This project depends on Python 2.7 and the Mercurial 4.6 package. If
31+
Python is not installed, install it before proceeding. The Mercurial
32+
package can be installed with `pip install mercurial`.
3333

3434
If you're on Windows, run the following commands in git bash (Git for
3535
Windows).

hg-fast-export.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# License: MIT <http://www.opensource.org/licenses/mit-license.php>
55

66
from mercurial import node
7+
from mercurial.scmutil import revsymbol
78
from hg2git import setup_repo,fixup_user,get_branch,get_changeset
89
from hg2git import load_cache,save_cache,get_git_sha1,set_default_branch,set_origin_name
910
from optparse import OptionParser
@@ -78,7 +79,7 @@ def get_filechanges(repo,revision,parents,mleft):
7879
l,c,r=[],[],[]
7980
for p in parents:
8081
if p<0: continue
81-
mright=repo.changectx(p).manifest()
82+
mright=revsymbol(repo,str(p)).manifest()
8283
l,c,r=split_dict(mleft,mright,l,c,r)
8384
l.sort()
8485
c.sort()
@@ -210,7 +211,7 @@ def get_branchname(name):
210211
wr(desc)
211212
wr()
212213

213-
ctx=repo.changectx(str(revision))
214+
ctx=revsymbol(repo,str(revision))
214215
man=ctx.manifest()
215216
added,changed,removed,type=[],[],[],''
216217

@@ -225,7 +226,7 @@ def get_branchname(name):
225226
# later non-merge revision: feed in changed manifest
226227
# if we have exactly one parent, just take the changes from the
227228
# manifest without expensively comparing checksums
228-
f=repo.status(repo.lookup(parents[0]),revnode)[:3]
229+
f=repo.status(parents[0],revnode)[:3]
229230
added,changed,removed=f[1],f[0],f[2]
230231
type='simple delta'
231232
else: # a merge with two parents
@@ -262,7 +263,7 @@ def export_note(ui,repo,revision,count,authors,encoding,is_first):
262263
if is_first:
263264
wr('from refs/notes/hg^0')
264265
wr('N inline :%d' % (revision+1))
265-
hg_hash=repo.changectx(str(revision)).hex()
266+
hg_hash=revsymbol(repo,str(revision)).hex()
266267
wr('data %d' % (len(hg_hash)))
267268
wr_no_nl(hg_hash)
268269
wr()

hg2git.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
# License: MIT <http://www.opensource.org/licenses/mit-license.php>
55

66
from mercurial import hg,util,ui,templatefilters
7+
from mercurial import error as hgerror
8+
from mercurial.scmutil import revsymbol,binnode
9+
710
import re
811
import os
912
import sys
@@ -69,7 +72,15 @@ def get_branch(name):
6972
return name
7073

7174
def get_changeset(ui,repo,revision,authors={},encoding=''):
72-
node=repo.lookup(revision)
75+
# Starting with Mercurial 4.6 lookup no longer accepts raw hashes
76+
# for lookups. Work around it by changing our behaviour depending on
77+
# how it fails
78+
try:
79+
node=repo.lookup(revision)
80+
except hgerror.ProgrammingError:
81+
node=binnode(revsymbol(repo,str(revision))) # We were given a numeric rev
82+
except hgerror.RepoLookupError:
83+
node=revision # We got a raw hash
7384
(manifest,user,(time,timezone),files,desc,extra)=repo.changelog.read(node)
7485
if encoding:
7586
user=user.decode(encoding).encode('utf8')

0 commit comments

Comments
 (0)