##// END OF EJS Templates
Remove trailing spaces, fix indentation
Remove trailing spaces, fix indentation

File last commit:

r5143:d4fa6baf default
r5143:d4fa6baf default
Show More
hg.py
178 lines | 5.5 KiB | text/x-python | PythonLexer
Brendan Cully
Split convert extension into common and repository type modules
r4536 # hg backend for convert extension
Bryan O'Sullivan
convert: Support Mercurial as a source, as well as a sink
r5013 # Note for hg->hg conversion: Old versions of Mercurial didn't trim
# the whitespace from the ends of commit messages, but new versions
# do. Changesets created by those older versions, then converted, may
# thus have different hashes for changesets that are otherwise
# identical.
Brendan Cully
Split convert extension into common and repository type modules
r4536 import os, time
Bryan O'Sullivan
convert: acquire/release locks periodically
r5014 from mercurial.i18n import _
Bryan O'Sullivan
convert: Support Mercurial as a source, as well as a sink
r5013 from mercurial.node import *
Bryan O'Sullivan
convert: acquire/release locks periodically
r5014 from mercurial import hg, lock, revlog, util
Brendan Cully
Split convert extension into common and repository type modules
r4536
Bryan O'Sullivan
convert: Support Mercurial as a source, as well as a sink
r5013 from common import NoRepo, commit, converter_source, converter_sink
Brendan Cully
Split convert extension into common and repository type modules
r4536
Bryan O'Sullivan
convert: Support Mercurial as a source, as well as a sink
r5013 class mercurial_sink(converter_sink):
Brendan Cully
convert: split converter into convertsource and convertsink
r4763 def __init__(self, ui, path):
Brendan Cully
Split convert extension into common and repository type modules
r4536 self.path = path
self.ui = ui
try:
self.repo = hg.repository(self.ui, path)
except:
Bryan O'Sullivan
convert: Support Mercurial as a source, as well as a sink
r5013 raise NoRepo("could not open hg repo %s as sink" % path)
Bryan O'Sullivan
convert: acquire/release locks periodically
r5014 self.lock = None
self.wlock = None
Bryan O'Sullivan
convert: add config option to turn off use of branch names
r5038 self.branchnames = ui.configbool('convert', 'hg.usebranchnames', True)
Bryan O'Sullivan
convert: acquire/release locks periodically
r5014
def before(self):
Alexis S. L. Carvalho
convert: fix locking order
r5052 self.wlock = self.repo.wlock()
Bryan O'Sullivan
convert: acquire/release locks periodically
r5014 self.lock = self.repo.lock()
def after(self):
self.lock = None
self.wlock = None
Brendan Cully
Split convert extension into common and repository type modules
r4536
Bryan O'Sullivan
convert: rename mapfile to revmapfile, so we can map more than just revs
r5011 def revmapfile(self):
Brendan Cully
Split convert extension into common and repository type modules
r4536 return os.path.join(self.path, ".hg", "shamap")
Edouard Gomez
convert extension: Add support for username mapping...
r4589 def authorfile(self):
return os.path.join(self.path, ".hg", "authormap")
Brendan Cully
Split convert extension into common and repository type modules
r4536 def getheads(self):
h = self.repo.changelog.heads()
Bryan O'Sullivan
convert: get rid of "hg." prefix where not needed
r5017 return [ hex(x) for x in h ]
Brendan Cully
Split convert extension into common and repository type modules
r4536
def putfile(self, f, e, data):
self.repo.wwrite(f, data, e)
Matt Mackall
dirstate: add __contains__ and make __getitem__ more useful...
r4906 if f not in self.repo.dirstate:
Matt Mackall
dirstate: break update into separate functions
r4904 self.repo.dirstate.add(f)
Brendan Cully
Split convert extension into common and repository type modules
r4536
Daniel Holth
convert extension: Add SVN converter
r4765 def copyfile(self, source, dest):
self.repo.copy(source, dest)
Brendan Cully
Split convert extension into common and repository type modules
r4536 def delfile(self, f):
try:
os.unlink(self.repo.wjoin(f))
#self.repo.remove([f])
except:
pass
def putcommit(self, files, parents, commit):
Bryan O'Sullivan
convert: add filename filtering and renaming support
r5016 if not files:
return hex(self.repo.changelog.tip())
seen = {hex(nullid): 1}
Brendan Cully
Split convert extension into common and repository type modules
r4536 pl = []
for p in parents:
if p not in seen:
pl.append(p)
seen[p] = 1
parents = pl
if len(parents) < 2: parents.append("0" * 40)
if len(parents) < 2: parents.append("0" * 40)
p2 = parents.pop(0)
text = commit.desc
extra = {}
Bryan O'Sullivan
convert: add config option to turn off use of branch names
r5038 if self.branchnames and commit.branch:
Brendan Cully
convert: record the source revision in the changelog
r4873 extra['branch'] = commit.branch
if commit.rev:
extra['convert_revision'] = commit.rev
Thomas Arendsen Hein
removed trailing whitespace
r4957
Brendan Cully
Split convert extension into common and repository type modules
r4536 while parents:
p1 = p2
p2 = parents.pop(0)
a = self.repo.rawcommit(files, text, commit.author, commit.date,
Bryan O'Sullivan
convert: get rid of "hg." prefix where not needed
r5017 bin(p1), bin(p2), extra=extra)
Bryan O'Sullivan
convert: acquire/release locks periodically
r5014 self.repo.dirstate.invalidate()
Brendan Cully
Split convert extension into common and repository type modules
r4536 text = "(octopus merge fixup)\n"
p2 = hg.hex(self.repo.changelog.tip())
return p2
def puttags(self, tags):
try:
old = self.repo.wfile(".hgtags").read()
oldlines = old.splitlines(1)
oldlines.sort()
except:
oldlines = []
k = tags.keys()
k.sort()
newlines = []
for tag in k:
newlines.append("%s %s\n" % (tags[tag], tag))
newlines.sort()
if newlines != oldlines:
self.ui.status("updating tags\n")
f = self.repo.wfile(".hgtags", "w")
f.write("".join(newlines))
f.close()
if not oldlines: self.repo.add([".hgtags"])
date = "%s 0" % int(time.mktime(time.gmtime()))
self.repo.rawcommit([".hgtags"], "update tags", "convert-repo",
Bryan O'Sullivan
convert: get rid of "hg." prefix where not needed
r5017 date, self.repo.changelog.tip(), nullid)
return hex(self.repo.changelog.tip())
Bryan O'Sullivan
convert: Support Mercurial as a source, as well as a sink
r5013
class mercurial_source(converter_source):
def __init__(self, ui, path, rev=None):
converter_source.__init__(self, ui, path, rev)
self.repo = hg.repository(self.ui, path)
self.lastrev = None
self.lastctx = None
def changectx(self, rev):
if self.lastrev != rev:
self.lastctx = self.repo.changectx(rev)
self.lastrev = rev
return self.lastctx
def getheads(self):
Bryan O'Sullivan
convert: only get history for requested revs when converting hg repo
r5131 if self.rev:
return [hex(self.repo.changectx(self.rev).node())]
else:
return [hex(node) for node in self.repo.heads()]
Bryan O'Sullivan
convert: Support Mercurial as a source, as well as a sink
r5013
def getfile(self, name, rev):
try:
return self.changectx(rev).filectx(name).data()
except revlog.LookupError, err:
raise IOError(err)
def getmode(self, name, rev):
m = self.changectx(rev).manifest()
return (m.execf(name) and 'x' or '') + (m.linkf(name) and 'l' or '')
def getchanges(self, rev):
ctx = self.changectx(rev)
m, a, r = self.repo.status(ctx.parents()[0].node(), ctx.node())[:3]
changes = [(name, rev) for name in m + a + r]
changes.sort()
Brendan Cully
convert: look up copies in getchanges instead of getcommit...
r5121 return (changes, self.getcopies(ctx))
Bryan O'Sullivan
convert: Support Mercurial as a source, as well as a sink
r5013
def getcopies(self, ctx):
added = self.repo.status(ctx.parents()[0].node(), ctx.node())[1]
copies = {}
for name in added:
try:
copies[name] = ctx.filectx(name).renamed()[0]
except TypeError:
pass
return copies
Thomas Arendsen Hein
Remove trailing spaces, fix indentation
r5143
Bryan O'Sullivan
convert: Support Mercurial as a source, as well as a sink
r5013 def getcommit(self, rev):
ctx = self.changectx(rev)
parents = [hex(p.node()) for p in ctx.parents() if p.node() != nullid]
return commit(author=ctx.user(), date=util.datestr(ctx.date()),
desc=ctx.description(), parents=parents,
Brendan Cully
convert: look up copies in getchanges instead of getcommit...
r5121 branch=ctx.branch())
Bryan O'Sullivan
convert: Support Mercurial as a source, as well as a sink
r5013
def gettags(self):
tags = [t for t in self.repo.tagslist() if t[0] != 'tip']
return dict([(name, hex(node)) for name, node in tags])