##// END OF EJS Templates
symlinks: minimal support for symlinks in merge/update...
symlinks: minimal support for symlinks in merge/update This will get angry, confused, and sad if you try to merge a symlink with a regular file.

File last commit:

r3982:714fbfe5 default
r4007:20da40cc default
Show More
mq.py
2181 lines | 78.2 KiB | text/x-python | PythonLexer
mason@suse.com
Add mq extension
r1808 # queue.py - patch queues for mercurial
#
Vadim Gelfer
update copyrights.
r2859 # Copyright 2005, 2006 Chris Mason <mason@suse.com>
mason@suse.com
Add mq extension
r1808 #
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.
Vadim Gelfer
help: add help to mq extension
r2554 '''patch management and development
This extension lets you work with a stack of patches in a Mercurial
repository. It manages two stacks of patches - all known patches, and
applied patches (subset of known patches).
Known patches are represented as patch files in the .hg/patches
directory. Applied patches are both patch files and changesets.
Common tasks (use "hg help command" for more details):
prepare repository to work with patches qinit
create new patch qnew
import existing patch qimport
print patch series qseries
print applied patches qapplied
print name of top applied patch qtop
add known patch to applied stack qpush
remove patch from applied stack qpop
refresh contents of top applied patch qrefresh
'''
Matt Mackall
Simplify i18n imports
r3891 from mercurial.i18n import _
Matt Mackall
Replace demandload with new demandimport
r3877 from mercurial import commands, cmdutil, hg, patch, revlog, util, changegroup
Benoit Boissinot
remove various unused import
r3963 import os, sys, re, errno
mason@suse.com
Add mq extension
r1808
Vadim Gelfer
mq: add qclone command
r2720 commands.norepo += " qclone qversion"
Brendan Cully
Make mq camelcase consistent with the rest of hg.
r2818 class statusentry:
Brendan Cully
Use StatusEntry class instead of repeated status line parsing....
r2780 def __init__(self, rev, name=None):
if not name:
Brendan Cully
mq: handle patch names containing ":"
r3091 fields = rev.split(':', 1)
Brendan Cully
Update qsave to use StatusEntry; don't throw exception on bad status lines.
r2816 if len(fields) == 2:
self.rev, self.name = fields
else:
self.rev, self.name = None, None
Brendan Cully
Use StatusEntry class instead of repeated status line parsing....
r2780 else:
self.rev, self.name = rev, name
def __str__(self):
return self.rev + ':' + self.name
mason@suse.com
Add mq extension
r1808 class queue:
def __init__(self, ui, path, patchdir=None):
self.basepath = path
Vadim Gelfer
mq: add join method
r2819 self.path = patchdir or os.path.join(path, "patches")
Thomas Arendsen Hein
Fix mq's usage of opener, which don't allow absolute paths now.
r1852 self.opener = util.opener(self.path)
mason@suse.com
Add mq extension
r1808 self.ui = ui
self.applied = []
self.full_series = []
self.applied_dirty = 0
self.series_dirty = 0
Thomas Arendsen Hein
Fix mq's usage of opener, which don't allow absolute paths now.
r1852 self.series_path = "series"
self.status_path = "status"
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 self.guards_path = "guards"
self.active_guards = None
self.guards_dirty = False
Vadim Gelfer
refactor text diff/patch code....
r2874 self._diffopts = None
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810
Vadim Gelfer
mq: add join method
r2819 if os.path.exists(self.join(self.series_path)):
Thomas Arendsen Hein
Fix mq's usage of opener, which don't allow absolute paths now.
r1852 self.full_series = self.opener(self.series_path).read().splitlines()
Vadim Gelfer
mq: rename read_series as parse_series, make simpler and faster
r2767 self.parse_series()
mason@suse.com
Add mq extension
r1808
Vadim Gelfer
mq: add join method
r2819 if os.path.exists(self.join(self.status_path)):
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 lines = self.opener(self.status_path).read().splitlines()
self.applied = [statusentry(l) for l in lines]
mason@suse.com
Add mq extension
r1808
Vadim Gelfer
refactor text diff/patch code....
r2874 def diffopts(self):
if self._diffopts is None:
Matt Mackall
Move ui.diffopts to patch.diffopts where it belongs
r2888 self._diffopts = patch.diffopts(self.ui)
Vadim Gelfer
refactor text diff/patch code....
r2874 return self._diffopts
Vadim Gelfer
mq: add join method
r2819 def join(self, *p):
return os.path.join(self.path, *p)
mason@suse.com
Add mq extension
r1808 def find_series(self, patch):
pre = re.compile("(\s*)([^#]+)")
index = 0
for l in self.full_series:
m = pre.match(l)
if m:
s = m.group(2)
s = s.rstrip()
if s == patch:
return index
index += 1
return None
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 guard_re = re.compile(r'\s?#([-+][^-+# \t\r\n\f][^# \t\r\n\f]*)')
Vadim Gelfer
mq: rename read_series as parse_series, make simpler and faster
r2767 def parse_series(self):
mason@suse.com
Add mq extension
r1808 self.series = []
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 self.series_guards = []
Vadim Gelfer
mq: rename read_series as parse_series, make simpler and faster
r2767 for l in self.full_series:
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 h = l.find('#')
if h == -1:
patch = l
comment = ''
elif h == 0:
continue
else:
patch = l[:h]
comment = l[h:]
patch = patch.strip()
if patch:
Brendan Cully
mq: bail out if a patch appears more than once in the series file....
r3184 if patch in self.series:
raise util.Abort(_('%s appears more than once in %s') %
(patch, self.join(self.series_path)))
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 self.series.append(patch)
self.series_guards.append(self.guard_re.findall(comment))
def check_guard(self, guard):
bad_chars = '# \t\r\n\f'
first = guard[0]
for c in '-+':
if first == c:
return (_('guard %r starts with invalid character: %r') %
(guard, c))
for c in bad_chars:
if c in guard:
return _('invalid character in guard %r: %r') % (guard, c)
Thomas Arendsen Hein
Whitespace/Tab cleanup
r3223
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 def set_active(self, guards):
for guard in guards:
bad = self.check_guard(guard)
if bad:
raise util.Abort(bad)
guards = dict.fromkeys(guards).keys()
guards.sort()
self.ui.debug('active guards: %s\n' % ' '.join(guards))
self.active_guards = guards
self.guards_dirty = True
def active(self):
if self.active_guards is None:
self.active_guards = []
try:
guards = self.opener(self.guards_path).read().split()
except IOError, err:
if err.errno != errno.ENOENT: raise
guards = []
for i, guard in enumerate(guards):
bad = self.check_guard(guard)
if bad:
self.ui.warn('%s:%d: %s\n' %
(self.join(self.guards_path), i + 1, bad))
else:
self.active_guards.append(guard)
return self.active_guards
def set_guards(self, idx, guards):
for g in guards:
if len(g) < 2:
raise util.Abort(_('guard %r too short') % g)
if g[0] not in '-+':
raise util.Abort(_('guard %r starts with invalid char') % g)
bad = self.check_guard(g[1:])
if bad:
raise util.Abort(bad)
drop = self.guard_re.sub('', self.full_series[idx])
self.full_series[idx] = drop + ''.join([' #' + g for g in guards])
self.parse_series()
self.series_dirty = True
Thomas Arendsen Hein
Whitespace/Tab cleanup
r3223
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 def pushable(self, idx):
if isinstance(idx, str):
idx = self.series.index(idx)
patchguards = self.series_guards[idx]
if not patchguards:
return True, None
default = False
guards = self.active()
exactneg = [g for g in patchguards if g[0] == '-' and g[1:] in guards]
if exactneg:
return False, exactneg[0]
pos = [g for g in patchguards if g[0] == '+']
Vadim Gelfer
mq: apply patch is any posative guard matches...
r2850 exactpos = [g for g in pos if g[1:] in guards]
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 if pos:
Vadim Gelfer
mq: apply patch is any posative guard matches...
r2850 if exactpos:
return True, exactpos[0]
return False, pos
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 return True, ''
def explain_pushable(self, idx, all_patches=False):
write = all_patches and self.ui.write or self.ui.warn
if all_patches or self.ui.verbose:
if isinstance(idx, str):
idx = self.series.index(idx)
pushable, why = self.pushable(idx)
if all_patches and pushable:
if why is None:
write(_('allowing %s - no guards in effect\n') %
self.series[idx])
else:
if not why:
write(_('allowing %s - no matching negative guards\n') %
self.series[idx])
else:
write(_('allowing %s - guarded by %r\n') %
(self.series[idx], why))
if not pushable:
Vadim Gelfer
mq: make guards more strict, add tests
r2829 if why:
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 write(_('skipping %s - guarded by %r\n') %
Brendan Cully
mq: fix explain_pushable for negative guards
r3870 (self.series[idx], why))
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 else:
write(_('skipping %s - no matching guards\n') %
self.series[idx])
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810
mason@suse.com
Add mq extension
r1808 def save_dirty(self):
Vadim Gelfer
mq: simplify save_dirty
r2772 def write_list(items, path):
fp = self.opener(path, 'w')
for i in items:
print >> fp, i
fp.close()
Vadim Gelfer
merge with brendan.
r2781 if self.applied_dirty: write_list(map(str, self.applied), self.status_path)
Vadim Gelfer
mq: simplify save_dirty
r2772 if self.series_dirty: write_list(self.full_series, self.series_path)
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 if self.guards_dirty: write_list(self.active_guards, self.guards_path)
mason@suse.com
Add mq extension
r1808
def readheaders(self, patch):
def eatdiff(lines):
while lines:
l = lines[-1]
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 if (l.startswith("diff -") or
l.startswith("Index:") or
l.startswith("===========")):
mason@suse.com
Add mq extension
r1808 del lines[-1]
else:
break
def eatempty(lines):
while lines:
l = lines[-1]
if re.match('\s*$', l):
del lines[-1]
else:
break
Vadim Gelfer
mq: add join method
r2819 pf = self.join(patch)
mason@suse.com
Add mq extension
r1808 message = []
comments = []
user = None
Danek Duvall
Add timestamp field to export format. Make import and mq use it.
r2299 date = None
mason@suse.com
Add mq extension
r1808 format = None
subject = None
diffstart = 0
for line in file(pf):
line = line.rstrip()
Brendan Cully
Teach mq about git patches
r2934 if line.startswith('diff --git'):
diffstart = 2
break
mason@suse.com
Add mq extension
r1808 if diffstart:
if line.startswith('+++ '):
diffstart = 2
break
if line.startswith("--- "):
diffstart = 1
continue
elif format == "hgpatch":
# parse values when importing the result of an hg export
if line.startswith("# User "):
user = line[7:]
Thomas Arendsen Hein
Use "# Date" instead of "# Timestamp" for dated export/import of patches....
r2300 elif line.startswith("# Date "):
date = line[7:]
mason@suse.com
Add mq extension
r1808 elif not line.startswith("# ") and line:
message.append(line)
format = None
elif line == '# HG changeset patch':
format = "hgpatch"
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 elif (format != "tagdone" and (line.startswith("Subject: ") or
line.startswith("subject: "))):
mason@suse.com
Add mq extension
r1808 subject = line[9:]
format = "tag"
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 elif (format != "tagdone" and (line.startswith("From: ") or
line.startswith("from: "))):
mason@suse.com
Add mq extension
r1808 user = line[6:]
format = "tag"
elif format == "tag" and line == "":
# when looking for tags (subject: from: etc) they
# end once you find a blank line in the source
format = "tagdone"
Thomas Arendsen Hein
Strip empty lines and trailing spaces around commit messages....
r2301 elif message or line:
mason@suse.com
Add mq extension
r1808 message.append(line)
comments.append(line)
eatdiff(message)
eatdiff(comments)
eatempty(message)
eatempty(comments)
# make sure message isn't empty
if format and format.startswith("tag") and subject:
message.insert(0, "")
message.insert(0, subject)
Danek Duvall
Add timestamp field to export format. Make import and mq use it.
r2299 return (message, comments, user, date, diffstart > 1)
mason@suse.com
Add mq extension
r1808
Vadim Gelfer
refactor text diff/patch code....
r2874 def printdiff(self, repo, node1, node2=None, files=None,
Brendan Cully
Fix test-mq-qdiff; add -I and -X options to qdiff
r2937 fp=None, changes=None, opts={}):
fns, matchfn, anypats = cmdutil.matchpats(repo, files, opts)
patch.diff(repo, node1, node2, fns, match=matchfn,
Vadim Gelfer
refactor text diff/patch code....
r2874 fp=fp, changes=changes, opts=self.diffopts())
mason@suse.com
Add mq extension
r1808 def mergeone(self, repo, mergeq, head, patch, rev, wlock):
# first try just applying the patch
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 (err, n) = self.apply(repo, [ patch ], update_status=False,
mason@suse.com
Add mq extension
r1808 strict=True, merge=rev, wlock=wlock)
if err == 0:
return (err, n)
if n is None:
Vadim Gelfer
mq: move many error messages to util.Abort
r2712 raise util.Abort(_("apply failed for patch %s") % patch)
mason@suse.com
Add mq extension
r1808
self.ui.warn("patch didn't work out, merging %s\n" % patch)
# apply failed, strip away that rev and merge.
Matt Mackall
Introduce update helper functions: update, merge, clean, and revert
r2808 hg.clean(repo, head, wlock=wlock)
mason@suse.com
Add mq extension
r1808 self.strip(repo, n, update=False, backup='strip', wlock=wlock)
Benoit Boissinot
mq: use contexts
r3980 ctx = repo.changectx(rev)
Matt Mackall
Introduce update helper functions: update, merge, clean, and revert
r2808 ret = hg.merge(repo, rev, wlock=wlock)
mason@suse.com
Add mq extension
r1808 if ret:
Vadim Gelfer
mq: move many error messages to util.Abort
r2712 raise util.Abort(_("update returned %d") % ret)
Benoit Boissinot
mq: use contexts
r3980 n = repo.commit(None, ctx.description(), ctx.user(),
force=1, wlock=wlock)
mason@suse.com
Add mq extension
r1808 if n == None:
Vadim Gelfer
mq: move many error messages to util.Abort
r2712 raise util.Abort(_("repo commit failed"))
mason@suse.com
Add mq extension
r1808 try:
Danek Duvall
Add timestamp field to export format. Make import and mq use it.
r2299 message, comments, user, date, patchfound = mergeq.readheaders(patch)
mason@suse.com
Add mq extension
r1808 except:
Vadim Gelfer
mq: move many error messages to util.Abort
r2712 raise util.Abort(_("unable to read %s") % patch)
mason@suse.com
Add mq extension
r1808
Thomas Arendsen Hein
Fix mq's usage of opener, which don't allow absolute paths now.
r1852 patchf = self.opener(patch, "w")
mason@suse.com
Add mq extension
r1808 if comments:
comments = "\n".join(comments) + '\n\n'
patchf.write(comments)
Vadim Gelfer
refactor text diff/patch code....
r2874 self.printdiff(repo, head, n, fp=patchf)
mason@suse.com
Add mq extension
r1808 patchf.close()
return (0, n)
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810
mason@suse.com
Add mq extension
r1808 def qparents(self, repo, rev=None):
if rev is None:
(p1, p2) = repo.dirstate.parents()
if p2 == revlog.nullid:
return p1
if len(self.applied) == 0:
return None
Brendan Cully
Use StatusEntry class instead of repeated status line parsing....
r2780 return revlog.bin(self.applied[-1].rev)
mason@suse.com
Add mq extension
r1808 pp = repo.changelog.parents(rev)
if pp[1] != revlog.nullid:
Brendan Cully
Use StatusEntry class instead of repeated status line parsing....
r2780 arevs = [ x.rev for x in self.applied ]
mason@suse.com
Add mq extension
r1808 p0 = revlog.hex(pp[0])
p1 = revlog.hex(pp[1])
if p0 in arevs:
return pp[0]
if p1 in arevs:
return pp[1]
return pp[0]
def mergepatch(self, repo, mergeq, series, wlock):
if len(self.applied) == 0:
# each of the patches merged in will have two parents. This
# can confuse the qrefresh, qdiff, and strip code because it
# needs to know which parent is actually in the patch queue.
# so, we insert a merge marker with only one parent. This way
# the first patch in the queue is never a merge patch
#
pname = ".hg.patches.merge.marker"
n = repo.commit(None, '[mq]: merge marker', user=None, force=1,
wlock=wlock)
Brendan Cully
Make mq camelcase consistent with the rest of hg.
r2818 self.applied.append(statusentry(revlog.hex(n), pname))
mason@suse.com
Add mq extension
r1808 self.applied_dirty = 1
head = self.qparents(repo)
for patch in series:
Chris Mason
mq: patch naming shortcuts...
r2696 patch = mergeq.lookup(patch, strict=True)
mason@suse.com
Add mq extension
r1808 if not patch:
self.ui.warn("patch %s does not exist\n" % patch)
return (1, None)
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 pushable, reason = self.pushable(patch)
if not pushable:
self.explain_pushable(patch, all_patches=True)
continue
mason@suse.com
Add mq extension
r1808 info = mergeq.isapplied(patch)
if not info:
self.ui.warn("patch %s is not applied\n" % patch)
return (1, None)
rev = revlog.bin(info[1])
(err, head) = self.mergeone(repo, mergeq, head, patch, rev, wlock)
if head:
Brendan Cully
Make mq camelcase consistent with the rest of hg.
r2818 self.applied.append(statusentry(revlog.hex(head), patch))
mason@suse.com
Add mq extension
r1808 self.applied_dirty = 1
if err:
return (err, head)
return (0, head)
Brendan Cully
New mq command qfold: Merge patches into the current patch....
r2748 def patch(self, repo, patchfile):
'''Apply patchfile to the working directory.
patchfile: file name of patch'''
Brendan Cully
patch: return list of modified files even when an exception is raised...
r3465 files = {}
Brendan Cully
New mq command qfold: Merge patches into the current patch....
r2748 try:
Brendan Cully
patch: return list of modified files even when an exception is raised...
r3465 fuzz = patch.patch(patchfile, self.ui, strip=1, cwd=repo.root,
files=files)
Brendan Cully
Unify mq and hg patch invocation....
r2919 except Exception, inst:
self.ui.note(str(inst) + '\n')
if not self.ui.verbose:
self.ui.warn("patch failed, unable to continue (try -v)\n")
Brendan Cully
patch: return list of modified files even when an exception is raised...
r3465 return (False, files, False)
Brendan Cully
New mq command qfold: Merge patches into the current patch....
r2748
Brendan Cully
Teach mq about git patches
r2934 return (True, files, fuzz)
Benoit Boissinot
mq: codingstyle
r2796
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 def apply(self, repo, series, list=False, update_status=True,
mason@suse.com
Add mq extension
r1808 strict=False, patchdir=None, merge=None, wlock=None):
# TODO unify with commands.py
if not patchdir:
patchdir = self.path
err = 0
if not wlock:
wlock = repo.wlock()
lock = repo.lock()
tr = repo.transaction()
n = None
Brendan Cully
Teach mq about git patches
r2934 for patchname in series:
pushable, reason = self.pushable(patchname)
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 if not pushable:
Brendan Cully
Teach mq about git patches
r2934 self.explain_pushable(patchname, all_patches=True)
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 continue
Brendan Cully
Teach mq about git patches
r2934 self.ui.warn("applying %s\n" % patchname)
pf = os.path.join(patchdir, patchname)
mason@suse.com
Add mq extension
r1808
try:
Brendan Cully
Teach mq about git patches
r2934 message, comments, user, date, patchfound = self.readheaders(patchname)
mason@suse.com
Add mq extension
r1808 except:
Brendan Cully
Teach mq about git patches
r2934 self.ui.warn("Unable to read %s\n" % patchname)
mason@suse.com
Add mq extension
r1808 err = 1
break
if not message:
Brendan Cully
Teach mq about git patches
r2934 message = "imported patch %s\n" % patchname
mason@suse.com
Add mq extension
r1808 else:
if list:
Brendan Cully
Teach mq about git patches
r2934 message.append("\nimported patch %s" % patchname)
mason@suse.com
Add mq extension
r1808 message = '\n'.join(message)
Brendan Cully
New mq command qfold: Merge patches into the current patch....
r2748 (patcherr, files, fuzz) = self.patch(repo, pf)
patcherr = not patcherr
mason@suse.com
Add mq extension
r1808
Brendan Cully
Teach mq about git patches
r2934 if merge and files:
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 # Mark as merged and update dirstate parent info
Brendan Cully
Teach mq about git patches
r2934 repo.dirstate.update(repo.dirstate.filterfiles(files.keys()), 'm')
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 p1, p2 = repo.dirstate.parents()
repo.dirstate.setparents(p1, merge)
Brendan Cully
Teach mq about git patches
r2934 files = patch.updatedir(self.ui, repo, files, wlock=wlock)
Danek Duvall
Add timestamp field to export format. Make import and mq use it.
r2299 n = repo.commit(files, message, user, date, force=1, lock=lock,
mason@suse.com
Add mq extension
r1808 wlock=wlock)
if n == None:
Vadim Gelfer
mq: move many error messages to util.Abort
r2712 raise util.Abort(_("repo commit failed"))
mason@suse.com
Add mq extension
r1808
if update_status:
Brendan Cully
Teach mq about git patches
r2934 self.applied.append(statusentry(revlog.hex(n), patchname))
mason@suse.com
Add mq extension
r1808
if patcherr:
if not patchfound:
Brendan Cully
Teach mq about git patches
r2934 self.ui.warn("patch %s is empty\n" % patchname)
mason@suse.com
Add mq extension
r1808 err = 0
else:
self.ui.warn("patch failed, rejects left in working dir\n")
err = 1
break
if fuzz and strict:
self.ui.warn("fuzz found when applying patch, stopping\n")
err = 1
break
tr.close()
return (err, n)
Brendan Cully
mq: add qdelete --forget option...
r3088 def delete(self, repo, patches, opts):
Brendan Cully
Allow qdel to delete multiple patches.
r2905 realpatches = []
for patch in patches:
patch = self.lookup(patch, strict=True)
info = self.isapplied(patch)
Brendan Cully
mq: change qdel --forget to --rev; accept any revision symbol
r3373 if info:
Brendan Cully
Allow qdel to delete multiple patches.
r2905 raise util.Abort(_("cannot delete applied patch %s") % patch)
if patch not in self.series:
raise util.Abort(_("patch %s not in series file") % patch)
Brendan Cully
mq: change qdel --forget to --rev; accept any revision symbol
r3373 realpatches.append(patch)
appliedbase = 0
if opts.get('rev'):
if not self.applied:
raise util.Abort(_('no patches applied'))
Thomas Arendsen Hein
Removed unused ui parameter from revpair/revrange and fix its users.
r3707 revs = cmdutil.revrange(repo, opts['rev'])
Brendan Cully
mq: change qdel --forget to --rev; accept any revision symbol
r3373 if len(revs) > 1 and revs[0] > revs[1]:
revs.reverse()
for rev in revs:
if appliedbase >= len(self.applied):
raise util.Abort(_("revision %d is not managed") % rev)
base = revlog.bin(self.applied[appliedbase].rev)
node = repo.changelog.node(rev)
if node != base:
raise util.Abort(_("cannot delete revision %d above "
"applied patches") % rev)
realpatches.append(self.applied[appliedbase].name)
Brendan Cully
mq: add qdelete --forget option...
r3088 appliedbase += 1
Brendan Cully
Allow qdel to delete multiple patches.
r2905
Brendan Cully
mq: add qdelete --forget option...
r3088 if not opts.get('keep'):
Brendan Cully
Add -f option to qdelete, to remove patch file.
r2752 r = self.qrepo()
if r:
Brendan Cully
Allow qdel to delete multiple patches.
r2905 r.remove(realpatches, True)
Brendan Cully
Add -f option to qdelete, to remove patch file.
r2752 else:
Brendan Cully
mq: make qdelete without -k or a subrepository delete all patches
r3375 for p in realpatches:
os.unlink(self.join(p))
Brendan Cully
Allow qdel to delete multiple patches.
r2905
Brendan Cully
mq: change qdel --forget to --rev; accept any revision symbol
r3373 if appliedbase:
Brendan Cully
mq: add qdelete --forget option...
r3088 del self.applied[:appliedbase]
self.applied_dirty = 1
Brendan Cully
Allow qdel to delete multiple patches.
r2905 indices = [self.find_series(p) for p in realpatches]
indices.sort()
for i in indices[-1::-1]:
del self.full_series[i]
Vadim Gelfer
mq: rename read_series as parse_series, make simpler and faster
r2767 self.parse_series()
mason@suse.com
Add mq extension
r1808 self.series_dirty = 1
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810
mason@suse.com
Add mq extension
r1808 def check_toppatch(self, repo):
if len(self.applied) > 0:
Brendan Cully
Use StatusEntry class instead of repeated status line parsing....
r2780 top = revlog.bin(self.applied[-1].rev)
mason@suse.com
Add mq extension
r1808 pp = repo.dirstate.parents()
if top not in pp:
Vadim Gelfer
mq: move many error messages to util.Abort
r2712 raise util.Abort(_("queue top not at same revision as working directory"))
mason@suse.com
Add mq extension
r1808 return top
return None
Vadim Gelfer
remove localrepository.changes....
r2875 def check_localchanges(self, repo, force=False, refresh=True):
m, a, r, d = repo.status()[:4]
if m or a or r or d:
if not force:
if refresh:
raise util.Abort(_("local changes found, refresh first"))
else:
raise util.Abort(_("local changes found"))
return m, a, r, d
mason@suse.com
Add mq extension
r1808 def new(self, repo, patch, msg=None, force=None):
Vadim Gelfer
mq: add join method
r2819 if os.path.exists(self.join(patch)):
Vadim Gelfer
mq: do not allow to qnew a patch twice
r2711 raise util.Abort(_('patch "%s" already exists') % patch)
Vadim Gelfer
remove localrepository.changes....
r2875 m, a, r, d = self.check_localchanges(repo, force)
commitfiles = m + a + r
mason@suse.com
Add mq extension
r1808 self.check_toppatch(repo)
wlock = repo.wlock()
Chris Mason
mq: fix qnew and qimport to deal with series file comments...
r2698 insert = self.full_series_end()
mason@suse.com
Add mq extension
r1808 if msg:
Chris Mason
mq: hg qnew -f should refresh the new patch...
r2511 n = repo.commit(commitfiles, "[mq]: %s" % msg, force=True,
wlock=wlock)
mason@suse.com
Add mq extension
r1808 else:
Chris Mason
mq: hg qnew -f should refresh the new patch...
r2511 n = repo.commit(commitfiles,
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 "New patch: %s" % patch, force=True, wlock=wlock)
mason@suse.com
Add mq extension
r1808 if n == None:
Vadim Gelfer
mq: move many error messages to util.Abort
r2712 raise util.Abort(_("repo commit failed"))
mason@suse.com
Add mq extension
r1808 self.full_series[insert:insert] = [patch]
Brendan Cully
Make mq camelcase consistent with the rest of hg.
r2818 self.applied.append(statusentry(revlog.hex(n), patch))
Vadim Gelfer
mq: rename read_series as parse_series, make simpler and faster
r2767 self.parse_series()
mason@suse.com
Add mq extension
r1808 self.series_dirty = 1
self.applied_dirty = 1
Thomas Arendsen Hein
Fix mq's usage of opener, which don't allow absolute paths now.
r1852 p = self.opener(patch, "w")
mason@suse.com
Add mq extension
r1808 if msg:
msg = msg + "\n"
p.write(msg)
p.close()
wlock = None
r = self.qrepo()
if r: r.add([patch])
Chris Mason
mq: hg qnew -f should refresh the new patch...
r2511 if commitfiles:
Alexis S. L. Carvalho
Fix "hg qnew -f foo" without -m...
r2856 self.refresh(repo, short=True)
mason@suse.com
Add mq extension
r1808
def strip(self, repo, rev, update=True, backup="all", wlock=None):
def limitheads(chlog, stop):
"""return the list of all nodes that have no children"""
p = {}
h = []
stoprev = 0
if stop in chlog.nodemap:
stoprev = chlog.rev(stop)
Benoit Boissinot
use xrange instead of range
r3473 for r in xrange(chlog.count() - 1, -1, -1):
mason@suse.com
Add mq extension
r1808 n = chlog.node(r)
if n not in p:
h.append(n)
if n == stop:
break
if r < stoprev:
break
for pn in chlog.parents(n):
p[pn] = 1
return h
def bundle(cg):
backupdir = repo.join("strip-backup")
if not os.path.isdir(backupdir):
os.mkdir(backupdir)
name = os.path.join(backupdir, "%s" % revlog.short(rev))
name = savename(name)
self.ui.warn("saving bundle to %s\n" % name)
Thomas Arendsen Hein
Make mq use changegroup.writebundle for writing strip backups.
r3708 return changegroup.writebundle(cg, name, "HG10BZ")
mason@suse.com
Add mq extension
r1808
Benoit Boissinot
mq: use contexts
r3980 def stripall(revnum):
mm = repo.changectx(rev).manifest()
mason@suse.com
Add mq extension
r1808 seen = {}
Benoit Boissinot
mq: use contexts
r3980 for x in xrange(revnum, repo.changelog.count()):
for f in repo.changectx(x).files():
mason@suse.com
Add mq extension
r1808 if f in seen:
continue
seen[f] = 1
if f in mm:
filerev = mm[f]
else:
filerev = 0
seen[f] = filerev
# we go in two steps here so the strip loop happens in a
# sensible order. When stripping many files, this helps keep
# our disk access patterns under control.
Benoit Boissinot
mq: fix variables shadowing builtin
r2794 seen_list = seen.keys()
seen_list.sort()
for f in seen_list:
mason@suse.com
Add mq extension
r1808 ff = repo.file(f)
filerev = seen[f]
if filerev != 0:
if filerev in ff.nodemap:
filerev = ff.rev(filerev)
else:
filerev = 0
ff.strip(filerev, revnum)
if not wlock:
wlock = repo.wlock()
lock = repo.lock()
chlog = repo.changelog
# TODO delete the undo files, and handle undo of merge sets
pp = chlog.parents(rev)
revnum = chlog.rev(rev)
if update:
Vadim Gelfer
remove localrepository.changes....
r2875 self.check_localchanges(repo, refresh=False)
mason@suse.com
Add mq extension
r1808 urev = self.qparents(repo, rev)
Matt Mackall
Introduce update helper functions: update, merge, clean, and revert
r2808 hg.clean(repo, urev, wlock=wlock)
mason@suse.com
Add mq extension
r1808 repo.dirstate.write()
# save is a list of all the branches we are truncating away
# that we actually want to keep. changegroup will be used
# to preserve them and add them back after the truncate
saveheads = []
savebases = {}
heads = limitheads(chlog, rev)
seen = {}
# search through all the heads, finding those where the revision
# we want to strip away is an ancestor. Also look for merges
# that might be turned into new heads by the strip.
while heads:
h = heads.pop()
n = h
while True:
seen[n] = 1
pp = chlog.parents(n)
if pp[1] != revlog.nullid and chlog.rev(pp[1]) > revnum:
if pp[1] not in seen:
heads.append(pp[1])
if pp[0] == revlog.nullid:
break
if chlog.rev(pp[0]) < revnum:
break
n = pp[0]
if n == rev:
break
r = chlog.reachable(h, rev)
if rev not in r:
saveheads.append(h)
for x in r:
if chlog.rev(x) > revnum:
savebases[x] = 1
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810
mason@suse.com
Add mq extension
r1808 # create a changegroup for all the branches we need to keep
Benoit Boissinot
mq: unused variables, improper usage of 'is [not]', undefined variable
r2797 if backup == "all":
mason@suse.com
Add mq extension
r1808 backupch = repo.changegroupsubset([rev], chlog.heads(), 'strip')
bundle(backupch)
if saveheads:
backupch = repo.changegroupsubset(savebases.keys(), saveheads, 'strip')
chgrpfile = bundle(backupch)
Benoit Boissinot
fix strip on windows...
r3901 chgrpfile = 'file:%s' % chgrpfile
mason@suse.com
Add mq extension
r1808
Benoit Boissinot
mq: use contexts
r3980 stripall(revnum)
mason@suse.com
Add mq extension
r1808
change = chlog.read(rev)
Brendan Cully
strip: strip changelog before manifest
r3075 chlog.strip(revnum, revnum)
mason@suse.com
Add mq extension
r1808 repo.manifest.strip(repo.manifest.rev(change[0]), revnum)
if saveheads:
self.ui.status("adding branch\n")
commands.unbundle(self.ui, repo, chgrpfile, update=False)
Benoit Boissinot
mq: unused variables, improper usage of 'is [not]', undefined variable
r2797 if backup != "strip":
mason@suse.com
Add mq extension
r1808 os.unlink(chgrpfile)
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810
mason@suse.com
Add mq extension
r1808 def isapplied(self, patch):
"""returns (index, rev, patch)"""
for i in xrange(len(self.applied)):
Brendan Cully
Use StatusEntry class instead of repeated status line parsing....
r2780 a = self.applied[i]
if a.name == patch:
return (i, a.rev, a.name)
mason@suse.com
Add mq extension
r1808 return None
Thomas Arendsen Hein
Whitespace/Tab cleanup
r3223 # if the exact patch name does not exist, we try a few
Chris Mason
mq: patch naming shortcuts...
r2696 # variations. If strict is passed, we try only #1
#
# 1) a number to indicate an offset in the series file
# 2) a unique substring of the patch name was given
# 3) patchname[-+]num to indicate an offset in the series file
def lookup(self, patch, strict=False):
Vadim Gelfer
qselect: add --pop, --reapply options
r2844 patch = patch and str(patch)
Chris Mason
mq: patch naming shortcuts...
r2696 def partial_name(s):
if s in self.series:
return s
Vadim Gelfer
mq: print matches if patch name not unique
r2765 matches = [x for x in self.series if s in x]
if len(matches) > 1:
self.ui.warn(_('patch name "%s" is ambiguous:\n') % s)
for m in matches:
self.ui.warn(' %s\n' % m)
return None
if matches:
return matches[0]
Chris Mason
mq: patch naming shortcuts...
r2696 if len(self.series) > 0 and len(self.applied) > 0:
if s == 'qtip':
Brendan Cully
mq: fix qheader without args when guards are applied after qtop
r3874 return self.series[self.series_end(True)-1]
Chris Mason
mq: patch naming shortcuts...
r2696 if s == 'qbase':
return self.series[0]
return None
mason@suse.com
Add mq extension
r1808 if patch == None:
return None
Chris Mason
mq: patch naming shortcuts...
r2696
# we don't want to return a partial match until we make
# sure the file name passed in does not exist (checked below)
res = partial_name(patch)
if res and res == patch:
return res
Vadim Gelfer
mq: add join method
r2819 if not os.path.isfile(self.join(patch)):
mason@suse.com
Add mq extension
r1808 try:
sno = int(patch)
except(ValueError, OverflowError):
Chris Mason
mq: patch naming shortcuts...
r2696 pass
else:
if sno < len(self.series):
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 return self.series[sno]
Chris Mason
mq: patch naming shortcuts...
r2696 if not strict:
# return any partial match made above
if res:
return res
Thomas Arendsen Hein
Fixed python2.3 incompatibility (rsplit) in qpush/qpop with index.
r3082 minus = patch.rfind('-')
if minus >= 0:
res = partial_name(patch[:minus])
Chris Mason
mq: patch naming shortcuts...
r2696 if res:
i = self.series.index(res)
try:
Thomas Arendsen Hein
Fixed python2.3 incompatibility (rsplit) in qpush/qpop with index.
r3082 off = int(patch[minus+1:] or 1)
Chris Mason
mq: patch naming shortcuts...
r2696 except(ValueError, OverflowError):
pass
else:
if i - off >= 0:
return self.series[i - off]
Thomas Arendsen Hein
Fixed python2.3 incompatibility (rsplit) in qpush/qpop with index.
r3082 plus = patch.rfind('+')
if plus >= 0:
res = partial_name(patch[:plus])
Chris Mason
mq: patch naming shortcuts...
r2696 if res:
i = self.series.index(res)
try:
Thomas Arendsen Hein
Fixed python2.3 incompatibility (rsplit) in qpush/qpop with index.
r3082 off = int(patch[plus+1:] or 1)
Chris Mason
mq: patch naming shortcuts...
r2696 except(ValueError, OverflowError):
pass
else:
if i + off < len(self.series):
return self.series[i + off]
Vadim Gelfer
mq: move many error messages to util.Abort
r2712 raise util.Abort(_("patch %s not in series") % patch)
mason@suse.com
Add mq extension
r1808
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 def push(self, repo, patch=None, force=False, list=False,
mason@suse.com
Add mq extension
r1808 mergeq=None, wlock=None):
if not wlock:
wlock = repo.wlock()
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 patch = self.lookup(patch)
mason@suse.com
Add mq extension
r1808 if patch and self.isapplied(patch):
Brendan Cully
mq: raise util.Abort instead of using sys.exit(1)
r3186 raise util.Abort(_("patch %s is already applied") % patch)
mason@suse.com
Add mq extension
r1808 if self.series_end() == len(self.series):
Brendan Cully
mq: raise util.Abort instead of using sys.exit(1)
r3186 raise util.Abort(_("patch series fully applied"))
mason@suse.com
Add mq extension
r1808 if not force:
self.check_localchanges(repo)
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810
mason@suse.com
Add mq extension
r1808 self.applied_dirty = 1;
start = self.series_end()
if start > 0:
self.check_toppatch(repo)
if not patch:
patch = self.series[start]
end = start + 1
else:
end = self.series.index(patch, start) + 1
s = self.series[start:end]
if mergeq:
ret = self.mergepatch(repo, mergeq, s, wlock)
else:
ret = self.apply(repo, s, list, wlock=wlock)
Brendan Cully
Use StatusEntry class instead of repeated status line parsing....
r2780 top = self.applied[-1].name
mason@suse.com
Add mq extension
r1808 if ret[0]:
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 self.ui.write("Errors during apply, please fix and refresh %s\n" %
mason@suse.com
Add mq extension
r1808 top)
else:
self.ui.write("Now at: %s\n" % top)
return ret[0]
Chris Mason
mq: qpop should act like quilt pop...
r2697 def pop(self, repo, patch=None, force=False, update=True, all=False,
wlock=None):
mason@suse.com
Add mq extension
r1808 def getfile(f, rev):
t = repo.file(f).read(rev)
Benoit Boissinot
mq: remove unecessary code, duplicate with util.opener
r3982 repo.wfile(f, "w").write(t)
mason@suse.com
Add mq extension
r1808
if not wlock:
wlock = repo.wlock()
if patch:
# index, rev, patch
info = self.isapplied(patch)
if not info:
patch = self.lookup(patch)
info = self.isapplied(patch)
if not info:
Vadim Gelfer
mq: move many error messages to util.Abort
r2712 raise util.Abort(_("patch %s is not applied") % patch)
mason@suse.com
Add mq extension
r1808 if len(self.applied) == 0:
Brendan Cully
mq: raise util.Abort instead of using sys.exit(1)
r3186 raise util.Abort(_("no patches applied"))
mason@suse.com
Add mq extension
r1808
if not update:
parents = repo.dirstate.parents()
Brendan Cully
Use StatusEntry class instead of repeated status line parsing....
r2780 rr = [ revlog.bin(x.rev) for x in self.applied ]
mason@suse.com
Add mq extension
r1808 for p in parents:
if p in rr:
self.ui.warn("qpop: forcing dirstate update\n")
update = True
if not force and update:
self.check_localchanges(repo)
self.applied_dirty = 1;
end = len(self.applied)
if not patch:
Chris Mason
mq: qpop should act like quilt pop...
r2697 if all:
popi = 0
else:
popi = len(self.applied) - 1
else:
popi = info[0] + 1
if popi >= end:
self.ui.warn("qpop: %s is already at the top\n" % patch)
return
Brendan Cully
Use StatusEntry class instead of repeated status line parsing....
r2780 info = [ popi ] + [self.applied[popi].rev, self.applied[popi].name]
Chris Mason
mq: qpop should act like quilt pop...
r2697
mason@suse.com
Add mq extension
r1808 start = info[0]
rev = revlog.bin(info[1])
# we know there are no local changes, so we can make a simplified
# form of hg.update.
if update:
top = self.check_toppatch(repo)
qp = self.qparents(repo, rev)
changes = repo.changelog.read(qp)
mmap = repo.manifest.read(changes[0])
Vadim Gelfer
remove localrepository.changes....
r2875 m, a, r, d, u = repo.status(qp, top)[:5]
mason@suse.com
Add mq extension
r1808 if d:
raise util.Abort("deletions found between repo revs")
Vadim Gelfer
remove localrepository.changes....
r2875 for f in m:
mason@suse.com
Add mq extension
r1808 getfile(f, mmap[f])
for f in r:
getfile(f, mmap[f])
Vadim Gelfer
manifest.execf is now a function.
r2872 util.set_exec(repo.wjoin(f), mmap.execf(f))
Vadim Gelfer
remove localrepository.changes....
r2875 repo.dirstate.update(m + r, 'n')
mason@suse.com
Add mq extension
r1808 for f in a:
Alexis S. L. Carvalho
qrefresh: fix handling of added files (including copies) in the slow path
r3699 try:
os.unlink(repo.wjoin(f))
except OSError, e:
if e.errno != errno.ENOENT:
raise
mason@suse.com
Add mq extension
r1808 try: os.removedirs(os.path.dirname(repo.wjoin(f)))
except: pass
if a:
repo.dirstate.forget(a)
repo.dirstate.setparents(qp, revlog.nullid)
self.strip(repo, rev, update=False, backup='strip', wlock=wlock)
del self.applied[start:end]
if len(self.applied):
Brendan Cully
Use StatusEntry class instead of repeated status line parsing....
r2780 self.ui.write("Now at: %s\n" % self.applied[-1].name)
mason@suse.com
Add mq extension
r1808 else:
self.ui.write("Patch queue now empty\n")
Brendan Cully
Fix test-mq-qdiff; add -I and -X options to qdiff
r2937 def diff(self, repo, pats, opts):
mason@suse.com
Add mq extension
r1808 top = self.check_toppatch(repo)
if not top:
self.ui.write("No patches applied\n")
return
qp = self.qparents(repo, top)
Alexis S. L. Carvalho
add --git option to qdiff
r3697 if opts.get('git'):
self.diffopts().git = True
Brendan Cully
Fix test-mq-qdiff; add -I and -X options to qdiff
r2937 self.printdiff(repo, qp, files=pats, opts=opts)
mason@suse.com
Add mq extension
r1808
Brendan Cully
allow qrefresh to take a list of files; closes #96.
r2938 def refresh(self, repo, pats=None, **opts):
mason@suse.com
Add mq extension
r1808 if len(self.applied) == 0:
self.ui.write("No patches applied\n")
Bryan O'Sullivan
qrefresh: exit with status 1 if no patches applied.
r3004 return 1
mason@suse.com
Add mq extension
r1808 wlock = repo.wlock()
self.check_toppatch(repo)
Brendan Cully
Call patch.diff directly instead of printdiff - this also saves an...
r3027 (top, patchfn) = (self.applied[-1].rev, self.applied[-1].name)
mason@suse.com
Add mq extension
r1808 top = revlog.bin(top)
cparents = repo.changelog.parents(top)
patchparent = self.qparents(repo, top)
Brendan Cully
Call patch.diff directly instead of printdiff - this also saves an...
r3027 message, comments, user, date, patchfound = self.readheaders(patchfn)
mason@suse.com
Add mq extension
r1808
Brendan Cully
Call patch.diff directly instead of printdiff - this also saves an...
r3027 patchf = self.opener(patchfn, "w")
Brendan Cully
allow qrefresh to take a list of files; closes #96.
r2938 msg = opts.get('msg', '').rstrip()
Brendan Cully
Change patch header as well as commit message with qrefresh -m or -l.
r2745 if msg:
if comments:
# Remove existing message.
ci = 0
Benoit Boissinot
use xrange instead of range
r3473 for mi in xrange(len(message)):
Brendan Cully
Change patch header as well as commit message with qrefresh -m or -l.
r2745 while message[mi] != comments[ci]:
ci += 1
del comments[ci]
comments.append(msg)
mason@suse.com
Add mq extension
r1808 if comments:
comments = "\n".join(comments) + '\n\n'
patchf.write(comments)
Alexis S. L. Carvalho
qrefresh: respect --git even in the slow path
r3698 if opts.get('git'):
self.diffopts().git = True
Brendan Cully
allow qrefresh to take a list of files; closes #96.
r2938 fns, matchfn, anypats = cmdutil.matchpats(repo, pats, opts)
mason@suse.com
Add mq extension
r1808 tip = repo.changelog.tip()
if top == tip:
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 # if the top of our patch queue is also the tip, there is an
mason@suse.com
Add mq extension
r1808 # optimization here. We update the dirstate in place and strip
# off the tip commit. Then just commit the current directory
# tree. We can also send repo.commit the list of files
# changed to speed up the diff
#
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 # in short mode, we only diff the files included in the
mason@suse.com
Add mq extension
r1808 # patch already
#
# this should really read:
Vadim Gelfer
remove localrepository.changes....
r2875 # mm, dd, aa, aa2, uu = repo.status(tip, patchparent)[:5]
mason@suse.com
Add mq extension
r1808 # but we do it backwards to take advantage of manifest/chlog
Vadim Gelfer
remove localrepository.changes....
r2875 # caching against the next repo.status call
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 #
Vadim Gelfer
remove localrepository.changes....
r2875 mm, aa, dd, aa2, uu = repo.status(patchparent, tip)[:5]
Alexis S. L. Carvalho
qrefresh: fix handling of copies in the fast path
r3700 changes = repo.changelog.read(tip)
man = repo.manifest.read(changes[0])
aaa = aa[:]
Brendan Cully
allow qrefresh to take a list of files; closes #96.
r2938 if opts.get('short'):
Vadim Gelfer
remove localrepository.changes....
r2875 filelist = mm + aa + dd
mason@suse.com
Add mq extension
r1808 else:
filelist = None
Vadim Gelfer
remove localrepository.changes....
r2875 m, a, r, d, u = repo.status(files=filelist)[:5]
mason@suse.com
Add mq extension
r1808
# we might end up with files that were added between tip and
# the dirstate parent, but then changed in the local dirstate.
# in this case, we want them to only show up in the added section
Vadim Gelfer
remove localrepository.changes....
r2875 for x in m:
mason@suse.com
Add mq extension
r1808 if x not in aa:
Vadim Gelfer
remove localrepository.changes....
r2875 mm.append(x)
mason@suse.com
Add mq extension
r1808 # we might end up with files added by the local dirstate that
# were deleted by the patch. In this case, they should only
# show up in the changed section.
for x in a:
if x in dd:
del dd[dd.index(x)]
Vadim Gelfer
remove localrepository.changes....
r2875 mm.append(x)
mason@suse.com
Add mq extension
r1808 else:
aa.append(x)
# make sure any files deleted in the local dirstate
# are not in the add or change column of the patch
forget = []
for x in d + r:
if x in aa:
del aa[aa.index(x)]
forget.append(x)
continue
Vadim Gelfer
remove localrepository.changes....
r2875 elif x in mm:
del mm[mm.index(x)]
mason@suse.com
Add mq extension
r1808 dd.append(x)
Matt Mackall
Make util.unique return a list
r3535 m = util.unique(mm)
r = util.unique(dd)
a = util.unique(aa)
Brendan Cully
allow qrefresh to take a list of files; closes #96.
r2938 filelist = filter(matchfn, util.unique(m + r + a))
Brendan Cully
Call patch.diff directly instead of printdiff - this also saves an...
r3027 patch.diff(repo, patchparent, files=filelist, match=matchfn,
fp=patchf, changes=(m, a, r, [], u),
opts=self.diffopts())
mason@suse.com
Add mq extension
r1808 patchf.close()
repo.dirstate.setparents(*cparents)
Alexis S. L. Carvalho
qrefresh: fix handling of copies in the fast path
r3700 copies = {}
for dst in a:
src = repo.dirstate.copied(dst)
if src is None:
continue
copies.setdefault(src, []).append(dst)
mason@suse.com
Add mq extension
r1808 repo.dirstate.update(a, 'a')
Alexis S. L. Carvalho
qrefresh: fix handling of copies in the fast path
r3700 # remember the copies between patchparent and tip
# this may be slow, so don't do it if we're not tracking copies
if self.diffopts().git:
for dst in aaa:
f = repo.file(dst)
src = f.renamed(man[dst])
if src:
copies[src[0]] = copies.get(dst, [])
if dst in a:
copies[src[0]].append(dst)
# we can't copy a file created by the patch itself
if dst in copies:
del copies[dst]
for src, dsts in copies.iteritems():
for dst in dsts:
repo.dirstate.copy(src, dst)
mason@suse.com
Add mq extension
r1808 repo.dirstate.update(r, 'r')
Brendan Cully
allow qrefresh to take a list of files; closes #96.
r2938 # if the patch excludes a modified file, mark that file with mtime=0
# so status can see it.
mm = []
Benoit Boissinot
use xrange instead of range
r3473 for i in xrange(len(m)-1, -1, -1):
Brendan Cully
allow qrefresh to take a list of files; closes #96.
r2938 if not matchfn(m[i]):
mm.append(m[i])
del m[i]
Vadim Gelfer
remove localrepository.changes....
r2875 repo.dirstate.update(m, 'n')
Brendan Cully
allow qrefresh to take a list of files; closes #96.
r2938 repo.dirstate.update(mm, 'n', st_mtime=0)
mason@suse.com
Add mq extension
r1808 repo.dirstate.forget(forget)
"Mathieu Clabaut "
MQ: uniformise message and logfile option....
r2694 if not msg:
if not message:
Brendan Cully
Call patch.diff directly instead of printdiff - this also saves an...
r3027 message = "patch queue: %s\n" % patchfn
"Mathieu Clabaut "
MQ: uniformise message and logfile option....
r2694 else:
message = "\n".join(message)
mason@suse.com
Add mq extension
r1808 else:
"Mathieu Clabaut "
MQ: uniformise message and logfile option....
r2694 message = msg
mason@suse.com
Add mq extension
r1808 self.strip(repo, top, update=False, backup='strip', wlock=wlock)
n = repo.commit(filelist, message, changes[1], force=1, wlock=wlock)
Brendan Cully
Call patch.diff directly instead of printdiff - this also saves an...
r3027 self.applied[-1] = statusentry(revlog.hex(n), patchfn)
mason@suse.com
Add mq extension
r1808 self.applied_dirty = 1
else:
Vadim Gelfer
refactor text diff/patch code....
r2874 self.printdiff(repo, patchparent, fp=patchf)
mason@suse.com
Add mq extension
r1808 patchf.close()
Alexis S. L. Carvalho
qrefresh: fix handling of added files (including copies) in the slow path
r3699 added = repo.status()[1]
for a in added:
f = repo.wjoin(a)
try:
os.unlink(f)
except OSError, e:
if e.errno != errno.ENOENT:
raise
try: os.removedirs(os.path.dirname(f))
except: pass
# forget the file copies in the dirstate
# push should readd the files later on
repo.dirstate.forget(added)
mason@suse.com
Add mq extension
r1808 self.pop(repo, force=True, wlock=wlock)
self.push(repo, force=True, wlock=wlock)
def init(self, repo, create=False):
if os.path.isdir(self.path):
Vadim Gelfer
mq: move many error messages to util.Abort
r2712 raise util.Abort(_("patch queue directory already exists"))
mason@suse.com
Add mq extension
r1808 os.mkdir(self.path)
if create:
return self.qrepo(create=True)
def unapplied(self, repo, patch=None):
if patch and patch not in self.series:
Vadim Gelfer
mq: move many error messages to util.Abort
r2712 raise util.Abort(_("patch %s is not in series file") % patch)
mason@suse.com
Add mq extension
r1808 if not patch:
start = self.series_end()
else:
start = self.series.index(patch) + 1
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 unapplied = []
for i in xrange(start, len(self.series)):
pushable, reason = self.pushable(i)
if pushable:
unapplied.append((i, self.series[i]))
self.explain_pushable(i)
return unapplied
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810
Brendan Cully
mq: add --summary to qapplied, qunapplied, qtop, qnext and qprev...
r3183 def qseries(self, repo, missing=None, start=0, length=0, status=None,
summary=False):
def displayname(patchname):
if summary:
msg = self.readheaders(patchname)[0]
msg = msg and ': ' + msg[0] or ': '
else:
msg = ''
return '%s%s' % (patchname, msg)
def pname(i):
if status == 'A':
return self.applied[i].name
else:
return self.series[i]
Alexis S. L. Carvalho
fix qseries -v and guards interaction...
r3763 applied = dict.fromkeys([p.name for p in self.applied])
Brendan Cully
mq: add --summary to qapplied, qunapplied, qtop, qnext and qprev...
r3183 if not length:
length = len(self.series) - start
mason@suse.com
Add mq extension
r1808 if not missing:
Benoit Boissinot
use xrange instead of range
r3473 for i in xrange(start, start+length):
Brendan Cully
mq: add --summary to qapplied, qunapplied, qtop, qnext and qprev...
r3183 pfx = ''
Alexis S. L. Carvalho
fix qseries -v and guards interaction...
r3763 patch = pname(i)
mason@suse.com
Add mq extension
r1808 if self.ui.verbose:
Alexis S. L. Carvalho
fix qseries -v and guards interaction...
r3763 if patch in applied:
stat = 'A'
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 elif self.pushable(i)[0]:
Alexis S. L. Carvalho
fix qseries -v and guards interaction...
r3763 stat = 'U'
Brendan Cully
Add -s option to qseries: display first line of patch header.
r2756 else:
Alexis S. L. Carvalho
fix qseries -v and guards interaction...
r3763 stat = 'G'
pfx = '%d %s ' % (i, stat)
Brendan Cully
mq: add --summary to qapplied, qunapplied, qtop, qnext and qprev...
r3183 self.ui.write('%s%s\n' % (pfx, displayname(patch)))
mason@suse.com
Add mq extension
r1808 else:
Benoit Boissinot
mq: fix variables shadowing builtin
r2794 msng_list = []
mason@suse.com
Add mq extension
r1808 for root, dirs, files in os.walk(self.path):
d = root[len(self.path) + 1:]
for f in files:
fl = os.path.join(d, f)
Thomas Arendsen Hein
Fix mq's usage of opener, which don't allow absolute paths now.
r1852 if (fl not in self.series and
fl not in (self.status_path, self.series_path)
and not fl.startswith('.')):
Benoit Boissinot
mq: fix variables shadowing builtin
r2794 msng_list.append(fl)
msng_list.sort()
Benoit Boissinot
mq: remove unecessary test
r2795 for x in msng_list:
Brendan Cully
mq: add --summary to qapplied, qunapplied, qtop, qnext and qprev...
r3183 pfx = self.ui.verbose and ('D ') or ''
self.ui.write("%s%s\n" % (pfx, displayname(x)))
mason@suse.com
Add mq extension
r1808
def issaveline(self, l):
Brendan Cully
Update qsave to use StatusEntry; don't throw exception on bad status lines.
r2816 if l.name == '.hg.patches.save.line':
mason@suse.com
Add mq extension
r1808 return True
def qrepo(self, create=False):
Vadim Gelfer
mq: add join method
r2819 if create or os.path.isdir(self.join(".hg")):
Thomas Arendsen Hein
Create local ui object per repository, so .hg/hgrc don't get mixed....
r1839 return hg.repository(self.ui, path=self.path, create=create)
mason@suse.com
Add mq extension
r1808
def restore(self, repo, rev, delete=None, qupdate=None):
c = repo.changelog.read(rev)
desc = c[4].strip()
lines = desc.splitlines()
i = 0
datastart = None
series = []
applied = []
qpp = None
for i in xrange(0, len(lines)):
if lines[i] == 'Patch Data:':
datastart = i + 1
elif lines[i].startswith('Dirstate:'):
l = lines[i].rstrip()
l = l[10:].split(' ')
qpp = [ hg.bin(x) for x in l ]
elif datastart != None:
l = lines[i].rstrip()
Brendan Cully
Make mq camelcase consistent with the rest of hg.
r2818 se = statusentry(l)
Benoit Boissinot
mq: fix variables shadowing builtin
r2794 file_ = se.name
if se.rev:
Brendan Cully
Use StatusEntry class instead of repeated status line parsing....
r2780 applied.append(se)
Brendan Cully
mq: don't write applied patches into series twice in restore
r3185 else:
series.append(file_)
mason@suse.com
Add mq extension
r1808 if datastart == None:
self.ui.warn("No saved patch data found\n")
return 1
self.ui.warn("restoring status: %s\n" % lines[0])
self.full_series = series
self.applied = applied
Vadim Gelfer
mq: rename read_series as parse_series, make simpler and faster
r2767 self.parse_series()
mason@suse.com
Add mq extension
r1808 self.series_dirty = 1
self.applied_dirty = 1
heads = repo.changelog.heads()
if delete:
if rev not in heads:
self.ui.warn("save entry has children, leaving it alone\n")
else:
self.ui.warn("removing save entry %s\n" % hg.short(rev))
pp = repo.dirstate.parents()
if rev in pp:
update = True
else:
update = False
self.strip(repo, rev, update=update, backup='strip')
if qpp:
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 self.ui.warn("saved queue repository parents: %s %s\n" %
mason@suse.com
Add mq extension
r1808 (hg.short(qpp[0]), hg.short(qpp[1])))
if qupdate:
print "queue directory updating"
r = self.qrepo()
if not r:
self.ui.warn("Unable to load queue repository\n")
return 1
Matt Mackall
Introduce update helper functions: update, merge, clean, and revert
r2808 hg.clean(r, qpp[0])
mason@suse.com
Add mq extension
r1808
def save(self, repo, msg=None):
if len(self.applied) == 0:
self.ui.warn("save: no patches applied, exiting\n")
return 1
if self.issaveline(self.applied[-1]):
self.ui.warn("status is already saved\n")
return 1
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810
mason@suse.com
Add mq extension
r1808 ar = [ ':' + x for x in self.full_series ]
if not msg:
msg = "hg patches saved state"
else:
msg = "hg patches: " + msg.rstrip('\r\n')
r = self.qrepo()
if r:
pp = r.dirstate.parents()
msg += "\nDirstate: %s %s" % (hg.hex(pp[0]), hg.hex(pp[1]))
msg += "\n\nPatch Data:\n"
Brendan Cully
Update qsave to use StatusEntry; don't throw exception on bad status lines.
r2816 text = msg + "\n".join([str(x) for x in self.applied]) + '\n' + (ar and
"\n".join(ar) + '\n' or "")
mason@suse.com
Add mq extension
r1808 n = repo.commit(None, text, user=None, force=1)
if not n:
self.ui.warn("repo commit failed\n")
return 1
Brendan Cully
Make mq camelcase consistent with the rest of hg.
r2818 self.applied.append(statusentry(revlog.hex(n),'.hg.patches.save.line'))
mason@suse.com
Add mq extension
r1808 self.applied_dirty = 1
Chris Mason
mq: fix qnew and qimport to deal with series file comments...
r2698 def full_series_end(self):
if len(self.applied) > 0:
Brendan Cully
Use StatusEntry class instead of repeated status line parsing....
r2780 p = self.applied[-1].name
Chris Mason
mq: fix qnew and qimport to deal with series file comments...
r2698 end = self.find_series(p)
if end == None:
return len(self.full_series)
return end + 1
return 0
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 def series_end(self, all_patches=False):
mason@suse.com
Add mq extension
r1808 end = 0
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 def next(start):
if all_patches:
return start
i = start
while i < len(self.series):
p, reason = self.pushable(i)
if p:
break
self.explain_pushable(i)
i += 1
return i
mason@suse.com
Add mq extension
r1808 if len(self.applied) > 0:
Brendan Cully
Use StatusEntry class instead of repeated status line parsing....
r2780 p = self.applied[-1].name
mason@suse.com
Add mq extension
r1808 try:
end = self.series.index(p)
except ValueError:
return 0
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 return next(end + 1)
return next(end)
mason@suse.com
Add mq extension
r1808
def appliedname(self, index):
Brendan Cully
Use StatusEntry class instead of repeated status line parsing....
r2780 pname = self.applied[index].name
mason@suse.com
Add mq extension
r1808 if not self.ui.verbose:
"Mathieu Clabaut "
mq: uniform verbose display of patche[s]....
r2677 p = pname
else:
Brendan Cully
mq: fix appliedname
r2941 p = str(self.series.index(pname)) + " " + pname
mason@suse.com
Add mq extension
r1808 return p
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810
Brendan Cully
mq: Add --rev argument to qimport, to adopt existing changesets.
r3141 def qimport(self, repo, files, patchname=None, rev=None, existing=None,
Brendan Cully
mq: add --git option to qimport -r
r3691 force=None, git=False):
Brendan Cully
mq: Add --rev argument to qimport, to adopt existing changesets.
r3141 def checkseries(patchname):
if patchname in self.series:
raise util.Abort(_('patch %s is already in the series file')
% patchname)
def checkfile(patchname):
if not force and os.path.exists(self.join(patchname)):
raise util.Abort(_('patch "%s" already exists')
% patchname)
if rev:
if files:
raise util.Abort(_('option "-r" not valid when importing '
'files'))
Thomas Arendsen Hein
Removed unused ui parameter from revpair/revrange and fix its users.
r3707 rev = cmdutil.revrange(repo, rev)
Brendan Cully
mq: Add --rev argument to qimport, to adopt existing changesets.
r3141 rev.sort(lambda x, y: cmp(y, x))
if (len(files) > 1 or len(rev) > 1) and patchname:
Vadim Gelfer
mq: move many error messages to util.Abort
r2712 raise util.Abort(_('option "-n" not valid when importing multiple '
Brendan Cully
mq: Add --rev argument to qimport, to adopt existing changesets.
r3141 'patches'))
mason@suse.com
Add mq extension
r1808 i = 0
Vadim Gelfer
mq: add qimported patches if patch dir is a repo
r2488 added = []
Brendan Cully
mq: Add --rev argument to qimport, to adopt existing changesets.
r3141 if rev:
# If mq patches are applied, we can only import revisions
# that form a linear path to qbase.
# Otherwise, they should form a linear path to a head.
heads = repo.changelog.heads(repo.changelog.node(rev[-1]))
if len(heads) > 1:
raise util.Abort(_('revision %d is the root of more than one '
'branch') % rev[-1])
if self.applied:
base = revlog.hex(repo.changelog.node(rev[0]))
if base in [n.rev for n in self.applied]:
raise util.Abort(_('revision %d is already managed')
% rev[0])
if heads != [revlog.bin(self.applied[-1].rev)]:
raise util.Abort(_('revision %d is not the parent of '
'the queue') % rev[0])
base = repo.changelog.rev(revlog.bin(self.applied[0].rev))
lastparent = repo.changelog.parentrevs(base)[0]
else:
if heads != [repo.changelog.node(rev[0])]:
raise util.Abort(_('revision %d has unmanaged children')
% rev[0])
lastparent = None
Brendan Cully
mq: add --git option to qimport -r
r3691 if git:
self.diffopts().git = True
Brendan Cully
mq: Add --rev argument to qimport, to adopt existing changesets.
r3141 for r in rev:
p1, p2 = repo.changelog.parentrevs(r)
n = repo.changelog.node(r)
Thomas Arendsen Hein
Define and use nullrev (revision of nullid) instead of -1.
r3578 if p2 != revlog.nullrev:
Brendan Cully
mq: Add --rev argument to qimport, to adopt existing changesets.
r3141 raise util.Abort(_('cannot import merge revision %d') % r)
if lastparent and lastparent != r:
raise util.Abort(_('revision %d is not the parent of %d')
% (r, lastparent))
lastparent = p1
if not patchname:
patchname = '%d.diff' % r
checkseries(patchname)
checkfile(patchname)
self.full_series.insert(0, patchname)
patchf = self.opener(patchname, "w")
patch.export(repo, [n], fp=patchf, opts=self.diffopts())
patchf.close()
se = statusentry(revlog.hex(n), patchname)
self.applied.insert(0, se)
added.append(patchname)
patchname = None
self.parse_series()
self.applied_dirty = 1
mason@suse.com
Add mq extension
r1808 for filename in files:
if existing:
Brendan Cully
mq: support qimport -
r3547 if filename == '-':
raise util.Abort(_('-e is incompatible with import from -'))
Brendan Cully
qimport: rename patch to patchname to avoid shadowing module
r3133 if not patchname:
patchname = filename
if not os.path.isfile(self.join(patchname)):
raise util.Abort(_("patch %s does not exist") % patchname)
mason@suse.com
Add mq extension
r1808 else:
try:
Brendan Cully
mq: support qimport -
r3547 if filename == '-':
if not patchname:
raise util.Abort(_('need --name to import a patch from -'))
text = sys.stdin.read()
else:
text = file(filename).read()
mason@suse.com
Add mq extension
r1808 except IOError:
Brendan Cully
qimport: rename patch to patchname to avoid shadowing module
r3133 raise util.Abort(_("unable to read %s") % patchname)
if not patchname:
patchname = os.path.basename(filename)
Brendan Cully
mq: Add --rev argument to qimport, to adopt existing changesets.
r3141 checkfile(patchname)
Brendan Cully
qimport: rename patch to patchname to avoid shadowing module
r3133 patchf = self.opener(patchname, "w")
mason@suse.com
Add mq extension
r1808 patchf.write(text)
Brendan Cully
mq: Add --rev argument to qimport, to adopt existing changesets.
r3141 checkseries(patchname)
Chris Mason
mq: fix qnew and qimport to deal with series file comments...
r2698 index = self.full_series_end() + i
Brendan Cully
qimport: rename patch to patchname to avoid shadowing module
r3133 self.full_series[index:index] = [patchname]
Vadim Gelfer
mq: rename read_series as parse_series, make simpler and faster
r2767 self.parse_series()
Brendan Cully
qimport: rename patch to patchname to avoid shadowing module
r3133 self.ui.warn("adding %s to series file\n" % patchname)
mason@suse.com
Add mq extension
r1808 i += 1
Brendan Cully
qimport: rename patch to patchname to avoid shadowing module
r3133 added.append(patchname)
patchname = None
mason@suse.com
Add mq extension
r1808 self.series_dirty = 1
Vadim Gelfer
mq: add qimported patches if patch dir is a repo
r2488 qrepo = self.qrepo()
if qrepo:
qrepo.add(added)
mason@suse.com
Add mq extension
r1808
Brendan Cully
mq: change qdel --forget to --rev; accept any revision symbol
r3373 def delete(ui, repo, *patches, **opts):
Brendan Cully
Allow qdel to delete multiple patches.
r2905 """remove patches from queue
Brendan Cully
Add -f option to qdelete, to remove patch file.
r2752
Brendan Cully
mq: change qdel --forget to --rev; accept any revision symbol
r3373 With --rev, mq will stop managing the named revisions. The
Brendan Cully
mq: add qdelete --forget option...
r3088 patches must be applied and at the base of the stack. This option
is useful when the patches have been applied upstream.
Otherwise, the patches must not be applied.
With --keep, the patch files are preserved in the patch directory."""
Brendan Cully
mq: replace module-wide repo hash with a repo attribute
r2724 q = repo.mq
Brendan Cully
mq: change qdel --forget to --rev; accept any revision symbol
r3373 q.delete(repo, patches, opts)
mason@suse.com
Add mq extension
r1808 q.save_dirty()
return 0
def applied(ui, repo, patch=None, **opts):
"""print the patches already applied"""
Brendan Cully
mq: add --summary to qapplied, qunapplied, qtop, qnext and qprev...
r3183 q = repo.mq
if patch:
if patch not in q.series:
raise util.Abort(_("patch %s is not in series file") % patch)
end = q.series.index(patch) + 1
else:
end = len(q.applied)
Brendan Cully
mq: raise util.Abort instead of using sys.exit(1)
r3186 if not end:
return
Brendan Cully
mq: add --summary to qapplied, qunapplied, qtop, qnext and qprev...
r3183 return q.qseries(repo, length=end, status='A', summary=opts.get('summary'))
mason@suse.com
Add mq extension
r1808
def unapplied(ui, repo, patch=None, **opts):
"""print the patches not yet applied"""
Brendan Cully
mq: add --summary to qapplied, qunapplied, qtop, qnext and qprev...
r3183 q = repo.mq
if patch:
if patch not in q.series:
raise util.Abort(_("patch %s is not in series file") % patch)
start = q.series.index(patch) + 1
else:
start = q.series_end()
q.qseries(repo, start=start, summary=opts.get('summary'))
mason@suse.com
Add mq extension
r1808
def qimport(ui, repo, *filename, **opts):
Brendan Cully
mq: Add --rev argument to qimport, to adopt existing changesets.
r3141 """import a patch
The patch will have the same name as its source file unless you
give it a new one with --name.
You can register an existing patch inside the patch directory
with the --existing flag.
With --force, an existing patch of the same name will be overwritten.
An existing changeset may be placed under mq control with --rev
(e.g. qimport --rev tip -n patch will place tip under mq control).
Brendan Cully
mq: add --git option to qimport -r
r3691 With --git, patches imported with --rev will use the git diff
format.
Brendan Cully
mq: Add --rev argument to qimport, to adopt existing changesets.
r3141 """
Brendan Cully
mq: replace module-wide repo hash with a repo attribute
r2724 q = repo.mq
Brendan Cully
qimport: rename patch to patchname to avoid shadowing module
r3133 q.qimport(repo, filename, patchname=opts['name'],
Brendan Cully
mq: add --git option to qimport -r
r3691 existing=opts['existing'], force=opts['force'], rev=opts['rev'],
git=opts['git'])
mason@suse.com
Add mq extension
r1808 q.save_dirty()
return 0
def init(ui, repo, **opts):
Brendan Cully
Add more verbose help text to mq commands.
r2754 """init a new queue repository
The queue repository is unversioned by default. If -c is
specified, qinit will create a separate nested repository
for patches. Use qcommit to commit changes to this queue
repository."""
Brendan Cully
mq: replace module-wide repo hash with a repo attribute
r2724 q = repo.mq
mason@suse.com
Add mq extension
r1808 r = q.init(repo, create=opts['create_repo'])
q.save_dirty()
if r:
fp = r.wopener('.hgignore', 'w')
print >> fp, 'syntax: glob'
print >> fp, 'status'
Brendan Cully
mq: auto-ignore guards in qinit -c
r3871 print >> fp, 'guards'
mason@suse.com
Add mq extension
r1808 fp.close()
r.wopener('series', 'w').close()
r.add(['.hgignore', 'series'])
return 0
Vadim Gelfer
mq: add qclone command
r2720 def clone(ui, source, dest=None, **opts):
'''clone main and patch repository at same time
If source is local, destination will have no patches applied. If
source is remote, this command can not check if patches are
applied in source, so cannot guarantee that patches are not
applied in destination. If you clone remote repository, be sure
before that it has no patches applied.
Source patch repository is looked for in <src>/.hg/patches by
default. Use -p <url> to change.
'''
Bryan O'Sullivan
fix call to commands.setremoteconfig
r2766 commands.setremoteconfig(ui, opts)
Vadim Gelfer
mq: add qclone command
r2720 if dest is None:
dest = hg.defaultdest(source)
sr = hg.repository(ui, ui.expandpath(source))
qbase, destrev = None, None
if sr.local():
reposetup(ui, sr)
Vadim Gelfer
mq: update to handle repomap not longer used
r2725 if sr.mq.applied:
Brendan Cully
Use StatusEntry class instead of repeated status line parsing....
r2780 qbase = revlog.bin(sr.mq.applied[0].rev)
Vadim Gelfer
mq: add qclone command
r2720 if not hg.islocal(dest):
destrev = sr.parents(qbase)[0]
ui.note(_('cloning main repo\n'))
sr, dr = hg.clone(ui, sr, dest,
pull=opts['pull'],
rev=destrev,
update=False,
stream=opts['uncompressed'])
ui.note(_('cloning patch repo\n'))
spr, dpr = hg.clone(ui, opts['patches'] or (sr.url() + '/.hg/patches'),
dr.url() + '/.hg/patches',
pull=opts['pull'],
update=not opts['noupdate'],
stream=opts['uncompressed'])
if dr.local():
if qbase:
ui.note(_('stripping applied patches from destination repo\n'))
reposetup(ui, dr)
Vadim Gelfer
mq: update to handle repomap not longer used
r2725 dr.mq.strip(dr, qbase, update=False, backup=None)
Vadim Gelfer
mq: add qclone command
r2720 if not opts['noupdate']:
ui.note(_('updating destination repo\n'))
Matt Mackall
Move merge code to its own module...
r2775 hg.update(dr, dr.changelog.tip())
Vadim Gelfer
mq: add qclone command
r2720
mason@suse.com
Add mq extension
r1808 def commit(ui, repo, *pats, **opts):
Thomas Arendsen Hein
mq: Added help for qcommit, consistently talk about queue repository.
r2526 """commit changes in the queue repository"""
Brendan Cully
mq: replace module-wide repo hash with a repo attribute
r2724 q = repo.mq
mason@suse.com
Add mq extension
r1808 r = q.qrepo()
if not r: raise util.Abort('no queue repository')
commands.commit(r.ui, r, *pats, **opts)
def series(ui, repo, **opts):
"""print the entire series file"""
Brendan Cully
Add -s option to qseries: display first line of patch header.
r2756 repo.mq.qseries(repo, missing=opts['missing'], summary=opts['summary'])
mason@suse.com
Add mq extension
r1808 return 0
def top(ui, repo, **opts):
"""print the name of the current patch"""
Brendan Cully
mq: add --summary to qapplied, qunapplied, qtop, qnext and qprev...
r3183 q = repo.mq
t = len(q.applied)
if t:
return q.qseries(repo, start=t-1, length=1, status='A',
summary=opts.get('summary'))
else:
ui.write("No patches applied\n")
return 1
mason@suse.com
Add mq extension
r1808
def next(ui, repo, **opts):
"""print the name of the next patch"""
Brendan Cully
mq: add --summary to qapplied, qunapplied, qtop, qnext and qprev...
r3183 q = repo.mq
end = q.series_end()
if end == len(q.series):
ui.write("All patches applied\n")
return 1
return q.qseries(repo, start=end, length=1, summary=opts.get('summary'))
mason@suse.com
Add mq extension
r1808
def prev(ui, repo, **opts):
"""print the name of the previous patch"""
Brendan Cully
mq: add --summary to qapplied, qunapplied, qtop, qnext and qprev...
r3183 q = repo.mq
l = len(q.applied)
if l == 1:
ui.write("Only one patch applied\n")
return 1
if not l:
ui.write("No patches applied\n")
return 1
return q.qseries(repo, start=l-2, length=1, status='A',
summary=opts.get('summary'))
mason@suse.com
Add mq extension
r1808
def new(ui, repo, patch, **opts):
Brendan Cully
Add more verbose help text to mq commands.
r2754 """create a new patch
qnew creates a new patch on top of the currently-applied patch
(if any). It will refuse to run if there are any outstanding
changes unless -f is specified, in which case the patch will
be initialised with them.
Brendan Cully
Add qnew -e option.
r2939 -e, -m or -l set the patch header as well as the commit message.
If none is specified, the patch header is empty and the
Brendan Cully
Clean up qnew help text.
r2770 commit message is 'New patch: PATCH'"""
Brendan Cully
mq: replace module-wide repo hash with a repo attribute
r2724 q = repo.mq
Brendan Cully
Update mq to use new logmessage arglist from 2794:bd8a9a94139f
r2804 message = commands.logmessage(opts)
Brendan Cully
Add qnew -e option.
r2939 if opts['edit']:
message = ui.edit(message, ui.username())
"Mathieu Clabaut "
MQ: uniformise message and logfile option....
r2694 q.new(repo, patch, msg=message, force=opts['force'])
mason@suse.com
Add mq extension
r1808 q.save_dirty()
return 0
Brendan Cully
allow qrefresh to take a list of files; closes #96.
r2938 def refresh(ui, repo, *pats, **opts):
Brendan Cully
mq help text updates and speling fixes
r2940 """update the current patch
If any file patterns are provided, the refreshed patch will contain only
the modifications that match those patterns; the remaining modifications
will remain in the working directory.
"""
Brendan Cully
mq: replace module-wide repo hash with a repo attribute
r2724 q = repo.mq
Brendan Cully
Update mq to use new logmessage arglist from 2794:bd8a9a94139f
r2804 message = commands.logmessage(opts)
Brendan Cully
Add option -e/--edit to qrefresh, to edit the existing header.
r2746 if opts['edit']:
if message:
raise util.Abort(_('option "-e" incompatible with "-m" or "-l"'))
Brendan Cully
Use StatusEntry class instead of repeated status line parsing....
r2780 patch = q.applied[-1].name
Brendan Cully
Add option -e/--edit to qrefresh, to edit the existing header.
r2746 (message, comment, user, date, hasdiff) = q.readheaders(patch)
message = ui.edit('\n'.join(message), user or ui.username())
Bryan O'Sullivan
qrefresh: exit with status 1 if no patches applied.
r3004 ret = q.refresh(repo, pats, msg=message, **opts)
mason@suse.com
Add mq extension
r1808 q.save_dirty()
Bryan O'Sullivan
qrefresh: exit with status 1 if no patches applied.
r3004 return ret
mason@suse.com
Add mq extension
r1808
Brendan Cully
Fix test-mq-qdiff; add -I and -X options to qdiff
r2937 def diff(ui, repo, *pats, **opts):
mason@suse.com
Add mq extension
r1808 """diff of the current patch"""
Brendan Cully
Fix test-mq-qdiff; add -I and -X options to qdiff
r2937 repo.mq.diff(repo, pats, opts)
mason@suse.com
Add mq extension
r1808 return 0
Brendan Cully
Add -m, -l, -e options to qfold.
r2753 def fold(ui, repo, *files, **opts):
Brendan Cully
New mq command qfold: Merge patches into the current patch....
r2748 """fold the named patches into the current patch
Brendan Cully
Add -m, -l, -e options to qfold.
r2753
Brendan Cully
Add -f option to qfold; improve qfold documentation.
r2771 Patches must not yet be applied. Each patch will be successively
applied to the current patch in the order given. If all the
patches apply successfully, the current patch will be refreshed
with the new cumulative patch, and the folded patches will
Brendan Cully
Replace qdel/qfold -f option with -k/--keep.
r2904 be deleted. With -k/--keep, the folded patch files will not
Brendan Cully
Add -f option to qfold; improve qfold documentation.
r2771 be removed afterwards.
Brendan Cully
Add -m, -l, -e options to qfold.
r2753 The header for each folded patch will be concatenated with
the current patch header, separated by a line of '* * *'."""
Brendan Cully
New mq command qfold: Merge patches into the current patch....
r2748 q = repo.mq
if not files:
raise util.Abort(_('qfold requires at least one patch name'))
if not q.check_toppatch(repo):
Thomas Arendsen Hein
Never apply string formatting to generated errors with util.Abort....
r3072 raise util.Abort(_('No patches applied'))
Brendan Cully
New mq command qfold: Merge patches into the current patch....
r2748
Brendan Cully
Update mq to use new logmessage arglist from 2794:bd8a9a94139f
r2804 message = commands.logmessage(opts)
Brendan Cully
Add -m, -l, -e options to qfold.
r2753 if opts['edit']:
if message:
raise util.Abort(_('option "-e" incompatible with "-m" or "-l"'))
Brendan Cully
New mq command qfold: Merge patches into the current patch....
r2748 parent = q.lookup('qtip')
patches = []
messages = []
for f in files:
Brendan Cully
Fix qfold after recent changes
r2936 p = q.lookup(f)
if p in patches or p == parent:
ui.warn(_('Skipping already folded patch %s') % p)
if q.isapplied(p):
raise util.Abort(_('qfold cannot fold already applied patch %s') % p)
patches.append(p)
Brendan Cully
New mq command qfold: Merge patches into the current patch....
r2748
Brendan Cully
Fix qfold after recent changes
r2936 for p in patches:
Brendan Cully
Add -m, -l, -e options to qfold.
r2753 if not message:
Brendan Cully
Fix qfold after recent changes
r2936 messages.append(q.readheaders(p)[0])
pf = q.join(p)
Brendan Cully
New mq command qfold: Merge patches into the current patch....
r2748 (patchsuccess, files, fuzz) = q.patch(repo, pf)
if not patchsuccess:
Brendan Cully
Fix qfold after recent changes
r2936 raise util.Abort(_('Error folding patch %s') % p)
patch.updatedir(ui, repo, files)
Brendan Cully
New mq command qfold: Merge patches into the current patch....
r2748
Brendan Cully
Add -m, -l, -e options to qfold.
r2753 if not message:
message, comments, user = q.readheaders(parent)[0:3]
for msg in messages:
message.append('* * *')
message.extend(msg)
message = '\n'.join(message)
if opts['edit']:
message = ui.edit(message, user or ui.username())
Brendan Cully
New mq command qfold: Merge patches into the current patch....
r2748
q.refresh(repo, msg=message)
Brendan Cully
mq: update qfold to call delete correctly
r3243 q.delete(repo, patches, opts)
Brendan Cully
New mq command qfold: Merge patches into the current patch....
r2748 q.save_dirty()
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 def guard(ui, repo, *args, **opts):
'''set or print guards for a patch
Brendan Cully
mq help text updates and speling fixes
r2940 Guards control whether a patch can be pushed. A patch with no
guards is always pushed. A patch with a positive guard ("+foo") is
pushed only if the qselect command has activated it. A patch with
a negative guard ("-foo") is never pushed if the qselect command
has activated it.
Vadim Gelfer
mq: new commands qselect, qguard...
r2821
Brendan Cully
mq help text updates and speling fixes
r2940 With no arguments, print the currently active guards.
With arguments, set guards for the named patch.
Vadim Gelfer
mq: new commands qselect, qguard...
r2821
Brendan Cully
mq help text updates and speling fixes
r2940 To set a negative guard "-foo" on topmost patch ("--" is needed so
hg will not interpret "-foo" as an option):
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 hg qguard -- -foo
Brendan Cully
mq help text updates and speling fixes
r2940 To set guards on another patch:
Thomas Arendsen Hein
Whitespace/Tab cleanup
r3223 hg qguard other.patch +2.6.17 -stable
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 '''
def status(idx):
guards = q.series_guards[idx] or ['unguarded']
ui.write('%s: %s\n' % (q.series[idx], ' '.join(guards)))
q = repo.mq
patch = None
args = list(args)
if opts['list']:
if args or opts['none']:
raise util.Abort(_('cannot mix -l/--list with options or arguments'))
for i in xrange(len(q.series)):
status(i)
return
if not args or args[0][0:1] in '-+':
if not q.applied:
raise util.Abort(_('no patches applied'))
patch = q.applied[-1].name
if patch is None and args[0][0:1] not in '-+':
patch = args.pop(0)
if patch is None:
raise util.Abort(_('no patch to work with'))
if args or opts['none']:
q.set_guards(q.find_series(patch), args)
q.save_dirty()
else:
status(q.series.index(q.lookup(patch)))
Brendan Cully
Add command qheader to display the header of a given patch.
r2747 def header(ui, repo, patch=None):
"""Print the header of the topmost or specified patch"""
q = repo.mq
if patch:
patch = q.lookup(patch)
else:
if not q.applied:
ui.write('No patches applied\n')
Bryan O'Sullivan
qheader: exit withh meaningful error code.
r3008 return 1
Brendan Cully
Add command qheader to display the header of a given patch.
r2747 patch = q.lookup('qtip')
message = repo.mq.readheaders(patch)[0]
ui.write('\n'.join(message) + '\n')
mason@suse.com
Add mq extension
r1808 def lastsavename(path):
Benoit Boissinot
mq: fix variables shadowing builtin
r2794 (directory, base) = os.path.split(path)
names = os.listdir(directory)
mason@suse.com
Add mq extension
r1808 namere = re.compile("%s.([0-9]+)" % base)
Benoit Boissinot
mq: fix variables shadowing builtin
r2794 maxindex = None
mason@suse.com
Add mq extension
r1808 maxname = None
for f in names:
m = namere.match(f)
if m:
index = int(m.group(1))
Benoit Boissinot
mq: fix variables shadowing builtin
r2794 if maxindex == None or index > maxindex:
maxindex = index
mason@suse.com
Add mq extension
r1808 maxname = f
if maxname:
Benoit Boissinot
mq: fix variables shadowing builtin
r2794 return (os.path.join(directory, maxname), maxindex)
mason@suse.com
Add mq extension
r1808 return (None, None)
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810
mason@suse.com
Add mq extension
r1808 def savename(path):
(last, index) = lastsavename(path)
if last is None:
index = 0
newpath = path + ".%d" % (index + 1)
return newpath
def push(ui, repo, patch=None, **opts):
"""push the next patch onto the stack"""
Brendan Cully
mq: replace module-wide repo hash with a repo attribute
r2724 q = repo.mq
mason@suse.com
Add mq extension
r1808 mergeq = None
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810
mason@suse.com
Add mq extension
r1808 if opts['all']:
Brendan Cully
mq: handle qpush -a with empty series
r3604 if not q.series:
raise util.Abort(_('no patches in series'))
mason@suse.com
Add mq extension
r1808 patch = q.series[-1]
if opts['merge']:
if opts['name']:
newpath = opts['name']
else:
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 newpath, i = lastsavename(q.path)
mason@suse.com
Add mq extension
r1808 if not newpath:
ui.warn("no saved queues found, please use -n\n")
return 1
mergeq = queue(ui, repo.join(""), newpath)
ui.warn("merging with queue at: %s\n" % mergeq.path)
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 ret = q.push(repo, patch, force=opts['force'], list=opts['list'],
mason@suse.com
Add mq extension
r1808 mergeq=mergeq)
q.save_dirty()
return ret
def pop(ui, repo, patch=None, **opts):
"""pop the current patch off the stack"""
localupdate = True
if opts['name']:
q = queue(ui, repo.join(""), repo.join(opts['name']))
ui.warn('using patch queue: %s\n' % q.path)
localupdate = False
else:
Brendan Cully
mq: replace module-wide repo hash with a repo attribute
r2724 q = repo.mq
Chris Mason
mq: qpop should act like quilt pop...
r2697 q.pop(repo, patch, force=opts['force'], update=localupdate, all=opts['all'])
mason@suse.com
Add mq extension
r1808 q.save_dirty()
return 0
Brendan Cully
New self-explanatory command qrename.
r2750 def rename(ui, repo, patch, name=None, **opts):
"""rename a patch
With one argument, renames the current patch to PATCH1.
With two arguments, renames PATCH1 to PATCH2."""
q = repo.mq
if not name:
name = patch
patch = None
if patch:
patch = q.lookup(patch)
else:
if not q.applied:
ui.write(_('No patches applied\n'))
return
patch = q.lookup('qtip')
Brendan Cully
Make qrename handle directory targets; closes #333.
r3083 absdest = q.join(name)
if os.path.isdir(absdest):
name = os.path.join(name, os.path.basename(patch))
absdest = q.join(name)
if os.path.exists(absdest):
raise util.Abort(_('%s already exists') % absdest)
Thomas Arendsen Hein
Whitespace/Tab cleanup
r3223
Brendan Cully
Make qrename handle directory targets; closes #333.
r3083 if name in q.series:
raise util.Abort(_('A patch named %s already exists in the series file') % name)
Brendan Cully
New self-explanatory command qrename.
r2750
if ui.verbose:
ui.write('Renaming %s to %s\n' % (patch, name))
i = q.find_series(patch)
Mathieu Clabaut
Issue424: mq patch loses guard when qrenamed
r3685 guards = q.guard_re.findall(q.full_series[i])
q.full_series[i] = name + ''.join([' #' + g for g in guards])
Vadim Gelfer
mq: rename read_series as parse_series, make simpler and faster
r2767 q.parse_series()
Brendan Cully
New self-explanatory command qrename.
r2750 q.series_dirty = 1
info = q.isapplied(patch)
if info:
Brendan Cully
Make mq camelcase consistent with the rest of hg.
r2818 q.applied[info[0]] = statusentry(info[1], name)
Brendan Cully
New self-explanatory command qrename.
r2750 q.applied_dirty = 1
Vadim Gelfer
mq: add join method
r2819 util.rename(q.join(patch), absdest)
Brendan Cully
New self-explanatory command qrename.
r2750 r = q.qrepo()
if r:
wlock = r.wlock()
if r.dirstate.state(name) == 'r':
r.undelete([name], wlock)
r.copy(patch, name, wlock)
r.remove([patch], False, wlock)
q.save_dirty()
mason@suse.com
Add mq extension
r1808 def restore(ui, repo, rev, **opts):
"""restore the queue state saved by a rev"""
rev = repo.lookup(rev)
Brendan Cully
mq: replace module-wide repo hash with a repo attribute
r2724 q = repo.mq
mason@suse.com
Add mq extension
r1808 q.restore(repo, rev, delete=opts['delete'],
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 qupdate=opts['update'])
mason@suse.com
Add mq extension
r1808 q.save_dirty()
return 0
def save(ui, repo, **opts):
"""save current queue state"""
Brendan Cully
mq: replace module-wide repo hash with a repo attribute
r2724 q = repo.mq
Brendan Cully
Update mq to use new logmessage arglist from 2794:bd8a9a94139f
r2804 message = commands.logmessage(opts)
"Mathieu Clabaut "
MQ: uniformise message and logfile option....
r2694 ret = q.save(repo, msg=message)
mason@suse.com
Add mq extension
r1808 if ret:
return ret
q.save_dirty()
if opts['copy']:
path = q.path
if opts['name']:
newpath = os.path.join(q.basepath, opts['name'])
if os.path.exists(newpath):
if not os.path.isdir(newpath):
Vadim Gelfer
mq: move many error messages to util.Abort
r2712 raise util.Abort(_('destination %s exists and is not '
'a directory') % newpath)
mason@suse.com
Add mq extension
r1808 if not opts['force']:
Vadim Gelfer
mq: move many error messages to util.Abort
r2712 raise util.Abort(_('destination %s exists, '
'use -f to force') % newpath)
mason@suse.com
Add mq extension
r1808 else:
newpath = savename(path)
ui.warn("copy %s to %s\n" % (path, newpath))
util.copyfiles(path, newpath)
if opts['empty']:
try:
Vadim Gelfer
mq: add join method
r2819 os.unlink(q.join(q.status_path))
mason@suse.com
Add mq extension
r1808 except:
pass
return 0
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810
mason@suse.com
Add mq extension
r1808 def strip(ui, repo, rev, **opts):
"""strip a revision and all later revs on the same branch"""
rev = repo.lookup(rev)
backup = 'all'
if opts['backup']:
backup = 'strip'
elif opts['nobackup']:
backup = 'none'
Brendan Cully
mq: do not update an empty working directory after strip....
r3087 update = repo.dirstate.parents()[0] != revlog.nullid
repo.mq.strip(repo, rev, backup=backup, update=update)
mason@suse.com
Add mq extension
r1808 return 0
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 def select(ui, repo, *args, **opts):
'''set or print guarded patches to push
Brendan Cully
mq help text updates and speling fixes
r2940 Use the qguard command to set or print guards on patch, then use
qselect to tell mq which guards to use. A patch will be pushed if it
has no guards or any positive guards match the currently selected guard,
but will not be pushed if any negative guards match the current guard.
For example:
Vadim Gelfer
mq: new commands qselect, qguard...
r2821
Brendan Cully
mq help text updates and speling fixes
r2940 qguard foo.patch -stable (negative guard)
qguard bar.patch +stable (positive guard)
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 qselect stable
Brendan Cully
mq help text updates and speling fixes
r2940 This activates the "stable" guard. mq will skip foo.patch (because
it has a negative match) but push bar.patch (because it
has a positive match).
Vadim Gelfer
mq: new commands qselect, qguard...
r2821
Brendan Cully
mq help text updates and speling fixes
r2940 With no arguments, prints the currently active guards.
With one argument, sets the active guard.
Thomas Arendsen Hein
Whitespace/Tab cleanup
r3223
Brendan Cully
mq help text updates and speling fixes
r2940 Use -n/--none to deactivate guards (no other arguments needed).
When no guards are active, patches with positive guards are skipped
and patches with negative guards are pushed.
Vadim Gelfer
mq: new commands qselect, qguard...
r2821
Brendan Cully
mq help text updates and speling fixes
r2940 qselect can change the guards on applied patches. It does not pop
guarded patches by default. Use --pop to pop back to the last applied
patch that is not guarded. Use --reapply (which implies --pop) to push
back to the current patch afterwards, but skip guarded patches.
Vadim Gelfer
qselect: add --pop, --reapply options
r2844
Brendan Cully
mq help text updates and speling fixes
r2940 Use -s/--series to print a list of all guards in the series file (no
other arguments needed). Use -v for more information.'''
Vadim Gelfer
mq: new commands qselect, qguard...
r2821
q = repo.mq
guards = q.active()
if args or opts['none']:
Vadim Gelfer
qselect: add --pop, --reapply options
r2844 old_unapplied = q.unapplied(repo)
old_guarded = [i for i in xrange(len(q.applied)) if
not q.pushable(i)[0]]
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 q.set_active(args)
q.save_dirty()
if not args:
ui.status(_('guards deactivated\n'))
Vadim Gelfer
qselect: add --pop, --reapply options
r2844 if not opts['pop'] and not opts['reapply']:
unapplied = q.unapplied(repo)
guarded = [i for i in xrange(len(q.applied))
if not q.pushable(i)[0]]
if len(unapplied) != len(old_unapplied):
ui.status(_('number of unguarded, unapplied patches has '
'changed from %d to %d\n') %
(len(old_unapplied), len(unapplied)))
if len(guarded) != len(old_guarded):
ui.status(_('number of guarded, applied patches has changed '
'from %d to %d\n') %
(len(old_guarded), len(guarded)))
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 elif opts['series']:
guards = {}
noguards = 0
for gs in q.series_guards:
if not gs:
noguards += 1
for g in gs:
guards.setdefault(g, 0)
guards[g] += 1
if ui.verbose:
guards['NONE'] = noguards
guards = guards.items()
guards.sort(lambda a, b: cmp(a[0][1:], b[0][1:]))
if guards:
ui.note(_('guards in series file:\n'))
for guard, count in guards:
ui.note('%2d ' % count)
ui.write(guard, '\n')
else:
ui.note(_('no guards in series file\n'))
else:
if guards:
ui.note(_('active guards:\n'))
for g in guards:
ui.write(g, '\n')
else:
ui.write(_('no active guards\n'))
Vadim Gelfer
qselect: add --pop, --reapply options
r2844 reapply = opts['reapply'] and q.applied and q.appliedname(-1)
popped = False
if opts['pop'] or opts['reapply']:
for i in xrange(len(q.applied)):
pushable, reason = q.pushable(i)
if not pushable:
ui.status(_('popping guarded patches\n'))
popped = True
if i == 0:
q.pop(repo, all=True)
else:
q.pop(repo, i-1)
break
if popped:
try:
if reapply:
ui.status(_('reapplying unguarded patches\n'))
q.push(repo, reapply)
finally:
q.save_dirty()
Vadim Gelfer
mq: new commands qselect, qguard...
r2821
mason@suse.com
Add mq extension
r1808 def reposetup(ui, repo):
Brendan Cully
Make mq camelcase consistent with the rest of hg.
r2818 class mqrepo(repo.__class__):
Vadim Gelfer
mq: do not allow to push from repo with patches applied
r2848 def abort_if_wdir_patched(self, errmsg, force=False):
if self.mq.applied and not force:
parent = revlog.hex(self.dirstate.parents()[0])
if parent in [s.rev for s in self.mq.applied]:
raise util.Abort(errmsg)
Thomas Arendsen Hein
Whitespace/Tab cleanup
r3223
Brendan Cully
Disallow commit over an applied mq patch.
r2845 def commit(self, *args, **opts):
if len(args) >= 6:
force = args[5]
else:
force = opts.get('force')
Vadim Gelfer
mq: do not allow to push from repo with patches applied
r2848 self.abort_if_wdir_patched(
_('cannot commit over an applied mq patch'),
force)
Brendan Cully
Disallow commit over an applied mq patch.
r2845
return super(mqrepo, self).commit(*args, **opts)
Vadim Gelfer
mq: do not allow to push from repo with patches applied
r2848 def push(self, remote, force=False, revs=None):
if self.mq.applied and not force:
raise util.Abort(_('source has mq patches applied'))
return super(mqrepo, self).push(remote, force, revs)
Thomas Arendsen Hein
Whitespace/Tab cleanup
r3223
Brendan Cully
mq: do not hold a reference to repo in tags override...
r2723 def tags(self):
if self.tagscache:
return self.tagscache
Brendan Cully
Make mq camelcase consistent with the rest of hg.
r2818 tagscache = super(mqrepo, self).tags()
Brendan Cully
Add mq patch names to tagscache instead of overriding lookup....
r2682
Brendan Cully
mq: replace module-wide repo hash with a repo attribute
r2724 q = self.mq
Brendan Cully
mq: do not hold a reference to repo in tags override...
r2723 if not q.applied:
return tagscache
Brendan Cully
Mq: modify repo.lookup to resolve applied patches too.
r2663
Brendan Cully
Use StatusEntry class instead of repeated status line parsing....
r2780 mqtags = [(patch.rev, patch.name) for patch in q.applied]
Brendan Cully
mq: do not hold a reference to repo in tags override...
r2723 mqtags.append((mqtags[-1][0], 'qtip'))
mqtags.append((mqtags[0][0], 'qbase'))
for patch in mqtags:
if patch[1] in tagscache:
self.ui.warn('Tag %s overrides mq patch of the same name\n' % patch[1])
else:
tagscache[patch[1]] = revlog.bin(patch[0])
Brendan Cully
Add mq patch names to tagscache instead of overriding lookup....
r2682
return tagscache
Brendan Cully
Add qtip and qbase to mq qlookup.
r2664
Alexis S. L. Carvalho
fix encoding conversion of branch names when mq is loaded
r3826 def _branchtags(self):
Alexis S. L. Carvalho
make mq play nicely with the branch cache...
r3492 q = self.mq
if not q.applied:
Alexis S. L. Carvalho
fix encoding conversion of branch names when mq is loaded
r3826 return super(mqrepo, self)._branchtags()
Alexis S. L. Carvalho
make mq play nicely with the branch cache...
r3492
self.branchcache = {} # avoid recursion in changectx
cl = self.changelog
partial, last, lrev = self._readbranchcache()
qbase = cl.rev(revlog.bin(q.applied[0].rev))
start = lrev + 1
if start < qbase:
# update the cache (excluding the patches) and save it
self._updatebranchcache(partial, lrev+1, qbase)
self._writebranchcache(partial, cl.node(qbase-1), qbase-1)
start = qbase
# if start = qbase, the cache is as updated as it should be.
# if start > qbase, the cache includes (part of) the patches.
# we might as well use it, but we won't save it.
# update the cache up to the tip
self._updatebranchcache(partial, start, cl.count())
Alexis S. L. Carvalho
fix encoding conversion of branch names when mq is loaded
r3826 return partial
Alexis S. L. Carvalho
make mq play nicely with the branch cache...
r3492
Vadim Gelfer
mq: only add mq attribute to local repo
r2851 if repo.local():
repo.__class__ = mqrepo
repo.mq = queue(ui, repo.join(""))
mason@suse.com
Add mq extension
r1808
Brendan Cully
mq: add --summary to qapplied, qunapplied, qtop, qnext and qprev...
r3183 seriesopts = [('s', 'summary', None, _('print first line of patch header'))]
mason@suse.com
Add mq extension
r1808 cmdtable = {
Brendan Cully
mq: add --summary to qapplied, qunapplied, qtop, qnext and qprev...
r3183 "qapplied": (applied, [] + seriesopts, 'hg qapplied [-s] [PATCH]'),
Vadim Gelfer
mq: add qclone command
r2720 "qclone": (clone,
[('', 'pull', None, _('use pull protocol to copy metadata')),
('U', 'noupdate', None, _('do not update the new working directories')),
('', 'uncompressed', None,
_('use uncompressed transfer (fast over LAN)')),
('e', 'ssh', '', _('specify ssh command to use')),
('p', 'patches', '', _('location of source patch repo')),
('', 'remotecmd', '',
_('specify hg command to run on the remote side'))],
'hg qclone [OPTION]... SOURCE [DEST]'),
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 "qcommit|qci":
(commit,
Thomas Arendsen Hein
Better help for mq: Corrected synopses, get qcommit options from commands.py.
r2185 commands.table["^commit|ci"][1],
'hg qcommit [OPTION]... [FILE]...'),
Brendan Cully
Fix test-mq-qdiff; add -I and -X options to qdiff
r2937 "^qdiff": (diff,
Alexis S. L. Carvalho
add --git option to qdiff
r3697 [('g', 'git', None, _('use git extended diff format')),
('I', 'include', [], _('include names matching the given patterns')),
Brendan Cully
Fix test-mq-qdiff; add -I and -X options to qdiff
r2937 ('X', 'exclude', [], _('exclude names matching the given patterns'))],
'hg qdiff [-I] [-X] [FILE]...'),
Brendan Cully
Replace qdel/qfold -f option with -k/--keep.
r2904 "qdelete|qremove|qrm":
Brendan Cully
Add -f option to qdelete, to remove patch file.
r2752 (delete,
Brendan Cully
mq: change qdel --forget to --rev; accept any revision symbol
r3373 [('k', 'keep', None, _('keep patch file')),
('r', 'rev', [], _('stop managing a revision'))],
'hg qdelete [-k] [-r REV]... PATCH...'),
Brendan Cully
Add -m, -l, -e options to qfold.
r2753 'qfold':
(fold,
[('e', 'edit', None, _('edit patch header')),
Mathieu Clabaut
Uniformisation of commit help for -m and -l....
r3857 ('k', 'keep', None, _('keep folded patch files'))
] + commands.commitopts,
Brendan Cully
Add -m, -l, -e options to qfold.
r2753 'hg qfold [-e] [-m <text>] [-l <file] PATCH...'),
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 'qguard': (guard, [('l', 'list', None, _('list all patches and guards')),
('n', 'none', None, _('drop all guards'))],
'hg qguard [PATCH] [+GUARD...] [-GUARD...]'),
Brendan Cully
Add command qheader to display the header of a given patch.
r2747 'qheader': (header, [],
_('hg qheader [PATCH]')),
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 "^qimport":
(qimport,
[('e', 'existing', None, 'import file in patch dir'),
('n', 'name', '', 'patch file name'),
Brendan Cully
mq: Add --rev argument to qimport, to adopt existing changesets.
r3141 ('f', 'force', None, 'overwrite existing files'),
Brendan Cully
mq: add --git option to qimport -r
r3691 ('r', 'rev', [], 'place existing revisions under mq control'),
('g', 'git', None, _('use git extended diff format'))],
'hg qimport [-e] [-n NAME] [-f] [-g] [-r REV]... FILE...'),
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 "^qinit":
(init,
Thomas Arendsen Hein
mq: Added help for qcommit, consistently talk about queue repository.
r2526 [('c', 'create-repo', None, 'create queue repository')],
Thomas Arendsen Hein
Better help for mq: Corrected synopses, get qcommit options from commands.py.
r2185 'hg qinit [-c]'),
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 "qnew":
(new,
Brendan Cully
Add qnew -e option.
r2939 [('e', 'edit', None, _('edit commit message')),
Mathieu Clabaut
Uniformisation of commit help for -m and -l....
r3857 ('f', 'force', None, _('import uncommitted changes into patch'))
] + commands.commitopts,
Brendan Cully
Add qnew -e option.
r2939 'hg qnew [-e] [-m TEXT] [-l FILE] [-f] PATCH'),
Brendan Cully
mq: add --summary to qapplied, qunapplied, qtop, qnext and qprev...
r3183 "qnext": (next, [] + seriesopts, 'hg qnext [-s]'),
"qprev": (prev, [] + seriesopts, 'hg qprev [-s]'),
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 "^qpop":
(pop,
[('a', 'all', None, 'pop all patches'),
('n', 'name', '', 'queue name to pop'),
('f', 'force', None, 'forget any local changes')],
Thomas Arendsen Hein
Better help for mq: Corrected synopses, get qcommit options from commands.py.
r2185 'hg qpop [-a] [-n NAME] [-f] [PATCH | INDEX]'),
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 "^qpush":
(push,
[('f', 'force', None, 'apply if the patch has rejects'),
('l', 'list', None, 'list patch name in commit text'),
('a', 'all', None, 'apply all patches'),
('m', 'merge', None, 'merge from another queue'),
('n', 'name', '', 'merge queue name')],
Thomas Arendsen Hein
Better help for mq: Corrected synopses, get qcommit options from commands.py.
r2185 'hg qpush [-f] [-l] [-a] [-m] [-n NAME] [PATCH | INDEX]'),
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 "^qrefresh":
(refresh,
Brendan Cully
Add option -e/--edit to qrefresh, to edit the existing header.
r2746 [('e', 'edit', None, _('edit commit message')),
Brendan Cully
mq: Add --git option to qrefresh
r3086 ('g', 'git', None, _('use git extended diff format')),
Mathieu Clabaut
Make qrefresh help more explanatory for options -m, -l and -s
r3690 ('s', 'short', None, 'refresh only files already in the patch'),
Brendan Cully
allow qrefresh to take a list of files; closes #96.
r2938 ('I', 'include', [], _('include names matching the given patterns')),
Mathieu Clabaut
Uniformisation of commit help for -m and -l....
r3857 ('X', 'exclude', [], _('exclude names matching the given patterns'))
] + commands.commitopts,
Brendan Cully
allow qrefresh to take a list of files; closes #96.
r2938 'hg qrefresh [-I] [-X] [-e] [-m TEXT] [-l FILE] [-s] FILES...'),
Vadim Gelfer
mq: add qmv as alias for qrename
r2751 'qrename|qmv':
Brendan Cully
New self-explanatory command qrename.
r2750 (rename, [], 'hg qrename PATCH1 [PATCH2]'),
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 "qrestore":
(restore,
[('d', 'delete', None, 'delete save entry'),
('u', 'update', None, 'update queue working dir')],
Thomas Arendsen Hein
Better help for mq: Corrected synopses, get qcommit options from commands.py.
r2185 'hg qrestore [-d] [-u] REV'),
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 "qsave":
(save,
Mathieu Clabaut
Uniformisation of commit help for -m and -l....
r3857 [('c', 'copy', None, 'copy patch directory'),
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 ('n', 'name', '', 'copy directory name'),
('e', 'empty', None, 'clear queue status file'),
Mathieu Clabaut
Uniformisation of commit help for -m and -l....
r3857 ('f', 'force', None, 'force copy')] + commands.commitopts,
"Mathieu Clabaut "
MQ: uniformise message and logfile option....
r2694 'hg qsave [-m TEXT] [-l FILE] [-c] [-n NAME] [-e] [-f]'),
Vadim Gelfer
mq: new commands qselect, qguard...
r2821 "qselect": (select,
[('n', 'none', None, _('disable all guards')),
Vadim Gelfer
qselect: add --pop, --reapply options
r2844 ('s', 'series', None, _('list all guards in series file')),
('', 'pop', None,
_('pop to before first guarded applied patch')),
('', 'reapply', None, _('pop, then reapply patches'))],
'hg qselect [OPTION...] [GUARD...]'),
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 "qseries":
(series,
Brendan Cully
mq: add --summary to qapplied, qunapplied, qtop, qnext and qprev...
r3183 [('m', 'missing', None, 'print patches not in series')] + seriesopts,
john.levon@sun.com
Add the -s option to `hg help qseries`.
r3085 'hg qseries [-ms]'),
Thomas Arendsen Hein
Whitespace, tab and formatting cleanups, mainly in mq.py
r1810 "^strip":
(strip,
[('f', 'force', None, 'force multi-head removal'),
('b', 'backup', None, 'bundle unrelated changesets'),
('n', 'nobackup', None, 'no backups')],
Thomas Arendsen Hein
Better help for mq: Corrected synopses, get qcommit options from commands.py.
r2185 'hg strip [-f] [-b] [-n] REV'),
Brendan Cully
mq: add --summary to qapplied, qunapplied, qtop, qnext and qprev...
r3183 "qtop": (top, [] + seriesopts, 'hg qtop [-s]'),
"qunapplied": (unapplied, [] + seriesopts, 'hg qunapplied [-s] [PATCH]'),
mason@suse.com
Add mq extension
r1808 }