comparison hgext/mq.py @ 13033:026053f691a4

mq: add an '-e/--exact' option to qpush This patch adds an '--exact/-e' option to qpush that will try to push the patches in the correct location in the DAG. Specifying this option does the following: * If --move is specified, abort. It makes no sense to move a patch to the front of the queue and try to apply it to its parent, because its parent is one of the patches we just moved it in front of! * If patches are already applied, abort. We don't want patch changesets scattered throughout the DAG. * If local changes are present, abort unless --force is used, as usual. * Find the first patch we're going to push (if we're pushing multiple patches with a target or --all). * If that patch doesn't have a parent, abort, obviously. * If the parent doesn't exist in the repo, abort. Something is wrong. * Update to the parent, then continue pushing the patches as normal.
author Steve Losh <steve@stevelosh.com>
date Wed, 17 Nov 2010 21:18:44 -0500
parents 3da456d0c885
children 77aa74fe0e0b
comparison
equal deleted inserted replaced
13032:e41e2b79883d 13033:026053f691a4
1004 if i + off < len(self.series): 1004 if i + off < len(self.series):
1005 return self.series[i + off] 1005 return self.series[i + off]
1006 raise util.Abort(_("patch %s not in series") % patch) 1006 raise util.Abort(_("patch %s not in series") % patch)
1007 1007
1008 def push(self, repo, patch=None, force=False, list=False, 1008 def push(self, repo, patch=None, force=False, list=False,
1009 mergeq=None, all=False, move=False): 1009 mergeq=None, all=False, move=False, exact=False):
1010 diffopts = self.diffopts() 1010 diffopts = self.diffopts()
1011 wlock = repo.wlock() 1011 wlock = repo.wlock()
1012 try: 1012 try:
1013 heads = [] 1013 heads = []
1014 for b, ls in repo.branchmap().iteritems(): 1014 for b, ls in repo.branchmap().iteritems():
1015 heads += ls 1015 heads += ls
1016 if not heads: 1016 if not heads:
1017 heads = [nullid] 1017 heads = [nullid]
1018 if repo.dirstate.parents()[0] not in heads: 1018 if repo.dirstate.parents()[0] not in heads and not exact:
1019 self.ui.status(_("(working directory not at a head)\n")) 1019 self.ui.status(_("(working directory not at a head)\n"))
1020 1020
1021 if not self.series: 1021 if not self.series:
1022 self.ui.warn(_('no patches in series\n')) 1022 self.ui.warn(_('no patches in series\n'))
1023 return 0 1023 return 0
1059 if start == len(self.series): 1059 if start == len(self.series):
1060 self.ui.warn(_('patch series already fully applied\n')) 1060 self.ui.warn(_('patch series already fully applied\n'))
1061 return 1 1061 return 1
1062 if not force: 1062 if not force:
1063 self.check_localchanges(repo) 1063 self.check_localchanges(repo)
1064
1065 if exact:
1066 if move:
1067 raise util.Abort(_("cannot use --exact and --move together"))
1068 if self.applied:
1069 raise util.Abort(_("cannot push --exact with applied patches"))
1070 root = self.series[start]
1071 target = patchheader(self.join(root), self.plainmode).parent
1072 if not target:
1073 raise util.Abort(_("%s does not have a parent recorded" % root))
1074 if not repo[target] == repo['.']:
1075 hg.update(repo, target)
1064 1076
1065 if move: 1077 if move:
1066 if not patch: 1078 if not patch:
1067 raise util.Abort(_("please specify the patch to move")) 1079 raise util.Abort(_("please specify the patch to move"))
1068 for i, rpn in enumerate(self.full_series[start:]): 1080 for i, rpn in enumerate(self.full_series[start:]):
2336 ui.warn(_("no saved queues found, please use -n\n")) 2348 ui.warn(_("no saved queues found, please use -n\n"))
2337 return 1 2349 return 1
2338 mergeq = queue(ui, repo.join(""), newpath) 2350 mergeq = queue(ui, repo.join(""), newpath)
2339 ui.warn(_("merging with queue at: %s\n") % mergeq.path) 2351 ui.warn(_("merging with queue at: %s\n") % mergeq.path)
2340 ret = q.push(repo, patch, force=opts.get('force'), list=opts.get('list'), 2352 ret = q.push(repo, patch, force=opts.get('force'), list=opts.get('list'),
2341 mergeq=mergeq, all=opts.get('all'), move=opts.get('move')) 2353 mergeq=mergeq, all=opts.get('all'), move=opts.get('move'),
2354 exact=opts.get('exact'))
2342 return ret 2355 return ret
2343 2356
2344 def pop(ui, repo, patch=None, **opts): 2357 def pop(ui, repo, patch=None, **opts):
2345 """pop the current patch off the stack 2358 """pop the current patch off the stack
2346 2359
3112 ('f', 'force', None, _('forget any local changes to patched files'))], 3125 ('f', 'force', None, _('forget any local changes to patched files'))],
3113 _('hg qpop [-a] [-f] [PATCH | INDEX]')), 3126 _('hg qpop [-a] [-f] [PATCH | INDEX]')),
3114 "^qpush": 3127 "^qpush":
3115 (push, 3128 (push,
3116 [('f', 'force', None, _('apply on top of local changes')), 3129 [('f', 'force', None, _('apply on top of local changes')),
3130 ('e', 'exact', None, _('apply the target patch to its recorded parent')),
3117 ('l', 'list', None, _('list patch name in commit text')), 3131 ('l', 'list', None, _('list patch name in commit text')),
3118 ('a', 'all', None, _('apply all patches')), 3132 ('a', 'all', None, _('apply all patches')),
3119 ('m', 'merge', None, _('merge from another queue (DEPRECATED)')), 3133 ('m', 'merge', None, _('merge from another queue (DEPRECATED)')),
3120 ('n', 'name', '', 3134 ('n', 'name', '',
3121 _('merge queue name (DEPRECATED)'), _('NAME')), 3135 _('merge queue name (DEPRECATED)'), _('NAME')),