##// END OF EJS Templates
check-code: detect legacy exception syntax...
check-code: detect legacy exception syntax We just rewrote all files to use modern exception syntax. Ban the old form. This will detect the "except type, instance" and "except (type1, type2), instance" forms.

File last commit:

r25660:328739ea default
r25661:20de1ace default
Show More
transplant.py
702 lines | 26.5 KiB | text/x-python | PythonLexer
Brendan Cully
Add transplant extension
r3714 # Patch transplanting extension for Mercurial
#
Thomas Arendsen Hein
Updated copyright notices and add "and others" to "hg version"
r4635 # Copyright 2006, 2007 Brendan Cully <brendan@kublai.com>
Brendan Cully
Add transplant extension
r3714 #
Martin Geisler
updated license to be explicit about GPL version 2
r8225 # This software may be used and distributed according to the terms of the
Matt Mackall
Update license to GPLv2+
r10263 # GNU General Public License version 2 or any later version.
Brendan Cully
Add transplant extension
r3714
Dirkjan Ochtman
extensions: change descriptions for extensions providing a few commands
r8934 '''command to transplant changesets from another branch
Brendan Cully
Add transplant extension
r3714
Mads Kiilerich
transplant: improve documentation
r19028 This extension allows you to transplant changes to another parent revision,
possibly in another repository. The transplant is done using 'diff' patches.
Brendan Cully
Add transplant extension
r3714
Martin Geisler
transplant: word-wrap help texts at 70 characters
r8000 Transplanted patches are recorded in .hg/transplant/transplants, as a
map from a changeset hash to its hash in the source repository.
Brendan Cully
Add transplant extension
r3714 '''
Dirkjan Ochtman
transplant: move docstrings before imports (see issue1466)
r7629 from mercurial.i18n import _
import os, tempfile
Matt Mackall
revlog: stop exporting node.short
r14393 from mercurial.node import short
Matt Mackall
scmutil: move revsingle/pair/range from cmdutil...
r14319 from mercurial import bundlerepo, hg, merge, match
from mercurial import patch, revlog, scmutil, util, error, cmdutil
Pierre-Yves David
transplant: use exchange.pull...
r22699 from mercurial import revset, templatekw, exchange
Dirkjan Ochtman
transplant: move docstrings before imports (see issue1466)
r7629
Patrick Mezard
transplant: do not rollback on patching error (issue3379)...
r16507 class TransplantError(error.Abort):
pass
Adrian Buehlmann
transplant: use cmdutil.command decorator
r14308 cmdtable = {}
command = cmdutil.command(cmdtable)
Augie Fackler
extensions: document that `testedwith = 'internal'` is special...
r25186 # Note for extension authors: ONLY specify testedwith = 'internal' for
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
# be specifying the version(s) of Mercurial they are tested with, or
# leave the attribute unspecified.
Augie Fackler
hgext: mark all first-party extensions as such
r16743 testedwith = 'internal'
Adrian Buehlmann
transplant: use cmdutil.command decorator
r14308
Benoit Boissinot
use new style classes
r8778 class transplantentry(object):
Brendan Cully
Add transplant extension
r3714 def __init__(self, lnode, rnode):
self.lnode = lnode
self.rnode = rnode
Benoit Boissinot
use new style classes
r8778 class transplants(object):
Brendan Cully
Add transplant extension
r3714 def __init__(self, path=None, transplantfile=None, opener=None):
self.path = path
self.transplantfile = transplantfile
self.opener = opener
if not opener:
Adrian Buehlmann
move opener from util to scmutil
r13970 self.opener = scmutil.opener(self.path)
Peter Arrenbrecht
transplant: maintain list of transplants in dict
r12313 self.transplants = {}
Brendan Cully
Add transplant extension
r3714 self.dirty = False
self.read()
def read(self):
abspath = os.path.join(self.path, self.transplantfile)
if self.transplantfile and os.path.exists(abspath):
Dan Villiom Podlaski Christiansen
prevent transient leaks of file handle by using new helper functions...
r14168 for line in self.opener.read(self.transplantfile).splitlines():
Brendan Cully
Add transplant extension
r3714 lnode, rnode = map(revlog.bin, line.split(':'))
Peter Arrenbrecht
transplant: maintain list of transplants in dict
r12313 list = self.transplants.setdefault(rnode, [])
list.append(transplantentry(lnode, rnode))
Brendan Cully
Add transplant extension
r3714
def write(self):
if self.dirty and self.transplantfile:
if not os.path.isdir(self.path):
os.mkdir(self.path)
fp = self.opener(self.transplantfile, 'w')
Peter Arrenbrecht
transplant: fix var name conflict introduced by 2912881c2a98
r12349 for list in self.transplants.itervalues():
for t in list:
l, r = map(revlog.hex, (t.lnode, t.rnode))
Peter Arrenbrecht
transplant: maintain list of transplants in dict
r12313 fp.write(l + ':' + r + '\n')
Brendan Cully
Add transplant extension
r3714 fp.close()
self.dirty = False
def get(self, rnode):
Peter Arrenbrecht
transplant: maintain list of transplants in dict
r12313 return self.transplants.get(rnode) or []
Brendan Cully
Add transplant extension
r3714
def set(self, lnode, rnode):
Peter Arrenbrecht
transplant: maintain list of transplants in dict
r12313 list = self.transplants.setdefault(rnode, [])
list.append(transplantentry(lnode, rnode))
Brendan Cully
Add transplant extension
r3714 self.dirty = True
def remove(self, transplant):
Peter Arrenbrecht
transplant: maintain list of transplants in dict
r12313 list = self.transplants.get(transplant.rnode)
if list:
del list[list.index(transplant)]
self.dirty = True
Brendan Cully
Add transplant extension
r3714
Benoit Boissinot
use new style classes
r8778 class transplanter(object):
FUJIWARA Katsunori
transplant: use "getcommiteditor()" instead of explicit editor choice...
r21411 def __init__(self, ui, repo, opts):
Brendan Cully
Add transplant extension
r3714 self.ui = ui
self.path = repo.join('transplant')
Adrian Buehlmann
move opener from util to scmutil
r13970 self.opener = scmutil.opener(self.path)
Martin Geisler
transplant: wrapped long lines
r7744 self.transplants = transplants(self.path, 'transplants',
opener=self.opener)
FUJIWARA Katsunori
transplant: change "editform" to distinguish merge commits from others...
r22252 def getcommiteditor():
editform = cmdutil.mergeeditform(repo[None], 'transplant')
return cmdutil.getcommiteditor(editform=editform, **opts)
self.getcommiteditor = getcommiteditor
Brendan Cully
Add transplant extension
r3714
def applied(self, repo, node, parent):
'''returns True if a node is already an ancestor of parent
Joshua Redstone
transplant: convert applied() algorithm from nodes to revs...
r17010 or is parent or has already been transplanted'''
if hasnode(repo, parent):
parentrev = repo.changelog.rev(parent)
Brendan Cully
Add transplant extension
r3714 if hasnode(repo, node):
Joshua Redstone
transplant: convert applied() algorithm from nodes to revs...
r17010 rev = repo.changelog.rev(node)
Siddharth Agarwal
transplant: replace incancestors uses with ancestors
r18082 reachable = repo.changelog.ancestors([parentrev], rev,
inclusive=True)
Joshua Redstone
transplant: convert applied() algorithm from nodes to revs...
r17010 if rev in reachable:
Brendan Cully
Add transplant extension
r3714 return True
for t in self.transplants.get(node):
# it might have been stripped
if not hasnode(repo, t.lnode):
self.transplants.remove(t)
return False
Joshua Redstone
transplant: convert applied() algorithm from nodes to revs...
r17010 lnoderev = repo.changelog.rev(t.lnode)
Siddharth Agarwal
transplant: replace incancestors uses with ancestors
r18082 if lnoderev in repo.changelog.ancestors([parentrev], lnoderev,
inclusive=True):
Brendan Cully
Add transplant extension
r3714 return True
return False
def apply(self, repo, source, revmap, merges, opts={}):
'''apply the revisions in revmap one by one in revision order'''
Matt Mackall
replace util.sort with sorted built-in...
r8209 revs = sorted(revmap)
Brendan Cully
Add transplant extension
r3714 p1, p2 = repo.dirstate.parents()
pulls = []
Siddharth Agarwal
transplant: don't honor whitespace and format-changing diffopts...
r23452 diffopts = patch.difffeatureopts(self.ui, opts)
Brendan Cully
Add transplant extension
r3714 diffopts.git = True
Greg Ward
transplant: wrap a transaction around the whole command
r15204 lock = wlock = tr = None
Brendan Cully
Add transplant extension
r3714 try:
Matt Mackall
Use try/finally pattern to cleanup locks and transactions
r4915 wlock = repo.wlock()
lock = repo.lock()
Greg Ward
transplant: wrap a transaction around the whole command
r15204 tr = repo.transaction('transplant')
Brendan Cully
Add transplant extension
r3714 for rev in revs:
node = revmap[rev]
Matt Mackall
revlog: stop exporting node.short
r14393 revstr = '%s:%s' % (rev, short(node))
Brendan Cully
Add transplant extension
r3714
if self.applied(repo, node, p1):
self.ui.warn(_('skipping already applied revision %s\n') %
revstr)
continue
parents = source.changelog.parents(node)
Levi Bard
transplant: manually transplant pullable changesets with --log
r16627 if not (opts.get('filter') or opts.get('log')):
Martin Geisler
transplant: wrapped long lines
r7744 # If the changeset parent is the same as the
# wdir's parent, just pull it.
Brendan Cully
Add transplant extension
r3714 if parents[0] == p1:
pulls.append(node)
p1 = node
continue
if pulls:
if source != repo:
Pierre-Yves David
transplant: use exchange.pull...
r22699 exchange.pull(repo, source.peer(), heads=pulls)
Matt Mackall
Make repo locks recursive, eliminate all passing of lock/wlock
r4917 merge.update(repo, pulls[-1], False, False, None)
Brendan Cully
Add transplant extension
r3714 p1, p2 = repo.dirstate.parents()
pulls = []
domerge = False
if node in merges:
Martin Geisler
transplant: wrapped long lines
r7744 # pulling all the merge revs at once would mean we
# couldn't transplant after the latest even if
# transplants before them fail.
Brendan Cully
Add transplant extension
r3714 domerge = True
if not hasnode(repo, node):
Pierre-Yves David
transplant: use exchange.pull...
r22699 exchange.pull(repo, source.peer(), heads=[node])
Brendan Cully
Add transplant extension
r3714
Steven Stallion
transplant: permit merge changesets via --parent...
r16400 skipmerge = False
Brendan Cully
Add transplant extension
r3714 if parents[1] != revlog.nullid:
Steven Stallion
transplant: permit merge changesets via --parent...
r16400 if not opts.get('parent'):
self.ui.note(_('skipping merge changeset %s:%s\n')
% (rev, short(node)))
skipmerge = True
else:
parent = source.lookup(opts['parent'])
if parent not in parents:
raise util.Abort(_('%s is not a parent of %s') %
(short(parent), short(node)))
else:
parent = parents[0]
if skipmerge:
Brendan Cully
Add transplant extension
r3714 patchfile = None
else:
fd, patchfile = tempfile.mkstemp(prefix='hg-transplant-')
fp = os.fdopen(fd, 'w')
Steven Stallion
transplant: permit merge changesets via --parent...
r16400 gen = patch.diff(source, parent, node, opts=diffopts)
Dirkjan Ochtman
patch: turn patch.diff() into a generator...
r7308 for chunk in gen:
fp.write(chunk)
Brendan Cully
Add transplant extension
r3714 fp.close()
del revmap[rev]
if patchfile or domerge:
try:
Patrick Mezard
transplant: do not rollback on patching error (issue3379)...
r16507 try:
n = self.applyone(repo, node,
source.changelog.read(node),
patchfile, merge=domerge,
log=opts.get('log'),
filter=opts.get('filter'))
except TransplantError:
# Do not rollback, it is up to the user to
# fix the merge or cancel everything
tr.close()
raise
Brendan Cully
transplant: fix ignoring empty changesets (eg after filter)
r4251 if n and domerge:
Brendan Cully
Add transplant extension
r3714 self.ui.status(_('%s merged at %s\n') % (revstr,
Matt Mackall
revlog: stop exporting node.short
r14393 short(n)))
Brendan Cully
transplant: fix ignoring empty changesets (eg after filter)
r4251 elif n:
Martin Geisler
transplant: wrapped long lines
r7744 self.ui.status(_('%s transplanted to %s\n')
Matt Mackall
revlog: stop exporting node.short
r14393 % (short(node),
short(n)))
Brendan Cully
Add transplant extension
r3714 finally:
if patchfile:
os.unlink(patchfile)
Greg Ward
transplant: wrap a transaction around the whole command
r15204 tr.close()
Brendan Cully
Add transplant extension
r3714 if pulls:
Pierre-Yves David
transplant: use exchange.pull...
r22699 exchange.pull(repo, source.peer(), heads=pulls)
Matt Mackall
Make repo locks recursive, eliminate all passing of lock/wlock
r4917 merge.update(repo, pulls[-1], False, False, None)
Brendan Cully
Add transplant extension
r3714 finally:
self.saveseries(revmap, merges)
self.transplants.write()
Greg Ward
transplant: wrap a transaction around the whole command
r15204 if tr:
tr.release()
Ronny Pfannschmidt
switch lock releasing in the extensions from gc to explicit
r8112 lock.release()
wlock.release()
Brendan Cully
Add transplant extension
r3714
Luke Plant
transplant: added 'HGREVISION' variable to the environment passed to the 'filter' command...
r13579 def filter(self, filter, node, changelog, patchfile):
Brendan Cully
Add transplant extension
r3714 '''arbitrarily rewrite changeset before applying it'''
Martin Geisler
i18n: mark strings for translation in transplant extension
r6966 self.ui.status(_('filtering %s\n') % patchfile)
Brendan Cully
transplant: split filter args into changelog entry and patch
r3759 user, date, msg = (changelog[1], changelog[2], changelog[4])
fd, headerfile = tempfile.mkstemp(prefix='hg-transplant-')
fp = os.fdopen(fd, 'w')
fp.write("# HG changeset patch\n")
fp.write("# User %s\n" % user)
fp.write("# Date %d %d\n" % date)
Mads Kiilerich
transplant: Add trailing LF in tmp file for filtering...
r9433 fp.write(msg + '\n')
Brendan Cully
transplant: split filter args into changelog entry and patch
r3759 fp.close()
try:
Yuya Nishihara
util.system: use ui.system() in place of optional ui.fout parameter
r23270 self.ui.system('%s %s %s' % (filter, util.shellquote(headerfile),
util.shellquote(patchfile)),
environ={'HGUSER': changelog[1],
'HGREVISION': revlog.hex(node),
},
onerr=util.Abort, errprefix=_('filter failed'))
Brendan Cully
transplant: split filter args into changelog entry and patch
r3759 user, date, msg = self.parselog(file(headerfile))[1:4]
finally:
os.unlink(headerfile)
return (user, date, msg)
Brendan Cully
Add transplant extension
r3714
def applyone(self, repo, node, cl, patchfile, merge=False, log=False,
Matt Mackall
Make repo locks recursive, eliminate all passing of lock/wlock
r4917 filter=None):
Brendan Cully
Add transplant extension
r3714 '''apply the patch in patchfile to the repository as a transplant'''
(manifest, user, (time, timezone), files, message) = cl[:5]
date = "%d %d" % (time, timezone)
extra = {'transplant_source': node}
if filter:
Luke Plant
transplant: added 'HGREVISION' variable to the environment passed to the 'filter' command...
r13579 (user, date, message) = self.filter(filter, node, cl, patchfile)
Brendan Cully
Add transplant extension
r3714
if log:
Martin Geisler
do not translate commit messages...
r9183 # we don't translate messages inserted into commits
Brendan Cully
Add transplant extension
r3714 message += '\n(transplanted from %s)' % revlog.hex(node)
Matt Mackall
revlog: stop exporting node.short
r14393 self.ui.status(_('applying %s\n') % short(node))
Brendan Cully
Add transplant extension
r3714 self.ui.note('%s %s\n%s\n' % (user, date, message))
if not patchfile and not merge:
raise util.Abort(_('can only omit patchfile if merging'))
if patchfile:
try:
Patrick Mezard
patch: turn patch() touched files dict into a set
r14564 files = set()
Patrick Mezard
patch: remove patch.patch() cwd argument
r14382 patch.patch(self.ui, repo, patchfile, files=files, eolmode=None)
Patrick Mezard
patch: make patch()/internalpatch() always update the dirstate
r14260 files = list(files)
Gregory Szorc
global: mass rewrite to use modern exception syntax...
r25660 except Exception as inst:
Brendan Cully
transplant: clobber old series when transplant fails
r3757 seriespath = os.path.join(self.path, 'series')
if os.path.exists(seriespath):
os.unlink(seriespath)
Matt Mackall
misc: replace .parents()[0] with p1()
r13878 p1 = repo.dirstate.p1()
Brendan Cully
Add transplant extension
r3714 p2 = node
Brendan Cully
transplant: preserve filter changes in --continue log
r3725 self.log(user, date, message, p1, p2, merge=merge)
Brendan Cully
Add transplant extension
r3714 self.ui.write(str(inst) + '\n')
Patrick Mezard
transplant: do not rollback on patching error (issue3379)...
r16507 raise TransplantError(_('fix up the merge and run '
'hg transplant --continue'))
Brendan Cully
Add transplant extension
r3714 else:
files = None
if merge:
p1, p2 = repo.dirstate.parents()
Patrick Mezard
localrepo: add setparents() to adjust dirstate copies (issue3407)...
r16551 repo.setparents(p1, node)
Matt Mackall
transplant: use match object rather than files for commit
r8703 m = match.always(repo.root, '')
else:
m = match.exact(repo.root, '', files)
Brendan Cully
Add transplant extension
r3714
Matt Mackall
transplant: add --edit option
r15220 n = repo.commit(message, user, date, extra=extra, match=m,
FUJIWARA Katsunori
transplant: change "editform" to distinguish merge commits from others...
r22252 editor=self.getcommiteditor())
Greg Ward
transplant: crash if repo.commit() finds nothing to commit...
r11638 if not n:
Patrick Mezard
transplant: fix emptied changeset message...
r17320 self.ui.warn(_('skipping emptied changeset %s\n') % short(node))
Patrick Mezard
transplant: handle non-empty patches doing nothing (issue2806)...
r17319 return None
Brendan Cully
Add transplant extension
r3714 if not merge:
self.transplants.set(n, node)
return n
Bryan O'Sullivan
repoview: remove unreachable code...
r18919 def resume(self, repo, source, opts):
Brendan Cully
Add transplant extension
r3714 '''recover last transaction and apply remaining changesets'''
if os.path.exists(os.path.join(self.path, 'journal')):
Bryan O'Sullivan
transplant: pass source through to recover
r18926 n, node = self.recover(repo, source, opts)
Pierre-Yves David
transplant: properly skip empty changeset (issue4423)...
r23781 if n:
self.ui.status(_('%s transplanted as %s\n') % (short(node),
short(n)))
else:
self.ui.status(_('%s skipped due to empty diff\n')
% (short(node),))
Brendan Cully
Add transplant extension
r3714 seriespath = os.path.join(self.path, 'series')
if not os.path.exists(seriespath):
Brendan Cully
transplant: log source node when recovering too.
r3758 self.transplants.write()
Brendan Cully
Add transplant extension
r3714 return
nodes, merges = self.readseries()
revmap = {}
for n in nodes:
revmap[source.changelog.rev(n)] = n
os.unlink(seriespath)
self.apply(repo, source, revmap, merges, opts)
Bryan O'Sullivan
transplant: pass source through to recover
r18926 def recover(self, repo, source, opts):
Brendan Cully
Add transplant extension
r3714 '''commit working directory using journal metadata'''
node, user, date, message, parents = self.readlog()
Steven Stallion
transplant: permit merge changesets via --parent...
r16400 merge = False
Brendan Cully
Add transplant extension
r3714
if not user or not date or not message or not parents[0]:
raise util.Abort(_('transplant log file is corrupt'))
Steven Stallion
transplant: permit merge changesets via --parent...
r16400 parent = parents[0]
if len(parents) > 1:
if opts.get('parent'):
parent = source.lookup(opts['parent'])
if parent not in parents:
raise util.Abort(_('%s is not a parent of %s') %
(short(parent), short(node)))
else:
merge = True
Brendan Cully
transplant: log source node when recovering too.
r3758 extra = {'transplant_source': node}
Brendan Cully
Add transplant extension
r3714 wlock = repo.wlock()
Matt Mackall
Use try/finally pattern to cleanup locks and transactions
r4915 try:
p1, p2 = repo.dirstate.parents()
Steven Stallion
transplant: permit merge changesets via --parent...
r16400 if p1 != parent:
Yuya Nishihara
commands: say "working directory" in full spelling
r24365 raise util.Abort(_('working directory not at transplant '
'parent %s') % revlog.hex(parent))
Matt Mackall
Use try/finally pattern to cleanup locks and transactions
r4915 if merge:
Patrick Mezard
localrepo: add setparents() to adjust dirstate copies (issue3407)...
r16551 repo.setparents(p1, parents[1])
Pierre-Yves David
transplant: properly skip empty changeset (issue4423)...
r23781 modified, added, removed, deleted = repo.status()[:4]
if merge or modified or added or removed or deleted:
n = repo.commit(message, user, date, extra=extra,
editor=self.getcommiteditor())
if not n:
raise util.Abort(_('commit failed'))
if not merge:
self.transplants.set(n, node)
else:
n = None
Matt Mackall
Use try/finally pattern to cleanup locks and transactions
r4915 self.unlog()
Brendan Cully
Add transplant extension
r3714
Matt Mackall
Use try/finally pattern to cleanup locks and transactions
r4915 return n, node
finally:
Ronny Pfannschmidt
switch lock releasing in the extensions from gc to explicit
r8112 wlock.release()
Brendan Cully
Add transplant extension
r3714
def readseries(self):
nodes = []
merges = []
cur = nodes
Dan Villiom Podlaski Christiansen
prevent transient leaks of file handle by using new helper functions...
r14168 for line in self.opener.read('series').splitlines():
Brendan Cully
Add transplant extension
r3714 if line.startswith('# Merges'):
cur = merges
continue
cur.append(revlog.bin(line))
return (nodes, merges)
def saveseries(self, revmap, merges):
if not revmap:
return
if not os.path.isdir(self.path):
os.mkdir(self.path)
series = self.opener('series', 'w')
Matt Mackall
replace util.sort with sorted built-in...
r8209 for rev in sorted(revmap):
Brendan Cully
Add transplant extension
r3714 series.write(revlog.hex(revmap[rev]) + '\n')
if merges:
series.write('# Merges\n')
for m in merges:
series.write(revlog.hex(m) + '\n')
series.close()
Brendan Cully
transplant: split filter args into changelog entry and patch
r3759 def parselog(self, fp):
parents = []
message = []
node = revlog.nullid
inmsg = False
Luke Plant
transplant: fix crash if filter script munges log file...
r13789 user = None
date = None
Brendan Cully
transplant: split filter args into changelog entry and patch
r3759 for line in fp.read().splitlines():
if inmsg:
message.append(line)
elif line.startswith('# User '):
user = line[7:]
elif line.startswith('# Date '):
date = line[7:]
elif line.startswith('# Node ID '):
node = revlog.bin(line[10:])
elif line.startswith('# Parent '):
parents.append(revlog.bin(line[9:]))
Georg Brandl
transplant: when reading journal, treat only lines starting with "# " special like patch.extract() does
r11411 elif not line.startswith('# '):
Brendan Cully
transplant: split filter args into changelog entry and patch
r3759 inmsg = True
message.append(line)
Luke Plant
transplant: fix crash if filter script munges log file...
r13789 if None in (user, date):
Brendan Cully
Fix transplant error message to correspond with test
r13790 raise util.Abort(_("filter corrupted changeset (no user or date)"))
Brendan Cully
transplant: split filter args into changelog entry and patch
r3759 return (node, user, date, '\n'.join(message), parents)
Thomas Arendsen Hein
Removed trailing whitespace and tabs from python files
r4516
Brendan Cully
transplant: preserve filter changes in --continue log
r3725 def log(self, user, date, message, p1, p2, merge=False):
Brendan Cully
Add transplant extension
r3714 '''journal changelog metadata for later recover'''
if not os.path.isdir(self.path):
os.mkdir(self.path)
fp = self.opener('journal', 'w')
Brendan Cully
transplant: preserve filter changes in --continue log
r3725 fp.write('# User %s\n' % user)
fp.write('# Date %s\n' % date)
Brendan Cully
Add transplant extension
r3714 fp.write('# Node ID %s\n' % revlog.hex(p2))
fp.write('# Parent ' + revlog.hex(p1) + '\n')
if merge:
fp.write('# Parent ' + revlog.hex(p2) + '\n')
Brendan Cully
transplant: preserve filter changes in --continue log
r3725 fp.write(message.rstrip() + '\n')
Brendan Cully
Add transplant extension
r3714 fp.close()
def readlog(self):
Brendan Cully
transplant: split filter args into changelog entry and patch
r3759 return self.parselog(self.opener('journal'))
Brendan Cully
Add transplant extension
r3714
def unlog(self):
'''remove changelog journal'''
absdst = os.path.join(self.path, 'journal')
if os.path.exists(absdst):
os.unlink(absdst)
def transplantfilter(self, repo, source, root):
def matchfn(node):
if self.applied(repo, node, root):
return False
if source.changelog.parents(node)[1] != revlog.nullid:
return False
extra = source.changelog.read(node)[5]
cnode = extra.get('transplant_source')
if cnode and self.applied(repo, cnode, root):
return False
return True
return matchfn
def hasnode(repo, node):
try:
Martin Geisler
code style: prefer 'is' and 'is not' tests with singletons
r13031 return repo.changelog.rev(node) is not None
Matt Mackall
errors: move revlog errors...
r7633 except error.RevlogError:
Brendan Cully
Add transplant extension
r3714 return False
def browserevs(ui, repo, nodes, opts):
'''interactively transplant changesets'''
Brendan Cully
transplant: show_changeset moved to cmdutil
r3723 displayer = cmdutil.show_changeset(ui, repo, opts)
Brendan Cully
Add transplant extension
r3714 transplants = []
merges = []
FUJIWARA Katsunori
transplant: use "ui.promptchoice()" for interactive transplant...
r20268 prompt = _('apply changeset? [ynmpcq?]:'
'$$ &yes, transplant this changeset'
'$$ &no, skip this changeset'
'$$ &merge at this changeset'
'$$ show &patch'
'$$ &commit selected changesets'
'$$ &quit and cancel transplant'
'$$ &? (show this help)')
Brendan Cully
Add transplant extension
r3714 for node in nodes:
Dirkjan Ochtman
cmdutil: use change contexts for cset-printer and cset-templater
r7369 displayer.show(repo[node])
Brendan Cully
Add transplant extension
r3714 action = None
while not action:
FUJIWARA Katsunori
transplant: use "ui.promptchoice()" for interactive transplant...
r20268 action = 'ynmpcq?'[ui.promptchoice(prompt)]
Brendan Cully
Add transplant extension
r3714 if action == '?':
FUJIWARA Katsunori
transplant: use "ui.extractchoices()" to show the list of available responses...
r20269 for c, t in ui.extractchoices(prompt)[1]:
ui.write('%s: %s\n' % (c, t))
Brendan Cully
Add transplant extension
r3714 action = None
elif action == 'p':
parent = repo.changelog.parents(node)[0]
Dirkjan Ochtman
patch: turn patch.diff() into a generator...
r7308 for chunk in patch.diff(repo, parent, node):
Martin Geisler
use ui instead of repo.ui when the former is in scope
r8615 ui.write(chunk)
Brendan Cully
Add transplant extension
r3714 action = None
if action == 'y':
transplants.append(node)
elif action == 'm':
merges.append(node)
elif action == 'c':
break
elif action == 'q':
transplants = ()
merges = ()
break
Robert Bachmann
Added support for templatevar "footer" to cmdutil.py
r10152 displayer.close()
Brendan Cully
Add transplant extension
r3714 return (transplants, merges)
Adrian Buehlmann
transplant: use cmdutil.command decorator
r14308 @command('transplant',
Mads Kiilerich
transplant: improve documentation
r19028 [('s', 'source', '', _('transplant changesets from REPO'), _('REPO')),
Mads Kiilerich
transplant: clarify what --branch do - it has nothing to do with branches...
r19027 ('b', 'branch', [], _('use this source changeset as head'), _('REV')),
('a', 'all', None, _('pull all changesets up to the --branch revisions')),
Adrian Buehlmann
transplant: use cmdutil.command decorator
r14308 ('p', 'prune', [], _('skip over REV'), _('REV')),
('m', 'merge', [], _('merge at REV'), _('REV')),
Steven Stallion
transplant: permit merge changesets via --parent...
r16400 ('', 'parent', '',
_('parent to choose when transplanting merge'), _('REV')),
Matt Mackall
transplant: add --edit option
r15220 ('e', 'edit', False, _('invoke editor on commit messages')),
Adrian Buehlmann
transplant: use cmdutil.command decorator
r14308 ('', 'log', None, _('append transplant info to log message')),
('c', 'continue', None, _('continue last transplant session '
Mads Kiilerich
transplant: improve documentation
r19028 'after fixing conflicts')),
Adrian Buehlmann
transplant: use cmdutil.command decorator
r14308 ('', 'filter', '',
_('filter changesets through command'), _('CMD'))],
_('hg transplant [-s REPO] [-b BRANCH [-a]] [-p REV] '
'[-m REV] [REV]...'))
Brendan Cully
Add transplant extension
r3714 def transplant(ui, repo, *revs, **opts):
'''transplant changesets from another branch
Selected changesets will be applied on top of the current working
Martin Geisler
transplant: explain that changesets are copied, not moved
r13605 directory with the log of the original changeset. The changesets
Mads Kiilerich
transplant: improve documentation
r19028 are copied and will thus appear twice in the history with different
identities.
Consider using the graft command if everything is inside the same
repository - it will use merges and will usually give a better result.
Use the rebase extension if the changesets are unpublished and you want
to move them instead of copying them.
Martin Geisler
transplant: explain that changesets are copied, not moved
r13605
If --log is specified, log messages will have a comment appended
of the form::
Brendan Cully
Add transplant extension
r3714
Martin Geisler
transplant: better reST formatting
r9200 (transplanted from CHANGESETHASH)
Brendan Cully
Add transplant extension
r3714
You can rewrite the changelog message with the --filter option.
Martin Geisler
transplant: word-wrap help texts at 70 characters
r8000 Its argument will be invoked with the current changelog message as
$1 and the patch as $2.
Brendan Cully
Add transplant extension
r3714
Mads Kiilerich
transplant: improve documentation
r19028 --source/-s specifies another repository to use for selecting changesets,
just as if it temporarily had been pulled.
Mads Kiilerich
transplant: clarify what --branch do - it has nothing to do with branches...
r19027 If --branch/-b is specified, these revisions will be used as
Mads Kiilerich
spelling: random spell checker fixes
r19951 heads when deciding which changesets to transplant, just as if only
Mads Kiilerich
transplant: clarify what --branch do - it has nothing to do with branches...
r19027 these revisions had been pulled.
If --all/-a is specified, all the revisions up to the heads specified
with --branch will be transplanted.
Brendan Cully
Add transplant extension
r3714
Mads Kiilerich
transplant: clarify what --branch do - it has nothing to do with branches...
r19027 Example:
- transplant all changes up to REV on top of your current revision::
hg transplant --branch REV --all
Brendan Cully
Add transplant extension
r3714
Martin Geisler
transplant: word-wrap help texts at 70 characters
r8000 You can optionally mark selected transplanted changesets as merge
changesets. You will not be prompted to transplant any ancestors
of a merged transplant, and you can merge descendants of them
normally instead of transplanting them.
Brendan Cully
Add transplant extension
r3714
Steven Stallion
transplant: permit merge changesets via --parent...
r16400 Merge changesets may be transplanted directly by specifying the
Steven Stallion
transplant: remove extraneous whitespace
r16457 proper parent changeset by calling :hg:`transplant --parent`.
Steven Stallion
transplant: permit merge changesets via --parent...
r16400
Martin Geisler
Use our custom hg reStructuredText role some more...
r11193 If no merges or revisions are provided, :hg:`transplant` will
start an interactive changeset browser.
Brendan Cully
Add transplant extension
r3714
Martin Geisler
transplant: word-wrap help texts at 70 characters
r8000 If a changeset application fails, you can fix the merge by hand
Martin Geisler
Use our custom hg reStructuredText role some more...
r11193 and then resume where you left off by calling :hg:`transplant
--continue/-c`.
Brendan Cully
Add transplant extension
r3714 '''
Peter Arrenbrecht
bundlerepo: fix and improve getremotechanges...
r14161 def incwalk(repo, csets, match=util.always):
for node in csets:
Brendan Cully
Add transplant extension
r3714 if match(node):
yield node
Mads Kiilerich
transplant: clarify what --branch do - it has nothing to do with branches...
r19027 def transplantwalk(repo, dest, heads, match=util.always):
'''Yield all nodes that are ancestors of a head but not ancestors
of dest.
If no heads are specified, the heads of repo will be used.'''
if not heads:
heads = repo.heads()
Brendan Cully
Add transplant extension
r3714 ancestors = []
Mads Kiilerich
transplant: use context ancestor instead of changelog ancestor...
r20988 ctx = repo[dest]
Mads Kiilerich
transplant: clarify what --branch do - it has nothing to do with branches...
r19027 for head in heads:
Mads Kiilerich
transplant: use context ancestor instead of changelog ancestor...
r20988 ancestors.append(ctx.ancestor(repo[head]).node())
Mads Kiilerich
transplant: clarify what --branch do - it has nothing to do with branches...
r19027 for node in repo.changelog.nodesbetween(ancestors, heads)[0]:
Brendan Cully
Add transplant extension
r3714 if match(node):
yield node
def checkopts(opts, revs):
if opts.get('continue'):
Matt Mackall
many, many trivial check-code fixups
r10282 if opts.get('branch') or opts.get('all') or opts.get('merge'):
Martin Geisler
transplant: wrapped long lines
r7744 raise util.Abort(_('--continue is incompatible with '
Mads Kiilerich
transplant: improve documentation
r19028 '--branch, --all and --merge'))
Brendan Cully
Add transplant extension
r3714 return
if not (opts.get('source') or revs or
opts.get('merge') or opts.get('branch')):
Mads Kiilerich
transplant: clarify what --branch do - it has nothing to do with branches...
r19027 raise util.Abort(_('no source URL, branch revision or revision '
Martin Geisler
transplant: wrapped long lines
r7744 'list provided'))
Brendan Cully
Add transplant extension
r3714 if opts.get('all'):
if not opts.get('branch'):
raise util.Abort(_('--all requires a branch revision'))
if revs:
Martin Geisler
transplant: wrapped long lines
r7744 raise util.Abort(_('--all is incompatible with a '
'revision list'))
Brendan Cully
Add transplant extension
r3714
checkopts(opts, revs)
if not opts.get('log'):
opts['log'] = ui.config('transplant', 'log')
if not opts.get('filter'):
opts['filter'] = ui.config('transplant', 'filter')
FUJIWARA Katsunori
transplant: use "getcommiteditor()" instead of explicit editor choice...
r21411 tp = transplanter(ui, repo, opts)
Brendan Cully
Add transplant extension
r3714
Matt Mackall
transplant: add checkunfinished (issue3955)...
r19480 cmdutil.checkunfinished(repo)
Brendan Cully
Add transplant extension
r3714 p1, p2 = repo.dirstate.parents()
Brendan Cully
transplant: forbid transplant to nonempty repositories with no working directory....
r8176 if len(repo) > 0 and p1 == revlog.nullid:
raise util.Abort(_('no revision checked out'))
Brendan Cully
Add transplant extension
r3714 if not opts.get('continue'):
if p2 != revlog.nullid:
raise util.Abort(_('outstanding uncommitted merges'))
m, a, r, d = repo.status()[:4]
if m or a or r or d:
raise util.Abort(_('outstanding local changes'))
Peter Arrenbrecht
bundlerepo: fix and improve getremotechanges...
r14161 sourcerepo = opts.get('source')
if sourcerepo:
Simon Heimberg
peer: subrepo isolation, pass repo instead of repo.ui to hg.peer...
r17874 peer = hg.peer(repo, opts, ui.expandpath(sourcerepo))
Mads Kiilerich
transplant: clarify what --branch do - it has nothing to do with branches...
r19027 heads = map(peer.lookup, opts.get('branch', ()))
Sune Foldager
peer: introduce peer methods to prepare for peer classes...
r17191 source, csets, cleanupfn = bundlerepo.getremotechanges(ui, repo, peer,
Mads Kiilerich
transplant: clarify what --branch do - it has nothing to do with branches...
r19027 onlyheads=heads, force=True)
Brendan Cully
Add transplant extension
r3714 else:
source = repo
Mads Kiilerich
transplant: clarify what --branch do - it has nothing to do with branches...
r19027 heads = map(source.lookup, opts.get('branch', ()))
Peter Arrenbrecht
bundlerepo: fix and improve getremotechanges...
r14161 cleanupfn = None
Brendan Cully
Add transplant extension
r3714
try:
if opts.get('continue'):
Brendan Cully
transplant: fix --continue; add --continue test
r3724 tp.resume(repo, source, opts)
Brendan Cully
Add transplant extension
r3714 return
Benoit Boissinot
fix coding style (reported by pylint)
r10394 tf = tp.transplantfilter(repo, source, p1)
Brendan Cully
Add transplant extension
r3714 if opts.get('prune'):
Mads Kiilerich
transplant: use set for prune lookup
r19055 prune = set(source.lookup(r)
for r in scmutil.revrange(source, opts.get('prune')))
Brendan Cully
Add transplant extension
r3714 matchfn = lambda x: tf(x) and x not in prune
else:
matchfn = tf
merges = map(source.lookup, opts.get('merge', ()))
revmap = {}
if revs:
Matt Mackall
scmutil: move revsingle/pair/range from cmdutil...
r14319 for r in scmutil.revrange(source, revs):
Brendan Cully
Add transplant extension
r3714 revmap[int(r)] = source.lookup(r)
elif opts.get('all') or not merges:
if source != repo:
Peter Arrenbrecht
bundlerepo: fix and improve getremotechanges...
r14161 alltransplants = incwalk(source, csets, match=matchfn)
Brendan Cully
Add transplant extension
r3714 else:
Mads Kiilerich
transplant: clarify what --branch do - it has nothing to do with branches...
r19027 alltransplants = transplantwalk(source, p1, heads,
Martin Geisler
transplant: wrapped long lines
r7744 match=matchfn)
Brendan Cully
Add transplant extension
r3714 if opts.get('all'):
revs = alltransplants
else:
revs, newmerges = browserevs(ui, source, alltransplants, opts)
merges.extend(newmerges)
for r in revs:
revmap[source.changelog.rev(r)] = r
for r in merges:
revmap[source.changelog.rev(r)] = r
tp.apply(repo, source, revmap, merges, opts)
finally:
Peter Arrenbrecht
bundlerepo: fix and improve getremotechanges...
r14161 if cleanupfn:
cleanupfn()
Brendan Cully
Add transplant extension
r3714
Juan Pablo Aroztegi
transplant: add the transplanted revset predicate...
r12581 def revsettransplanted(repo, subset, x):
Idan Kamara
transplant: fix revset doc
r14211 """``transplanted([set])``
Transplanted changesets in set, or all transplanted changesets.
Patrick Mezard
Fix and unify transplant and bookmarks revsets doc registration
r12822 """
Juan Pablo Aroztegi
transplant: add the transplanted revset predicate...
r12581 if x:
Mads Kiilerich
check-code: indent 4 spaces in py files
r17299 s = revset.getset(repo, subset, x)
Juan Pablo Aroztegi
transplant: add the transplanted revset predicate...
r12581 else:
Mads Kiilerich
check-code: indent 4 spaces in py files
r17299 s = subset
Lucas Moscovicz
hgext: updated extensions to return a baseset when adding symbols
r20442 return revset.baseset([r for r in s if
repo[r].extra().get('transplant_source')])
Juan Pablo Aroztegi
transplant: add the transplanted revset predicate...
r12581
Patrick Mezard
transplant: add "transplanted" keyword...
r13689 def kwtransplanted(repo, ctx, **args):
""":transplanted: String. The node identifier of the transplanted
changeset if any."""
n = ctx.extra().get('transplant_source')
return n and revlog.hex(n) or ''
Juan Pablo Aroztegi
transplant: add the transplanted revset predicate...
r12581
Patrick Mezard
Fix and unify transplant and bookmarks revsets doc registration
r12822 def extsetup(ui):
Juan Pablo Aroztegi
transplant: add the transplanted revset predicate...
r12581 revset.symbols['transplanted'] = revsettransplanted
Patrick Mezard
transplant: add "transplanted" keyword...
r13689 templatekw.keywords['transplanted'] = kwtransplanted
Matt Mackall
transplant: add checkunfinished (issue3955)...
r19480 cmdutil.unfinishedstates.append(
Matt Mackall
checkunfinished: accommodate histedit quirk...
r19496 ['series', True, False, _('transplant in progress'),
Matt Mackall
transplant: add checkunfinished (issue3955)...
r19480 _("use 'hg transplant --continue' or 'hg update' to abort")])
Juan Pablo Aroztegi
transplant: add the transplanted revset predicate...
r12581
Patrick Mezard
hggettext: handle i18nfunctions declaration for docstrings translations
r12823 # tell hggettext to extract docstrings from these functions:
Patrick Mezard
i18n: register new template keywords for translation
r13698 i18nfunctions = [revsettransplanted, kwtransplanted]