Show More
@@ -280,6 +280,9 b' def newcommit(repo, phase, *args, **kwar' | |||||
280 | if phase is not None: |
|
280 | if phase is not None: | |
281 | repo.ui.restoreconfig(backup) |
|
281 | repo.ui.restoreconfig(backup) | |
282 |
|
282 | |||
|
283 | class AbortNoCleanup(error.Abort): | |||
|
284 | pass | |||
|
285 | ||||
283 | class queue(object): |
|
286 | class queue(object): | |
284 | def __init__(self, ui, path, patchdir=None): |
|
287 | def __init__(self, ui, path, patchdir=None): | |
285 | self.basepath = path |
|
288 | self.basepath = path | |
@@ -681,7 +684,7 b' class queue(object):' | |||||
681 |
|
684 | |||
682 | def apply(self, repo, series, list=False, update_status=True, |
|
685 | def apply(self, repo, series, list=False, update_status=True, | |
683 | strict=False, patchdir=None, merge=None, all_files=None, |
|
686 | strict=False, patchdir=None, merge=None, all_files=None, | |
684 | tobackup=None): |
|
687 | tobackup=None, check=False): | |
685 | wlock = lock = tr = None |
|
688 | wlock = lock = tr = None | |
686 | try: |
|
689 | try: | |
687 | wlock = repo.wlock() |
|
690 | wlock = repo.wlock() | |
@@ -690,10 +693,14 b' class queue(object):' | |||||
690 | try: |
|
693 | try: | |
691 | ret = self._apply(repo, series, list, update_status, |
|
694 | ret = self._apply(repo, series, list, update_status, | |
692 | strict, patchdir, merge, all_files=all_files, |
|
695 | strict, patchdir, merge, all_files=all_files, | |
693 | tobackup=tobackup) |
|
696 | tobackup=tobackup, check=check) | |
694 | tr.close() |
|
697 | tr.close() | |
695 | self.savedirty() |
|
698 | self.savedirty() | |
696 | return ret |
|
699 | return ret | |
|
700 | except AbortNoCleanup: | |||
|
701 | tr.close() | |||
|
702 | self.savedirty() | |||
|
703 | return 2, repo.dirstate.p1() | |||
697 | except: |
|
704 | except: | |
698 | try: |
|
705 | try: | |
699 | tr.abort() |
|
706 | tr.abort() | |
@@ -708,7 +715,7 b' class queue(object):' | |||||
708 |
|
715 | |||
709 | def _apply(self, repo, series, list=False, update_status=True, |
|
716 | def _apply(self, repo, series, list=False, update_status=True, | |
710 | strict=False, patchdir=None, merge=None, all_files=None, |
|
717 | strict=False, patchdir=None, merge=None, all_files=None, | |
711 | tobackup=None): |
|
718 | tobackup=None, check=False): | |
712 | """returns (error, hash) |
|
719 | """returns (error, hash) | |
713 |
|
720 | |||
714 | error = 1 for unable to read, 2 for patch failed, 3 for patch |
|
721 | error = 1 for unable to read, 2 for patch failed, 3 for patch | |
@@ -749,6 +756,9 b' class queue(object):' | |||||
749 | if tobackup: |
|
756 | if tobackup: | |
750 | touched = patchmod.changedfiles(self.ui, repo, pf) |
|
757 | touched = patchmod.changedfiles(self.ui, repo, pf) | |
751 | touched = set(touched) & tobackup |
|
758 | touched = set(touched) & tobackup | |
|
759 | if touched and check: | |||
|
760 | raise AbortNoCleanup( | |||
|
761 | _("local changes found, refresh first")) | |||
752 | self.backup(repo, touched, copy=True) |
|
762 | self.backup(repo, touched, copy=True) | |
753 | tobackup = tobackup - touched |
|
763 | tobackup = tobackup - touched | |
754 | (patcherr, files, fuzz) = self.patch(repo, pf) |
|
764 | (patcherr, files, fuzz) = self.patch(repo, pf) | |
@@ -959,6 +969,10 b' class queue(object):' | |||||
959 | else: |
|
969 | else: | |
960 | raise util.Abort(_('patch "%s" already exists') % name) |
|
970 | raise util.Abort(_('patch "%s" already exists') % name) | |
961 |
|
971 | |||
|
972 | def checkforcecheck(self, check, force): | |||
|
973 | if force and check: | |||
|
974 | raise util.Abort(_('cannot use both --force and --check')) | |||
|
975 | ||||
962 | def new(self, repo, patchfn, *pats, **opts): |
|
976 | def new(self, repo, patchfn, *pats, **opts): | |
963 | """options: |
|
977 | """options: | |
964 | msg: a string or a no-argument function returning a string |
|
978 | msg: a string or a no-argument function returning a string | |
@@ -1156,8 +1170,9 b' class queue(object):' | |||||
1156 | return self.series[i + off] |
|
1170 | return self.series[i + off] | |
1157 | raise util.Abort(_("patch %s not in series") % patch) |
|
1171 | raise util.Abort(_("patch %s not in series") % patch) | |
1158 |
|
1172 | |||
1159 | def push(self, repo, patch=None, force=False, list=False, |
|
1173 | def push(self, repo, patch=None, force=False, list=False, mergeq=None, | |
1160 |
|
|
1174 | all=False, move=False, exact=False, nobackup=False, check=False): | |
|
1175 | self.checkforcecheck(check, force) | |||
1161 | diffopts = self.diffopts() |
|
1176 | diffopts = self.diffopts() | |
1162 | wlock = repo.wlock() |
|
1177 | wlock = repo.wlock() | |
1163 | try: |
|
1178 | try: | |
@@ -1212,10 +1227,13 b' class queue(object):' | |||||
1212 | if start == len(self.series): |
|
1227 | if start == len(self.series): | |
1213 | self.ui.warn(_('patch series already fully applied\n')) |
|
1228 | self.ui.warn(_('patch series already fully applied\n')) | |
1214 | return 1 |
|
1229 | return 1 | |
1215 | if not force: |
|
1230 | if not force and not check: | |
1216 | self.checklocalchanges(repo, refresh=self.applied) |
|
1231 | self.checklocalchanges(repo, refresh=self.applied) | |
1217 |
|
1232 | |||
1218 | if exact: |
|
1233 | if exact: | |
|
1234 | if check: | |||
|
1235 | raise util.Abort( | |||
|
1236 | _("cannot use --exact and --check together")) | |||
1219 | if move: |
|
1237 | if move: | |
1220 | raise util.Abort(_("cannot use --exact and --move together")) |
|
1238 | raise util.Abort(_("cannot use --exact and --move together")) | |
1221 | if self.applied: |
|
1239 | if self.applied: | |
@@ -1257,8 +1275,11 b' class queue(object):' | |||||
1257 | end = self.series.index(patch, start) + 1 |
|
1275 | end = self.series.index(patch, start) + 1 | |
1258 |
|
1276 | |||
1259 | tobackup = set() |
|
1277 | tobackup = set() | |
1260 | if not nobackup and force: |
|
1278 | if (not nobackup and force) or check: | |
1261 | m, a, r, d = self.checklocalchanges(repo, force=True) |
|
1279 | m, a, r, d = self.checklocalchanges(repo, force=True) | |
|
1280 | if check: | |||
|
1281 | tobackup.update(m + a + r + d) | |||
|
1282 | else: | |||
1262 | tobackup.update(m + a) |
|
1283 | tobackup.update(m + a) | |
1263 |
|
1284 | |||
1264 | s = self.series[start:end] |
|
1285 | s = self.series[start:end] | |
@@ -1268,7 +1289,7 b' class queue(object):' | |||||
1268 | ret = self.mergepatch(repo, mergeq, s, diffopts) |
|
1289 | ret = self.mergepatch(repo, mergeq, s, diffopts) | |
1269 | else: |
|
1290 | else: | |
1270 | ret = self.apply(repo, s, list, all_files=all_files, |
|
1291 | ret = self.apply(repo, s, list, all_files=all_files, | |
1271 | tobackup=tobackup) |
|
1292 | tobackup=tobackup, check=check) | |
1272 | except: |
|
1293 | except: | |
1273 | self.ui.warn(_('cleaning up working directory...')) |
|
1294 | self.ui.warn(_('cleaning up working directory...')) | |
1274 | node = repo.dirstate.p1() |
|
1295 | node = repo.dirstate.p1() | |
@@ -1300,8 +1321,7 b' class queue(object):' | |||||
1300 |
|
1321 | |||
1301 | def pop(self, repo, patch=None, force=False, update=True, all=False, |
|
1322 | def pop(self, repo, patch=None, force=False, update=True, all=False, | |
1302 | nobackup=False, check=False): |
|
1323 | nobackup=False, check=False): | |
1303 | if force and check: |
|
1324 | self.checkforcecheck(check, force) | |
1304 | raise util.Abort(_('cannot use both --force and --check')) |
|
|||
1305 | wlock = repo.wlock() |
|
1325 | wlock = repo.wlock() | |
1306 | try: |
|
1326 | try: | |
1307 | if patch: |
|
1327 | if patch: | |
@@ -2638,7 +2658,8 b' def savename(path):' | |||||
2638 | return newpath |
|
2658 | return newpath | |
2639 |
|
2659 | |||
2640 | @command("^qpush", |
|
2660 | @command("^qpush", | |
2641 |
[(' |
|
2661 | [('c', 'check', None, _('tolerate non-conflicting local changes')), | |
|
2662 | ('f', 'force', None, _('apply on top of local changes')), | |||
2642 | ('e', 'exact', None, _('apply the target patch to its recorded parent')), |
|
2663 | ('e', 'exact', None, _('apply the target patch to its recorded parent')), | |
2643 | ('l', 'list', None, _('list patch name in commit text')), |
|
2664 | ('l', 'list', None, _('list patch name in commit text')), | |
2644 | ('a', 'all', None, _('apply all patches')), |
|
2665 | ('a', 'all', None, _('apply all patches')), | |
@@ -2652,8 +2673,10 b' def savename(path):' | |||||
2652 | def push(ui, repo, patch=None, **opts): |
|
2673 | def push(ui, repo, patch=None, **opts): | |
2653 | """push the next patch onto the stack |
|
2674 | """push the next patch onto the stack | |
2654 |
|
2675 | |||
2655 | When -f/--force is applied, all local changes in patched files |
|
2676 | By default, abort if the working directory contains uncommitted | |
2656 | will be lost. |
|
2677 | changes. With -c/--check, abort only if the uncommitted files | |
|
2678 | overlap with patched files. With -f/--force, backup and patch over | |||
|
2679 | uncommitted changes. | |||
2657 |
|
2680 | |||
2658 | Return 0 on success. |
|
2681 | Return 0 on success. | |
2659 | """ |
|
2682 | """ | |
@@ -2672,7 +2695,8 b' def push(ui, repo, patch=None, **opts):' | |||||
2672 | ui.warn(_("merging with queue at: %s\n") % mergeq.path) |
|
2695 | ui.warn(_("merging with queue at: %s\n") % mergeq.path) | |
2673 | ret = q.push(repo, patch, force=opts.get('force'), list=opts.get('list'), |
|
2696 | ret = q.push(repo, patch, force=opts.get('force'), list=opts.get('list'), | |
2674 | mergeq=mergeq, all=opts.get('all'), move=opts.get('move'), |
|
2697 | mergeq=mergeq, all=opts.get('all'), move=opts.get('move'), | |
2675 |
exact=opts.get('exact'), nobackup=opts.get('no_backup') |
|
2698 | exact=opts.get('exact'), nobackup=opts.get('no_backup'), | |
|
2699 | check=opts.get('check')) | |||
2676 | return ret |
|
2700 | return ret | |
2677 |
|
2701 | |||
2678 | @command("^qpop", |
|
2702 | @command("^qpop", |
@@ -317,3 +317,54 b' test qgoto --force --no-backup' | |||||
317 | now at: p2 |
|
317 | now at: p2 | |
318 | $ test -f a.orig && echo 'error: backup with --no-backup' |
|
318 | $ test -f a.orig && echo 'error: backup with --no-backup' | |
319 | [1] |
|
319 | [1] | |
|
320 | ||||
|
321 | test qpush --check | |||
|
322 | ||||
|
323 | $ hg qpush --check --force | |||
|
324 | abort: cannot use both --force and --check | |||
|
325 | [255] | |||
|
326 | $ hg qpush --check --exact | |||
|
327 | abort: cannot use --exact and --check together | |||
|
328 | [255] | |||
|
329 | $ echo b >> b | |||
|
330 | $ hg qpush --check | |||
|
331 | applying p3 | |||
|
332 | errors during apply, please fix and refresh p2 | |||
|
333 | [2] | |||
|
334 | $ rm b | |||
|
335 | $ hg qpush --check | |||
|
336 | applying p3 | |||
|
337 | errors during apply, please fix and refresh p2 | |||
|
338 | [2] | |||
|
339 | $ hg rm -A b | |||
|
340 | $ hg qpush --check | |||
|
341 | applying p3 | |||
|
342 | errors during apply, please fix and refresh p2 | |||
|
343 | [2] | |||
|
344 | $ hg revert -aq b | |||
|
345 | $ echo d > d | |||
|
346 | $ hg add d | |||
|
347 | $ hg qpush --check | |||
|
348 | applying p3 | |||
|
349 | errors during apply, please fix and refresh p2 | |||
|
350 | [2] | |||
|
351 | $ hg forget d | |||
|
352 | $ rm d | |||
|
353 | $ hg qpop | |||
|
354 | popping p2 | |||
|
355 | patch queue now empty | |||
|
356 | $ echo b >> b | |||
|
357 | $ hg qpush -a --check | |||
|
358 | applying p2 | |||
|
359 | applying p3 | |||
|
360 | errors during apply, please fix and refresh p2 | |||
|
361 | [2] | |||
|
362 | $ hg qtop | |||
|
363 | p2 | |||
|
364 | $ hg parents --template "{rev} {desc}\n" | |||
|
365 | 2 imported patch p2 | |||
|
366 | $ hg st b | |||
|
367 | M b | |||
|
368 | $ cat b | |||
|
369 | b | |||
|
370 | b |
General Comments 0
You need to be logged in to leave comments.
Login now