2009-04-26 03:47:44 +04:00
|
|
|
# git.py - git support for the convert extension
|
|
|
|
#
|
|
|
|
# Copyright 2005-2009 Matt Mackall <mpm@selenic.com> and others
|
|
|
|
#
|
|
|
|
# This software may be used and distributed according to the terms of the
|
2010-01-20 07:20:08 +03:00
|
|
|
# GNU General Public License version 2 or any later version.
|
2016-03-02 23:42:13 +03:00
|
|
|
from __future__ import absolute_import
|
2007-06-11 07:08:47 +04:00
|
|
|
|
|
|
|
import os
|
2016-05-14 08:03:12 +03:00
|
|
|
|
|
|
|
from mercurial.i18n import _
|
2016-03-02 23:42:13 +03:00
|
|
|
from mercurial import (
|
|
|
|
config,
|
|
|
|
error,
|
|
|
|
node as nodemod,
|
|
|
|
)
|
2007-06-11 07:08:47 +04:00
|
|
|
|
2016-03-02 23:42:13 +03:00
|
|
|
from . import (
|
|
|
|
common,
|
|
|
|
)
|
2007-06-11 07:08:47 +04:00
|
|
|
|
2012-10-30 04:40:13 +04:00
|
|
|
class submodule(object):
|
|
|
|
def __init__(self, path, node, url):
|
|
|
|
self.path = path
|
|
|
|
self.node = node
|
|
|
|
self.url = url
|
|
|
|
|
|
|
|
def hgsub(self):
|
|
|
|
return "%s = [git]%s" % (self.path, self.url)
|
|
|
|
|
|
|
|
def hgsubstate(self):
|
|
|
|
return "%s %s" % (self.node, self.path)
|
|
|
|
|
2016-12-23 09:28:11 +03:00
|
|
|
# Keys in extra fields that should not be copied if the user requests.
|
2017-02-11 03:56:29 +03:00
|
|
|
bannedextrakeys = {
|
2016-12-23 09:28:11 +03:00
|
|
|
# Git commit object built-ins.
|
|
|
|
'tree',
|
|
|
|
'parent',
|
|
|
|
'author',
|
|
|
|
'committer',
|
|
|
|
# Mercurial built-ins.
|
|
|
|
'branch',
|
|
|
|
'close',
|
2017-02-11 03:56:29 +03:00
|
|
|
}
|
2016-12-23 09:28:11 +03:00
|
|
|
|
2016-03-29 20:29:00 +03:00
|
|
|
class convert_git(common.converter_source, common.commandline):
|
2007-08-26 16:51:27 +04:00
|
|
|
# Windows does not support GIT_DIR= construct while other systems
|
|
|
|
# cannot remove environment variable. Just assume none have
|
|
|
|
# both issues.
|
2007-07-02 08:09:08 +04:00
|
|
|
|
2016-03-23 03:05:11 +03:00
|
|
|
def _gitcmd(self, cmd, *args, **kwargs):
|
|
|
|
return cmd('--git-dir=%s' % self.path, *args, **kwargs)
|
|
|
|
|
|
|
|
def gitrun0(self, *args, **kwargs):
|
|
|
|
return self._gitcmd(self.run0, *args, **kwargs)
|
|
|
|
|
|
|
|
def gitrun(self, *args, **kwargs):
|
|
|
|
return self._gitcmd(self.run, *args, **kwargs)
|
|
|
|
|
|
|
|
def gitrunlines0(self, *args, **kwargs):
|
|
|
|
return self._gitcmd(self.runlines0, *args, **kwargs)
|
|
|
|
|
|
|
|
def gitrunlines(self, *args, **kwargs):
|
|
|
|
return self._gitcmd(self.runlines, *args, **kwargs)
|
2014-05-28 08:12:24 +04:00
|
|
|
|
2016-03-23 03:05:11 +03:00
|
|
|
def gitpipe(self, *args, **kwargs):
|
|
|
|
return self._gitcmd(self._run3, *args, **kwargs)
|
2013-02-08 18:02:57 +04:00
|
|
|
|
2015-07-08 20:27:43 +03:00
|
|
|
def __init__(self, ui, path, revs=None):
|
|
|
|
super(convert_git, self).__init__(ui, path, revs=revs)
|
2016-03-29 20:29:00 +03:00
|
|
|
common.commandline.__init__(self, ui, 'git')
|
2015-07-08 20:27:43 +03:00
|
|
|
|
2016-04-07 06:57:46 +03:00
|
|
|
# Pass an absolute path to git to prevent from ever being interpreted
|
|
|
|
# as a URL
|
|
|
|
path = os.path.abspath(path)
|
|
|
|
|
2007-06-11 07:08:47 +04:00
|
|
|
if os.path.isdir(path + "/.git"):
|
|
|
|
path += "/.git"
|
|
|
|
if not os.path.exists(path + "/objects"):
|
2016-03-02 23:42:13 +03:00
|
|
|
raise common.NoRepo(_("%s does not look like a Git repository") %
|
|
|
|
path)
|
2007-10-31 00:14:15 +03:00
|
|
|
|
2014-09-24 01:45:23 +04:00
|
|
|
# The default value (50) is based on the default for 'git diff'.
|
|
|
|
similarity = ui.configint('convert', 'git.similarity', default=50)
|
2014-09-12 22:23:26 +04:00
|
|
|
if similarity < 0 or similarity > 100:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('similarity must be between 0 and 100'))
|
2014-09-12 22:23:26 +04:00
|
|
|
if similarity > 0:
|
2016-03-23 03:05:11 +03:00
|
|
|
self.simopt = ['-C%d%%' % similarity]
|
2017-06-30 04:33:51 +03:00
|
|
|
findcopiesharder = ui.configbool('convert', 'git.findcopiesharder')
|
2014-09-12 23:28:30 +04:00
|
|
|
if findcopiesharder:
|
2016-03-23 03:05:11 +03:00
|
|
|
self.simopt.append('--find-copies-harder')
|
2016-12-18 23:53:20 +03:00
|
|
|
|
2017-06-30 04:34:06 +03:00
|
|
|
renamelimit = ui.configint('convert', 'git.renamelimit')
|
2016-12-18 23:53:20 +03:00
|
|
|
self.simopt.append('-l%d' % renamelimit)
|
2014-09-12 22:23:26 +04:00
|
|
|
else:
|
2016-03-23 03:05:11 +03:00
|
|
|
self.simopt = []
|
2014-09-12 22:23:26 +04:00
|
|
|
|
2016-03-02 23:42:13 +03:00
|
|
|
common.checktool('git', 'git')
|
2007-10-31 00:14:15 +03:00
|
|
|
|
2007-07-01 23:58:08 +04:00
|
|
|
self.path = path
|
2012-10-30 04:40:13 +04:00
|
|
|
self.submodules = []
|
2007-07-01 23:58:08 +04:00
|
|
|
|
2016-03-23 03:05:11 +03:00
|
|
|
self.catfilepipe = self.gitpipe('cat-file', '--batch')
|
2014-05-28 08:12:24 +04:00
|
|
|
|
2016-12-23 09:28:11 +03:00
|
|
|
self.copyextrakeys = self.ui.configlist('convert', 'git.extrakeys')
|
|
|
|
banned = set(self.copyextrakeys) & bannedextrakeys
|
|
|
|
if banned:
|
|
|
|
raise error.Abort(_('copying of extra key is forbidden: %s') %
|
|
|
|
_(', ').join(sorted(banned)))
|
|
|
|
|
2017-06-30 04:33:29 +03:00
|
|
|
committeractions = self.ui.configlist('convert', 'git.committeractions')
|
2017-01-14 10:21:10 +03:00
|
|
|
|
|
|
|
messagedifferent = None
|
|
|
|
messagealways = None
|
|
|
|
for a in committeractions:
|
|
|
|
if a.startswith(('messagedifferent', 'messagealways')):
|
|
|
|
k = a
|
|
|
|
v = None
|
|
|
|
if '=' in a:
|
|
|
|
k, v = a.split('=', 1)
|
|
|
|
|
|
|
|
if k == 'messagedifferent':
|
|
|
|
messagedifferent = v or 'committer:'
|
|
|
|
elif k == 'messagealways':
|
|
|
|
messagealways = v or 'committer:'
|
|
|
|
|
|
|
|
if messagedifferent and messagealways:
|
|
|
|
raise error.Abort(_('committeractions cannot define both '
|
|
|
|
'messagedifferent and messagealways'))
|
|
|
|
|
|
|
|
dropcommitter = 'dropcommitter' in committeractions
|
|
|
|
replaceauthor = 'replaceauthor' in committeractions
|
|
|
|
|
2017-01-14 21:11:19 +03:00
|
|
|
if dropcommitter and replaceauthor:
|
2017-01-14 10:21:10 +03:00
|
|
|
raise error.Abort(_('committeractions cannot define both '
|
2017-01-14 21:11:19 +03:00
|
|
|
'dropcommitter and replaceauthor'))
|
2017-01-14 10:21:10 +03:00
|
|
|
|
|
|
|
if dropcommitter and messagealways:
|
|
|
|
raise error.Abort(_('committeractions cannot define both '
|
|
|
|
'dropcommitter and messagealways'))
|
|
|
|
|
|
|
|
if not messagedifferent and not messagealways:
|
|
|
|
messagedifferent = 'committer:'
|
|
|
|
|
|
|
|
self.committeractions = {
|
|
|
|
'dropcommitter': dropcommitter,
|
|
|
|
'replaceauthor': replaceauthor,
|
|
|
|
'messagedifferent': messagedifferent,
|
|
|
|
'messagealways': messagealways,
|
|
|
|
}
|
|
|
|
|
2014-05-28 08:12:24 +04:00
|
|
|
def after(self):
|
|
|
|
for f in self.catfilepipe:
|
|
|
|
f.close()
|
|
|
|
|
2007-06-11 07:08:47 +04:00
|
|
|
def getheads(self):
|
2015-07-08 20:27:43 +03:00
|
|
|
if not self.revs:
|
2016-03-23 03:05:11 +03:00
|
|
|
output, status = self.gitrun('rev-parse', '--branches', '--remotes')
|
|
|
|
heads = output.splitlines()
|
|
|
|
if status:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('cannot retrieve git heads'))
|
2007-07-02 09:00:25 +04:00
|
|
|
else:
|
2015-07-08 20:29:11 +03:00
|
|
|
heads = []
|
|
|
|
for rev in self.revs:
|
2016-03-23 03:05:11 +03:00
|
|
|
rawhead, ret = self.gitrun('rev-parse', '--verify', rev)
|
2015-07-08 20:29:11 +03:00
|
|
|
heads.append(rawhead[:-1])
|
|
|
|
if ret:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('cannot retrieve git head "%s"') % rev)
|
2010-04-26 00:59:50 +04:00
|
|
|
return heads
|
2007-06-11 07:08:47 +04:00
|
|
|
|
|
|
|
def catfile(self, rev, type):
|
2016-03-02 23:42:13 +03:00
|
|
|
if rev == nodemod.nullhex:
|
2012-05-12 18:00:58 +04:00
|
|
|
raise IOError
|
2014-05-28 08:12:24 +04:00
|
|
|
self.catfilepipe[0].write(rev+'\n')
|
|
|
|
self.catfilepipe[0].flush()
|
|
|
|
info = self.catfilepipe[1].readline().split()
|
|
|
|
if info[1] != type:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('cannot read %r object at %s') % (type, rev))
|
2014-05-28 08:12:24 +04:00
|
|
|
size = int(info[2])
|
|
|
|
data = self.catfilepipe[1].read(size)
|
|
|
|
if len(data) < size:
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('cannot read %r object at %s: unexpected size')
|
2014-07-31 21:14:24 +04:00
|
|
|
% (type, rev))
|
2014-05-28 08:12:24 +04:00
|
|
|
# read the trailing newline
|
|
|
|
self.catfilepipe[1].read(1)
|
2010-04-26 00:59:50 +04:00
|
|
|
return data
|
2007-06-11 07:08:47 +04:00
|
|
|
|
|
|
|
def getfile(self, name, rev):
|
2016-03-02 23:42:13 +03:00
|
|
|
if rev == nodemod.nullhex:
|
2014-08-27 00:03:32 +04:00
|
|
|
return None, None
|
2012-10-30 04:40:13 +04:00
|
|
|
if name == '.hgsub':
|
|
|
|
data = '\n'.join([m.hgsub() for m in self.submoditer()])
|
|
|
|
mode = ''
|
|
|
|
elif name == '.hgsubstate':
|
|
|
|
data = '\n'.join([m.hgsubstate() for m in self.submoditer()])
|
|
|
|
mode = ''
|
|
|
|
else:
|
|
|
|
data = self.catfile(rev, "blob")
|
|
|
|
mode = self.modecache[(name, rev)]
|
2010-05-09 23:52:34 +04:00
|
|
|
return data, mode
|
2007-06-11 07:08:47 +04:00
|
|
|
|
2012-10-30 04:40:13 +04:00
|
|
|
def submoditer(self):
|
2016-03-02 23:42:13 +03:00
|
|
|
null = nodemod.nullhex
|
2012-10-30 04:40:13 +04:00
|
|
|
for m in sorted(self.submodules, key=lambda p: p.path):
|
|
|
|
if m.node != null:
|
|
|
|
yield m
|
|
|
|
|
|
|
|
def parsegitmodules(self, content):
|
|
|
|
"""Parse the formatted .gitmodules file, example file format:
|
|
|
|
[submodule "sub"]\n
|
|
|
|
\tpath = sub\n
|
|
|
|
\turl = git://giturl\n
|
|
|
|
"""
|
|
|
|
self.submodules = []
|
|
|
|
c = config.config()
|
2015-06-30 03:19:18 +03:00
|
|
|
# Each item in .gitmodules starts with whitespace that cant be parsed
|
|
|
|
c.parse('.gitmodules', '\n'.join(line.strip() for line in
|
|
|
|
content.split('\n')))
|
2012-10-30 04:40:13 +04:00
|
|
|
for sec in c.sections():
|
|
|
|
s = c[sec]
|
|
|
|
if 'url' in s and 'path' in s:
|
|
|
|
self.submodules.append(submodule(s['path'], '', s['url']))
|
|
|
|
|
|
|
|
def retrievegitmodules(self, version):
|
2016-03-23 03:05:11 +03:00
|
|
|
modules, ret = self.gitrun('show', '%s:%s' % (version, '.gitmodules'))
|
2012-10-30 04:40:13 +04:00
|
|
|
if ret:
|
2015-06-30 03:19:58 +03:00
|
|
|
# This can happen if a file is in the repo that has permissions
|
|
|
|
# 160000, but there is no .gitmodules file.
|
|
|
|
self.ui.warn(_("warning: cannot read submodules config file in "
|
|
|
|
"%s\n") % version)
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
self.parsegitmodules(modules)
|
|
|
|
except error.ParseError:
|
|
|
|
self.ui.warn(_("warning: unable to parse .gitmodules in %s\n")
|
|
|
|
% version)
|
|
|
|
return
|
|
|
|
|
2012-10-30 04:40:13 +04:00
|
|
|
for m in self.submodules:
|
2016-03-23 03:05:11 +03:00
|
|
|
node, ret = self.gitrun('rev-parse', '%s:%s' % (version, m.path))
|
2012-10-30 04:40:13 +04:00
|
|
|
if ret:
|
|
|
|
continue
|
|
|
|
m.node = node.strip()
|
|
|
|
|
convert: introduce --full for converting all files
Convert will normally only process files that were changed in a source
revision, apply the filemap, and record it has a change in the target
repository. (If it ends up not really changing anything, nothing changes.)
That means that _if_ the filemap is changed before continuing an incremental
convert, the change will only kick in when the files it affects are modified in
a source revision and thus processed.
With --full, convert will make a full conversion every time and process
all files in the source repo and remove target repo files that shouldn't be
there. Filemap changes will thus kick in on the first converted revision, no
matter what is changed.
This flag should in most cases not make any difference but will make convert
significantly slower.
Other names has been considered for this feature, such as "resync", "sync",
"checkunmodified", "all" or "allfiles", but I found that they were less obvious
and required more explanation than "full" and were harder to describe
consistently.
2014-08-27 00:03:32 +04:00
|
|
|
def getchanges(self, version, full):
|
|
|
|
if full:
|
2015-10-14 09:06:54 +03:00
|
|
|
raise error.Abort(_("convert from git does not support --full"))
|
2007-06-11 07:08:47 +04:00
|
|
|
self.modecache = {}
|
2016-03-23 03:05:11 +03:00
|
|
|
cmd = ['diff-tree','-z', '--root', '-m', '-r'] + self.simopt + [version]
|
|
|
|
output, status = self.gitrun(*cmd)
|
|
|
|
if status:
|
|
|
|
raise error.Abort(_('cannot read changes in %s') % version)
|
2007-06-11 07:08:47 +04:00
|
|
|
changes = []
|
2014-09-12 22:23:26 +04:00
|
|
|
copies = {}
|
2009-05-17 05:04:17 +04:00
|
|
|
seen = set()
|
2008-10-26 15:23:02 +03:00
|
|
|
entry = None
|
2014-09-12 10:57:49 +04:00
|
|
|
subexists = [False]
|
|
|
|
subdeleted = [False]
|
2016-03-23 03:05:11 +03:00
|
|
|
difftree = output.split('\x00')
|
2014-09-12 10:35:19 +04:00
|
|
|
lcount = len(difftree)
|
|
|
|
i = 0
|
2014-09-12 10:57:49 +04:00
|
|
|
|
2015-08-25 08:16:01 +03:00
|
|
|
skipsubmodules = self.ui.configbool('convert', 'git.skipsubmodules',
|
|
|
|
False)
|
2014-09-12 22:23:26 +04:00
|
|
|
def add(entry, f, isdest):
|
2014-09-12 10:57:49 +04:00
|
|
|
seen.add(f)
|
|
|
|
h = entry[3]
|
|
|
|
p = (entry[1] == "100755")
|
|
|
|
s = (entry[1] == "120000")
|
2014-09-12 22:23:26 +04:00
|
|
|
renamesource = (not isdest and entry[4][0] == 'R')
|
2014-09-12 10:57:49 +04:00
|
|
|
|
|
|
|
if f == '.gitmodules':
|
2015-08-25 08:16:01 +03:00
|
|
|
if skipsubmodules:
|
|
|
|
return
|
|
|
|
|
2014-09-12 10:57:49 +04:00
|
|
|
subexists[0] = True
|
2014-09-12 22:23:26 +04:00
|
|
|
if entry[4] == 'D' or renamesource:
|
2014-09-12 10:57:49 +04:00
|
|
|
subdeleted[0] = True
|
2016-03-02 23:42:13 +03:00
|
|
|
changes.append(('.hgsub', nodemod.nullhex))
|
2014-09-12 10:57:49 +04:00
|
|
|
else:
|
|
|
|
changes.append(('.hgsub', ''))
|
|
|
|
elif entry[1] == '160000' or entry[0] == ':160000':
|
2015-08-25 08:16:01 +03:00
|
|
|
if not skipsubmodules:
|
|
|
|
subexists[0] = True
|
2014-09-12 10:57:49 +04:00
|
|
|
else:
|
2014-09-12 22:23:26 +04:00
|
|
|
if renamesource:
|
2016-03-02 23:42:13 +03:00
|
|
|
h = nodemod.nullhex
|
2014-09-12 10:57:49 +04:00
|
|
|
self.modecache[(f, h)] = (p and "x") or (s and "l") or ""
|
|
|
|
changes.append((f, h))
|
|
|
|
|
2014-09-12 10:35:19 +04:00
|
|
|
while i < lcount:
|
|
|
|
l = difftree[i]
|
|
|
|
i += 1
|
2008-10-26 15:23:02 +03:00
|
|
|
if not entry:
|
|
|
|
if not l.startswith(':'):
|
|
|
|
continue
|
2014-09-12 10:37:47 +04:00
|
|
|
entry = l.split()
|
2007-09-25 02:00:11 +04:00
|
|
|
continue
|
2008-10-26 15:23:02 +03:00
|
|
|
f = l
|
2015-08-07 03:21:46 +03:00
|
|
|
if entry[4][0] == 'C':
|
|
|
|
copysrc = f
|
|
|
|
copydest = difftree[i]
|
|
|
|
i += 1
|
|
|
|
f = copydest
|
|
|
|
copies[copydest] = copysrc
|
2008-10-26 15:23:02 +03:00
|
|
|
if f not in seen:
|
2014-09-12 22:23:26 +04:00
|
|
|
add(entry, f, False)
|
|
|
|
# A file can be copied multiple times, or modified and copied
|
|
|
|
# simultaneously. So f can be repeated even if fdest isn't.
|
2015-08-07 03:21:46 +03:00
|
|
|
if entry[4][0] == 'R':
|
|
|
|
# rename: next line is the destination
|
2014-09-12 22:23:26 +04:00
|
|
|
fdest = difftree[i]
|
|
|
|
i += 1
|
|
|
|
if fdest not in seen:
|
|
|
|
add(entry, fdest, True)
|
|
|
|
# .gitmodules isn't imported at all, so it being copied to
|
|
|
|
# and fro doesn't really make sense
|
|
|
|
if f != '.gitmodules' and fdest != '.gitmodules':
|
|
|
|
copies[fdest] = f
|
2008-10-26 15:23:02 +03:00
|
|
|
entry = None
|
2012-10-30 04:40:13 +04:00
|
|
|
|
2014-09-12 10:57:49 +04:00
|
|
|
if subexists[0]:
|
|
|
|
if subdeleted[0]:
|
2016-03-02 23:42:13 +03:00
|
|
|
changes.append(('.hgsubstate', nodemod.nullhex))
|
2014-07-14 18:33:59 +04:00
|
|
|
else:
|
|
|
|
self.retrievegitmodules(version)
|
|
|
|
changes.append(('.hgsubstate', ''))
|
2015-03-19 19:40:19 +03:00
|
|
|
return (changes, copies, set())
|
2007-06-11 07:08:47 +04:00
|
|
|
|
|
|
|
def getcommit(self, version):
|
|
|
|
c = self.catfile(version, "commit") # read the commit hash
|
|
|
|
end = c.find("\n\n")
|
2010-01-25 09:05:27 +03:00
|
|
|
message = c[end + 2:]
|
2007-07-01 23:58:08 +04:00
|
|
|
message = self.recode(message)
|
2007-06-11 07:08:47 +04:00
|
|
|
l = c[:end].splitlines()
|
|
|
|
parents = []
|
2009-05-01 13:32:19 +04:00
|
|
|
author = committer = None
|
2016-12-23 09:28:11 +03:00
|
|
|
extra = {}
|
2007-06-11 07:08:47 +04:00
|
|
|
for e in l[1:]:
|
|
|
|
n, v = e.split(" ", 1)
|
|
|
|
if n == "author":
|
|
|
|
p = v.split()
|
|
|
|
tm, tz = p[-2:]
|
|
|
|
author = " ".join(p[:-2])
|
|
|
|
if author[0] == "<": author = author[1:-1]
|
2007-07-01 23:58:08 +04:00
|
|
|
author = self.recode(author)
|
2007-06-11 07:08:47 +04:00
|
|
|
if n == "committer":
|
|
|
|
p = v.split()
|
|
|
|
tm, tz = p[-2:]
|
|
|
|
committer = " ".join(p[:-2])
|
|
|
|
if committer[0] == "<": committer = committer[1:-1]
|
2007-07-01 23:58:08 +04:00
|
|
|
committer = self.recode(committer)
|
2010-01-25 09:05:27 +03:00
|
|
|
if n == "parent":
|
|
|
|
parents.append(v)
|
2016-12-23 09:28:11 +03:00
|
|
|
if n in self.copyextrakeys:
|
|
|
|
extra[n] = v
|
2007-06-11 07:08:47 +04:00
|
|
|
|
2017-01-14 10:21:10 +03:00
|
|
|
if self.committeractions['dropcommitter']:
|
|
|
|
committer = None
|
|
|
|
elif self.committeractions['replaceauthor']:
|
|
|
|
author = committer
|
|
|
|
|
|
|
|
if committer:
|
|
|
|
messagealways = self.committeractions['messagealways']
|
|
|
|
messagedifferent = self.committeractions['messagedifferent']
|
|
|
|
if messagealways:
|
|
|
|
message += '\n%s %s\n' % (messagealways, committer)
|
|
|
|
elif messagedifferent and author != committer:
|
|
|
|
message += '\n%s %s\n' % (messagedifferent, committer)
|
|
|
|
|
2007-06-11 07:08:47 +04:00
|
|
|
tzs, tzh, tzm = tz[-5:-4] + "1", tz[-4:-2], tz[-2:]
|
|
|
|
tz = -int(tzs) * (int(tzh) * 3600 + int(tzm))
|
|
|
|
date = tm + " " + str(tz)
|
2017-06-30 04:34:14 +03:00
|
|
|
saverev = self.ui.configbool('convert', 'git.saverev')
|
2007-06-11 07:08:47 +04:00
|
|
|
|
2016-03-02 23:42:13 +03:00
|
|
|
c = common.commit(parents=parents, date=date, author=author,
|
|
|
|
desc=message,
|
2016-12-23 09:28:11 +03:00
|
|
|
rev=version,
|
2016-12-23 09:28:35 +03:00
|
|
|
extra=extra,
|
|
|
|
saverev=saverev)
|
2007-06-11 07:08:47 +04:00
|
|
|
return c
|
|
|
|
|
2014-09-10 18:51:46 +04:00
|
|
|
def numcommits(self):
|
2016-03-23 03:05:11 +03:00
|
|
|
output, ret = self.gitrunlines('rev-list', '--all')
|
|
|
|
if ret:
|
|
|
|
raise error.Abort(_('cannot retrieve number of commits in %s') \
|
|
|
|
% self.path)
|
|
|
|
return len(output)
|
2014-09-10 18:51:46 +04:00
|
|
|
|
2007-06-11 07:08:47 +04:00
|
|
|
def gettags(self):
|
|
|
|
tags = {}
|
2012-03-14 04:13:45 +04:00
|
|
|
alltags = {}
|
2016-03-23 03:05:11 +03:00
|
|
|
output, status = self.gitrunlines('ls-remote', '--tags', self.path)
|
|
|
|
|
|
|
|
if status:
|
|
|
|
raise error.Abort(_('cannot read tags from %s') % self.path)
|
2007-06-11 07:08:47 +04:00
|
|
|
prefix = 'refs/tags/'
|
2012-03-14 04:13:45 +04:00
|
|
|
|
|
|
|
# Build complete list of tags, both annotated and bare ones
|
2016-03-23 03:05:11 +03:00
|
|
|
for line in output:
|
2007-06-11 07:08:47 +04:00
|
|
|
line = line.strip()
|
2013-02-08 17:09:48 +04:00
|
|
|
if line.startswith("error:") or line.startswith("fatal:"):
|
2015-10-08 22:55:45 +03:00
|
|
|
raise error.Abort(_('cannot read tags from %s') % self.path)
|
2007-06-11 07:08:47 +04:00
|
|
|
node, tag = line.split(None, 1)
|
|
|
|
if not tag.startswith(prefix):
|
|
|
|
continue
|
2012-03-14 04:13:45 +04:00
|
|
|
alltags[tag[len(prefix):]] = node
|
2007-06-11 07:08:47 +04:00
|
|
|
|
2012-03-14 04:13:45 +04:00
|
|
|
# Filter out tag objects for annotated tag refs
|
|
|
|
for tag in alltags:
|
|
|
|
if tag.endswith('^{}'):
|
|
|
|
tags[tag[:-3]] = alltags[tag]
|
|
|
|
else:
|
|
|
|
if tag + '^{}' in alltags:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
tags[tag] = alltags[tag]
|
|
|
|
|
2007-06-11 07:08:47 +04:00
|
|
|
return tags
|
2007-10-05 06:21:37 +04:00
|
|
|
|
|
|
|
def getchangedfiles(self, version, i):
|
|
|
|
changes = []
|
|
|
|
if i is None:
|
2016-03-23 03:05:11 +03:00
|
|
|
output, status = self.gitrunlines('diff-tree', '--root', '-m',
|
|
|
|
'-r', version)
|
|
|
|
if status:
|
|
|
|
raise error.Abort(_('cannot read changes in %s') % version)
|
|
|
|
for l in output:
|
2007-10-05 06:21:37 +04:00
|
|
|
if "\t" not in l:
|
|
|
|
continue
|
|
|
|
m, f = l[:-1].split("\t")
|
|
|
|
changes.append(f)
|
|
|
|
else:
|
2016-03-23 03:05:11 +03:00
|
|
|
output, status = self.gitrunlines('diff-tree', '--name-only',
|
|
|
|
'--root', '-r', version,
|
|
|
|
'%s^%s' % (version, i + 1), '--')
|
2016-04-04 16:38:48 +03:00
|
|
|
if status:
|
|
|
|
raise error.Abort(_('cannot read changes in %s') % version)
|
2016-03-23 03:05:11 +03:00
|
|
|
changes = [f.rstrip('\n') for f in output]
|
2007-10-05 06:21:37 +04:00
|
|
|
|
|
|
|
return changes
|
2011-03-25 03:38:43 +03:00
|
|
|
|
|
|
|
def getbookmarks(self):
|
|
|
|
bookmarks = {}
|
|
|
|
|
2015-07-29 23:21:03 +03:00
|
|
|
# Handle local and remote branches
|
2017-06-30 04:34:00 +03:00
|
|
|
remoteprefix = self.ui.config('convert', 'git.remoteprefix')
|
2015-07-29 23:21:03 +03:00
|
|
|
reftypes = [
|
|
|
|
# (git prefix, hg prefix)
|
|
|
|
('refs/remotes/origin/', remoteprefix + '/'),
|
|
|
|
('refs/heads/', '')
|
|
|
|
]
|
2011-03-25 03:38:43 +03:00
|
|
|
|
2017-02-11 03:56:29 +03:00
|
|
|
exclude = {
|
2015-07-29 23:21:03 +03:00
|
|
|
'refs/remotes/origin/HEAD',
|
2017-02-11 03:56:29 +03:00
|
|
|
}
|
2015-07-29 23:21:03 +03:00
|
|
|
|
|
|
|
try:
|
2016-03-23 03:05:11 +03:00
|
|
|
output, status = self.gitrunlines('show-ref')
|
|
|
|
for line in output:
|
2015-07-29 23:21:03 +03:00
|
|
|
line = line.strip()
|
|
|
|
rev, name = line.split(None, 1)
|
|
|
|
# Process each type of branch
|
|
|
|
for gitprefix, hgprefix in reftypes:
|
|
|
|
if not name.startswith(gitprefix) or name in exclude:
|
2011-03-25 03:38:43 +03:00
|
|
|
continue
|
2015-07-29 23:21:03 +03:00
|
|
|
name = '%s%s' % (hgprefix, name[len(gitprefix):])
|
2011-03-25 03:38:43 +03:00
|
|
|
bookmarks[name] = rev
|
2015-07-29 23:21:03 +03:00
|
|
|
except Exception:
|
|
|
|
pass
|
2011-03-25 03:38:43 +03:00
|
|
|
|
|
|
|
return bookmarks
|
2013-04-26 03:02:58 +04:00
|
|
|
|
2014-01-21 21:34:55 +04:00
|
|
|
def checkrevformat(self, revstr, mapname='splicemap'):
|
2013-04-26 03:02:58 +04:00
|
|
|
""" git revision string is a 40 byte hex """
|
2014-01-21 21:34:55 +04:00
|
|
|
self.checkhexformat(revstr, mapname)
|