Show More
@@ -554,14 +554,17 b' class queue(object):' | |||||
554 | except OSError, inst: |
|
554 | except OSError, inst: | |
555 | self.ui.warn(_('error removing undo: %s\n') % str(inst)) |
|
555 | self.ui.warn(_('error removing undo: %s\n') % str(inst)) | |
556 |
|
556 | |||
557 | def backup(self, repo, files): |
|
557 | def backup(self, repo, files, copy=False): | |
558 | # backup local changes in --force case |
|
558 | # backup local changes in --force case | |
559 | for f in sorted(files): |
|
559 | for f in sorted(files): | |
560 | absf = repo.wjoin(f) |
|
560 | absf = repo.wjoin(f) | |
561 | if os.path.lexists(absf): |
|
561 | if os.path.lexists(absf): | |
562 | self.ui.note(_('saving current version of %s as %s\n') % |
|
562 | self.ui.note(_('saving current version of %s as %s\n') % | |
563 | (f, f + '.orig')) |
|
563 | (f, f + '.orig')) | |
564 | util.rename(absf, absf + '.orig') |
|
564 | if copy: | |
|
565 | util.copyfile(absf, absf + '.orig') | |||
|
566 | else: | |||
|
567 | util.rename(absf, absf + '.orig') | |||
565 |
|
568 | |||
566 | def printdiff(self, repo, diffopts, node1, node2=None, files=None, |
|
569 | def printdiff(self, repo, diffopts, node1, node2=None, files=None, | |
567 | fp=None, changes=None, opts={}): |
|
570 | fp=None, changes=None, opts={}): | |
@@ -677,7 +680,8 b' class queue(object):' | |||||
677 | return (False, list(files), False) |
|
680 | return (False, list(files), False) | |
678 |
|
681 | |||
679 | def apply(self, repo, series, list=False, update_status=True, |
|
682 | def apply(self, repo, series, list=False, update_status=True, | |
680 |
strict=False, patchdir=None, merge=None, all_files=None |
|
683 | strict=False, patchdir=None, merge=None, all_files=None, | |
|
684 | tobackup=None): | |||
681 | wlock = lock = tr = None |
|
685 | wlock = lock = tr = None | |
682 | try: |
|
686 | try: | |
683 | wlock = repo.wlock() |
|
687 | wlock = repo.wlock() | |
@@ -685,7 +689,8 b' class queue(object):' | |||||
685 | tr = repo.transaction("qpush") |
|
689 | tr = repo.transaction("qpush") | |
686 | try: |
|
690 | try: | |
687 | ret = self._apply(repo, series, list, update_status, |
|
691 | ret = self._apply(repo, series, list, update_status, | |
688 |
strict, patchdir, merge, all_files=all_files |
|
692 | strict, patchdir, merge, all_files=all_files, | |
|
693 | tobackup=tobackup) | |||
689 | tr.close() |
|
694 | tr.close() | |
690 | self.savedirty() |
|
695 | self.savedirty() | |
691 | return ret |
|
696 | return ret | |
@@ -702,9 +707,14 b' class queue(object):' | |||||
702 | self.removeundo(repo) |
|
707 | self.removeundo(repo) | |
703 |
|
708 | |||
704 | def _apply(self, repo, series, list=False, update_status=True, |
|
709 | def _apply(self, repo, series, list=False, update_status=True, | |
705 |
strict=False, patchdir=None, merge=None, all_files=None |
|
710 | strict=False, patchdir=None, merge=None, all_files=None, | |
706 | '''returns (error, hash) |
|
711 | tobackup=None): | |
707 | error = 1 for unable to read, 2 for patch failed, 3 for patch fuzz''' |
|
712 | """returns (error, hash) | |
|
713 | ||||
|
714 | error = 1 for unable to read, 2 for patch failed, 3 for patch | |||
|
715 | fuzz. tobackup is None or a set of files to backup before they | |||
|
716 | are modified by a patch. | |||
|
717 | """ | |||
708 | # TODO unify with commands.py |
|
718 | # TODO unify with commands.py | |
709 | if not patchdir: |
|
719 | if not patchdir: | |
710 | patchdir = self.path |
|
720 | patchdir = self.path | |
@@ -736,6 +746,11 b' class queue(object):' | |||||
736 | message = '\n'.join(message) |
|
746 | message = '\n'.join(message) | |
737 |
|
747 | |||
738 | if ph.haspatch: |
|
748 | if ph.haspatch: | |
|
749 | if tobackup: | |||
|
750 | touched = patchmod.changedfiles(self.ui, repo, pf) | |||
|
751 | touched = set(touched) & tobackup | |||
|
752 | self.backup(repo, touched, copy=True) | |||
|
753 | tobackup = tobackup - touched | |||
739 | (patcherr, files, fuzz) = self.patch(repo, pf) |
|
754 | (patcherr, files, fuzz) = self.patch(repo, pf) | |
740 | if all_files is not None: |
|
755 | if all_files is not None: | |
741 | all_files.update(files) |
|
756 | all_files.update(files) | |
@@ -1241,13 +1256,19 b' class queue(object):' | |||||
1241 | else: |
|
1256 | else: | |
1242 | end = self.series.index(patch, start) + 1 |
|
1257 | end = self.series.index(patch, start) + 1 | |
1243 |
|
1258 | |||
|
1259 | tobackup = set() | |||
|
1260 | if force: | |||
|
1261 | m, a, r, d = self.checklocalchanges(repo, force=True) | |||
|
1262 | tobackup.update(m + a) | |||
|
1263 | ||||
1244 | s = self.series[start:end] |
|
1264 | s = self.series[start:end] | |
1245 | all_files = set() |
|
1265 | all_files = set() | |
1246 | try: |
|
1266 | try: | |
1247 | if mergeq: |
|
1267 | if mergeq: | |
1248 | ret = self.mergepatch(repo, mergeq, s, diffopts) |
|
1268 | ret = self.mergepatch(repo, mergeq, s, diffopts) | |
1249 | else: |
|
1269 | else: | |
1250 |
ret = self.apply(repo, s, list, all_files=all_files |
|
1270 | ret = self.apply(repo, s, list, all_files=all_files, | |
|
1271 | tobackup=tobackup) | |||
1251 | except: |
|
1272 | except: | |
1252 | self.ui.warn(_('cleaning up working directory...')) |
|
1273 | self.ui.warn(_('cleaning up working directory...')) | |
1253 | node = repo.dirstate.p1() |
|
1274 | node = repo.dirstate.p1() |
@@ -188,3 +188,52 b' test qpop --force and backup files' | |||||
188 | bb |
|
188 | bb | |
189 | $ cat c.orig |
|
189 | $ cat c.orig | |
190 | cc |
|
190 | cc | |
|
191 | ||||
|
192 | test qpush --force and backup files | |||
|
193 | ||||
|
194 | $ echo a >> a | |||
|
195 | $ hg qnew p2 | |||
|
196 | $ echo b >> b | |||
|
197 | $ echo d > d | |||
|
198 | $ echo e > e | |||
|
199 | $ hg add d e | |||
|
200 | $ hg rm c | |||
|
201 | $ hg qnew p3 | |||
|
202 | $ hg qpop -a | |||
|
203 | popping p3 | |||
|
204 | popping p2 | |||
|
205 | patch queue now empty | |||
|
206 | $ echo a >> a | |||
|
207 | $ echo b1 >> b | |||
|
208 | $ echo d1 > d | |||
|
209 | $ hg add d | |||
|
210 | $ echo e1 > e | |||
|
211 | $ hg qpush -a --force --verbose | |||
|
212 | applying p2 | |||
|
213 | saving current version of a as a.orig | |||
|
214 | patching file a | |||
|
215 | a | |||
|
216 | applying p3 | |||
|
217 | saving current version of b as b.orig | |||
|
218 | saving current version of d as d.orig | |||
|
219 | patching file b | |||
|
220 | patching file c | |||
|
221 | patching file d | |||
|
222 | file d already exists | |||
|
223 | 1 out of 1 hunks FAILED -- saving rejects to file d.rej | |||
|
224 | patching file e | |||
|
225 | file e already exists | |||
|
226 | 1 out of 1 hunks FAILED -- saving rejects to file e.rej | |||
|
227 | patch failed to apply | |||
|
228 | b | |||
|
229 | patch failed, rejects left in working dir | |||
|
230 | errors during apply, please fix and refresh p3 | |||
|
231 | [2] | |||
|
232 | $ cat a.orig | |||
|
233 | a | |||
|
234 | a | |||
|
235 | $ cat b.orig | |||
|
236 | b | |||
|
237 | b1 | |||
|
238 | $ cat d.orig | |||
|
239 | d1 |
@@ -1356,11 +1356,15 b' qpush should fail, local changes' | |||||
1356 |
|
1356 | |||
1357 | apply force, should discard changes in hello, but not bye |
|
1357 | apply force, should discard changes in hello, but not bye | |
1358 |
|
1358 | |||
1359 | $ hg qpush -f |
|
1359 | $ hg qpush -f --verbose | |
1360 | applying empty |
|
1360 | applying empty | |
|
1361 | saving current version of hello.txt as hello.txt.orig | |||
|
1362 | patching file hello.txt | |||
|
1363 | hello.txt | |||
1361 | now at: empty |
|
1364 | now at: empty | |
1362 | $ hg st |
|
1365 | $ hg st | |
1363 | M bye.txt |
|
1366 | M bye.txt | |
|
1367 | ? hello.txt.orig | |||
1364 | $ hg diff --config diff.nodates=True |
|
1368 | $ hg diff --config diff.nodates=True | |
1365 | diff -r ba252371dbc1 bye.txt |
|
1369 | diff -r ba252371dbc1 bye.txt | |
1366 | --- a/bye.txt |
|
1370 | --- a/bye.txt |
General Comments 0
You need to be logged in to leave comments.
Login now