# Copyright (c) 2007, 2008 Rocco Rutte <pdmef@gmx.net> and others.
# License: MIT <http://www.opensource.org/licenses/mit-license.php>
-from mercurial import repo,hg,cmdutil,util,ui,revlog,node
+from mercurial import node
from hg2git import setup_repo,fixup_user,get_branch,get_changeset
from hg2git import load_cache,save_cache,get_git_sha1,set_default_branch,set_origin_name
-from tempfile import mkstemp
from optparse import OptionParser
import re
import sys
import os
+if sys.platform == "win32":
+ # On Windows, sys.stdout is initially opened in text mode, which means that
+ # when a LF (\n) character is written to sys.stdout, it will be converted
+ # into CRLF (\r\n). That makes git blow up, so use this platform-specific
+ # code to change the mode of sys.stdout to binary.
+ import msvcrt
+ msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
+
# silly regex to catch Signed-off-by lines in log message
sob_re=re.compile('^Signed-[Oo]ff-[Bb]y: (.+)$')
# insert 'checkpoint' command after this many commits or none at all if 0
return 'l' in flags and '120000' or 'x' in flags and '100755' or '100644'
def wr(msg=''):
- if msg == None:
- msg = ''
- print msg
+ if msg:
+ sys.stdout.write(msg)
+ sys.stdout.write('\n')
#map(lambda x: sys.stderr.write('\t[%s]\n' % x),msg.split('\n'))
def checkpoint(count):
n=name
p=re.compile('([[ ~^:?*]|\.\.)')
n=p.sub('_', n)
- if n[-1] == '/': n=n[:-1]+'_'
+ if n[-1] in ('/', '.'): n=n[:-1]+'_'
n='/'.join(map(dot,n.split('/')))
p=re.compile('_+')
n=p.sub('_', n)
branch=get_branchname(branch)
+ parents = [p for p in repo.changelog.parentrevs(revision) if p >= 0]
+
+ if len(parents)==0 and revision != 0:
+ wr('reset refs/heads/%s' % branch)
+
wr('commit refs/heads/%s' % branch)
wr('mark :%d' % (revision+1))
if sob:
wr(desc)
wr()
- parents = [p for p in repo.changelog.parentrevs(revision) if p >= 0]
# Sort the parents based on revision ids so that we always get the
# same resulting git repo, no matter how the revisions were
sys.stderr.write('Loaded %d authors\n' % l)
return cache
+def branchtip(repo, heads):
+ '''return the tipmost branch head in heads'''
+ tip = heads[-1]
+ for h in reversed(heads):
+ if not repo[h].closesbranch():
+ tip = h
+ break
+ return tip
+
def verify_heads(ui,repo,cache,force):
- branches=repo.branchtags()
+ branches={}
+ for bn, heads in repo.branchmap().iteritems():
+ branches[bn] = branchtip(repo, heads)
l=[(-repo.changelog.rev(n), n, t) for t, n in branches.items()]
l.sort()
b=get_branch(b)
sha1=get_git_sha1(b)
c=cache.get(b)
- if sha1!=None and c!=None:
- sys.stderr.write('Verifying branch [%s]\n' % b)
if sha1!=c:
sys.stderr.write('Error: Branch [%s] modified outside hg-fast-export:'
'\n%s (repo) != %s (cache)\n' % (b,sha1,c))