Mercurial > hg
annotate hgext/shelve.py @ 27085:d50ff8f4891f
histedit: add an experimental base action
This is a first (very simple) version of the histedit base action.
It works well in common usecases like rebasing the whole stack and
spliting the stack.
I don't see any obvious edge cases - but probably there is more than one.
That's why I want to keep it behind experimental.histeditng config knob
for now. I think on knob for all new histedit behaviors is better because
we will test all of them together and testers will need to turn it on only
once to get all new nice things.
author | Mateusz Kwapich <mitrandir@fb.com> |
---|---|
date | Tue, 17 Nov 2015 15:04:31 -0800 |
parents | f2554154509f |
children | 156985f2dec0 |
rev | line source |
---|---|
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1 # shelve.py - save/restore working directory state |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
2 # |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
3 # Copyright 2013 Facebook, Inc. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
4 # |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
7 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
8 """save and restore changes to the working directory |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
9 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
10 The "hg shelve" command saves changes made to the working directory |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
11 and reverts those changes, resetting the working directory to a clean |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
12 state. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
13 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
14 Later on, the "hg unshelve" command restores the changes saved by "hg |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
15 shelve". Changes can be restored even after updating to a different |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
16 parent, in which case Mercurial's merge machinery will resolve any |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
17 conflicts if necessary. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
18 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
19 You can have more than one shelved change outstanding at a time; each |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
20 shelved change has a distinct name. For details, see the help for "hg |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
21 shelve". |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
22 """ |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
23 |
25113
0ca8410ea345
util: drop alias for collections.deque
Martin von Zweigbergk <martinvonz@google.com>
parents:
25104
diff
changeset
|
24 import collections |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
25 import itertools |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
26 from mercurial.i18n import _ |
20407
955547eb2e20
shelve: publicancestors do not have to visit nullrev
Mads Kiilerich <madski@unity3d.com>
parents:
20149
diff
changeset
|
27 from mercurial.node import nullid, nullrev, bin, hex |
20409
0b7a9940a397
shelve: mention walk options in help
Mads Kiilerich <madski@unity3d.com>
parents:
20408
diff
changeset
|
28 from mercurial import changegroup, cmdutil, scmutil, phases, commands |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
29 from mercurial import error, hg, mdiff, merge, patch, repair, util |
26799
ae03d4190321
shelve: properly process bundle2 bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26697
diff
changeset
|
30 from mercurial import templatefilters, exchange, bundlerepo, bundle2 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
31 from mercurial import lock as lockmod |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
32 from hgext import rebase |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
33 import errno |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
34 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
35 cmdtable = {} |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
36 command = cmdutil.command(cmdtable) |
25186
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
25113
diff
changeset
|
37 # Note for extension authors: ONLY specify testedwith = 'internal' for |
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
25113
diff
changeset
|
38 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
25113
diff
changeset
|
39 # be specifying the version(s) of Mercurial they are tested with, or |
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
25113
diff
changeset
|
40 # leave the attribute unspecified. |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
41 testedwith = 'internal' |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
42 |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
43 backupdir = 'shelve-backup' |
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
44 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
45 class shelvedfile(object): |
19909
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
46 """Helper for the file storing a single shelve |
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
47 |
22581
c5ece02fb211
shelve: avoid writing file that is never read from
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22202
diff
changeset
|
48 Handles common functions on shelve files (.hg/.patch) using |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
49 the vfs layer""" |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
50 def __init__(self, repo, name, filetype=None): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
51 self.repo = repo |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
52 self.name = name |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
53 self.vfs = scmutil.vfs(repo.join('shelved')) |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
54 self.backupvfs = scmutil.vfs(repo.join(backupdir)) |
23895
cda18ded2c48
changegroup.writebundle: provide ui
Eric Sumner <ericsumner@fb.com>
parents:
23877
diff
changeset
|
55 self.ui = self.repo.ui |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
56 if filetype: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
57 self.fname = name + '.' + filetype |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
58 else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
59 self.fname = name |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
60 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
61 def exists(self): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
62 return self.vfs.exists(self.fname) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
63 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
64 def filename(self): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
65 return self.vfs.join(self.fname) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
66 |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
67 def backupfilename(self): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
68 def gennames(base): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
69 yield base |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
70 base, ext = base.rsplit('.', 1) |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
71 for i in itertools.count(1): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
72 yield '%s-%d.%s' % (base, i, ext) |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
73 |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
74 name = self.backupvfs.join(self.fname) |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
75 for n in gennames(name): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
76 if not self.backupvfs.exists(n): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
77 return n |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
78 |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
79 def movetobackup(self): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
80 if not self.backupvfs.isdir(): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
81 self.backupvfs.makedir() |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
82 util.rename(self.filename(), self.backupfilename()) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
83 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
84 def stat(self): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
85 return self.vfs.stat(self.fname) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
86 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
87 def opener(self, mode='rb'): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
88 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
89 return self.vfs(self.fname, mode) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25260
diff
changeset
|
90 except IOError as err: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
91 if err.errno != errno.ENOENT: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
92 raise |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
93 raise error.Abort(_("shelved change '%s' not found") % self.name) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
94 |
20982
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
95 def applybundle(self): |
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
96 fp = self.opener() |
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
97 try: |
21064
4d9d490d7bbe
bundle2: add a ui argument to readbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21063
diff
changeset
|
98 gen = exchange.readbundle(self.repo.ui, fp, self.fname, self.vfs) |
26799
ae03d4190321
shelve: properly process bundle2 bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26697
diff
changeset
|
99 if not isinstance(gen, bundle2.unbundle20): |
ae03d4190321
shelve: properly process bundle2 bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26697
diff
changeset
|
100 gen.apply(self.repo, 'unshelve', |
ae03d4190321
shelve: properly process bundle2 bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26697
diff
changeset
|
101 'bundle:' + self.vfs.join(self.fname), |
ae03d4190321
shelve: properly process bundle2 bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26697
diff
changeset
|
102 targetphase=phases.secret) |
ae03d4190321
shelve: properly process bundle2 bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26697
diff
changeset
|
103 if isinstance(gen, bundle2.unbundle20): |
ae03d4190321
shelve: properly process bundle2 bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26697
diff
changeset
|
104 bundle2.applybundle(self.repo, gen, |
ae03d4190321
shelve: properly process bundle2 bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26697
diff
changeset
|
105 self.repo.currenttransaction(), |
ae03d4190321
shelve: properly process bundle2 bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26697
diff
changeset
|
106 source='unshelve', |
ae03d4190321
shelve: properly process bundle2 bundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26697
diff
changeset
|
107 url='bundle:' + self.vfs.join(self.fname)) |
20982
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
108 finally: |
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
109 fp.close() |
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
110 |
22898
43816070284e
shelve: add a bundlerepo method
Matt Mackall <mpm@selenic.com>
parents:
22844
diff
changeset
|
111 def bundlerepo(self): |
43816070284e
shelve: add a bundlerepo method
Matt Mackall <mpm@selenic.com>
parents:
22844
diff
changeset
|
112 return bundlerepo.bundlerepository(self.repo.baseui, self.repo.root, |
43816070284e
shelve: add a bundlerepo method
Matt Mackall <mpm@selenic.com>
parents:
22844
diff
changeset
|
113 self.vfs.join(self.fname)) |
26506
edecf059fda6
shelve: move changegroup generation inside writebundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26505
diff
changeset
|
114 def writebundle(self, bases, node): |
26507
ae29cffa05db
shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26506
diff
changeset
|
115 btype = 'HG10BZ' |
ae29cffa05db
shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26506
diff
changeset
|
116 cgversion = '01' |
ae29cffa05db
shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26506
diff
changeset
|
117 compression = None |
ae29cffa05db
shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26506
diff
changeset
|
118 if 'generaldelta' in self.repo.requirements: |
ae29cffa05db
shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26506
diff
changeset
|
119 btype = 'HG20' |
ae29cffa05db
shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26506
diff
changeset
|
120 cgversion = '02' |
ae29cffa05db
shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26506
diff
changeset
|
121 compression = 'BZ' |
ae29cffa05db
shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26506
diff
changeset
|
122 |
ae29cffa05db
shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26506
diff
changeset
|
123 cg = changegroup.changegroupsubset(self.repo, bases, [node], 'shelve', |
ae29cffa05db
shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26506
diff
changeset
|
124 version=cgversion) |
ae29cffa05db
shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26506
diff
changeset
|
125 changegroup.writebundle(self.ui, cg, self.fname, btype, self.vfs, |
ae29cffa05db
shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26506
diff
changeset
|
126 compression=compression) |
20983
2778616de7ce
shelve: add "writebundle()" to invoke "writebundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20982
diff
changeset
|
127 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
128 class shelvedstate(object): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
129 """Handle persistence during unshelving operations. |
19909
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
130 |
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
131 Handles saving and restoring a shelved state. Ensures that different |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
132 versions of a shelved state are possible and handles them appropriately. |
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
133 """ |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
134 _version = 1 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
135 _filename = 'shelvedstate' |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
136 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
137 @classmethod |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
138 def load(cls, repo): |
23877
7cc77030c557
localrepo: remove all external users of localrepo.opener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
22922
diff
changeset
|
139 fp = repo.vfs(cls._filename) |
19904
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
140 try: |
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
141 version = int(fp.readline().strip()) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
142 |
19904
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
143 if version != cls._version: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
144 raise error.Abort(_('this version of shelve is incompatible ' |
19904
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
145 'with the version used in this repo')) |
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
146 name = fp.readline().strip() |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
147 wctx = fp.readline().strip() |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
148 pendingctx = fp.readline().strip() |
19904
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
149 parents = [bin(h) for h in fp.readline().split()] |
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
150 stripnodes = [bin(h) for h in fp.readline().split()] |
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
151 finally: |
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
152 fp.close() |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
153 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
154 obj = cls() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
155 obj.name = name |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
156 obj.wctx = repo[bin(wctx)] |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
157 obj.pendingctx = repo[bin(pendingctx)] |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
158 obj.parents = parents |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
159 obj.stripnodes = stripnodes |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
160 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
161 return obj |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
162 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
163 @classmethod |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
164 def save(cls, repo, name, originalwctx, pendingctx, stripnodes): |
23877
7cc77030c557
localrepo: remove all external users of localrepo.opener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
22922
diff
changeset
|
165 fp = repo.vfs(cls._filename, 'wb') |
19904
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
166 fp.write('%i\n' % cls._version) |
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
167 fp.write('%s\n' % name) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
168 fp.write('%s\n' % hex(originalwctx.node())) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
169 fp.write('%s\n' % hex(pendingctx.node())) |
19904
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
170 fp.write('%s\n' % ' '.join([hex(p) for p in repo.dirstate.parents()])) |
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
171 fp.write('%s\n' % ' '.join([hex(n) for n in stripnodes])) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
172 fp.close() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
173 |
19908
07ee5c8867ca
shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19904
diff
changeset
|
174 @classmethod |
07ee5c8867ca
shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19904
diff
changeset
|
175 def clear(cls, repo): |
07ee5c8867ca
shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19904
diff
changeset
|
176 util.unlinkpath(repo.join(cls._filename), ignoremissing=True) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
177 |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
178 def cleanupoldbackups(repo): |
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
179 vfs = scmutil.vfs(repo.join(backupdir)) |
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
180 maxbackups = repo.ui.configint('shelve', 'maxbackups', 10) |
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
181 hgfiles = [f for f in vfs.listdir() if f.endswith('.hg')] |
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
182 hgfiles = sorted([(vfs.stat(f).st_mtime, f) for f in hgfiles]) |
25774
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
183 if 0 < maxbackups and maxbackups < len(hgfiles): |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
184 bordermtime = hgfiles[-maxbackups][0] |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
185 else: |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
186 bordermtime = None |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
187 for mtime, f in hgfiles[:len(hgfiles) - maxbackups]: |
25774
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
188 if mtime == bordermtime: |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
189 # keep it, because timestamp can't decide exact order of backups |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
190 continue |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
191 base = f[:-3] |
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
192 for ext in 'hg patch'.split(): |
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
193 try: |
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
194 vfs.unlink(base + '.' + ext) |
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
195 except OSError as err: |
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
196 if err.errno != errno.ENOENT: |
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
197 raise |
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
198 |
26522
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
199 def _aborttransaction(repo): |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
200 '''Abort current transaction for shelve/unshelve, but keep dirstate |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
201 ''' |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
202 backupname = 'dirstate.shelve' |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
203 dirstatebackup = None |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
204 try: |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
205 # create backup of (un)shelved dirstate, because aborting transaction |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
206 # should restore dirstate to one at the beginning of the |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
207 # transaction, which doesn't include the result of (un)shelving |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
208 fp = repo.vfs.open(backupname, "w") |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
209 dirstatebackup = backupname |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
210 # clearing _dirty/_dirtypl of dirstate by _writedirstate below |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
211 # is unintentional. but it doesn't cause problem in this case, |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
212 # because no code path refers them until transaction is aborted. |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
213 repo.dirstate._writedirstate(fp) # write in-memory changes forcibly |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
214 |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
215 tr = repo.currenttransaction() |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
216 tr.abort() |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
217 |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
218 # restore to backuped dirstate |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
219 repo.vfs.rename(dirstatebackup, 'dirstate') |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
220 dirstatebackup = None |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
221 finally: |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
222 if dirstatebackup: |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
223 repo.vfs.unlink(dirstatebackup) |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
224 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
225 def createcmd(ui, repo, pats, opts): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
226 """subcommand that creates a new shelve""" |
19909
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
227 |
26602
c062a9c0293c
shelve: rename 'publicancestors' to something accurate (issue4737)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26587
diff
changeset
|
228 def mutableancestors(ctx): |
c062a9c0293c
shelve: rename 'publicancestors' to something accurate (issue4737)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26587
diff
changeset
|
229 """return all mutable ancestors for ctx (included) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
230 |
20408
3392695abd68
shelve: really pass publicancestors to changegroupsubset - not the parents
Mads Kiilerich <madski@unity3d.com>
parents:
20407
diff
changeset
|
231 Much faster than the revset ancestors(ctx) & draft()""" |
20407
955547eb2e20
shelve: publicancestors do not have to visit nullrev
Mads Kiilerich <madski@unity3d.com>
parents:
20149
diff
changeset
|
232 seen = set([nullrev]) |
25113
0ca8410ea345
util: drop alias for collections.deque
Martin von Zweigbergk <martinvonz@google.com>
parents:
25104
diff
changeset
|
233 visit = collections.deque() |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
234 visit.append(ctx) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
235 while visit: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
236 ctx = visit.popleft() |
20408
3392695abd68
shelve: really pass publicancestors to changegroupsubset - not the parents
Mads Kiilerich <madski@unity3d.com>
parents:
20407
diff
changeset
|
237 yield ctx.node() |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
238 for parent in ctx.parents(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
239 rev = parent.rev() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
240 if rev not in seen: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
241 seen.add(rev) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
242 if parent.mutable(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
243 visit.append(parent) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
244 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
245 wctx = repo[None] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
246 parents = wctx.parents() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
247 if len(parents) > 1: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
248 raise error.Abort(_('cannot shelve while merging')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
249 parent = parents[0] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
250 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
251 # we never need the user, so we use a generic user for all shelve operations |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
252 user = 'shelve@localhost' |
24947
a02d293a1079
bookmarks: rename bookmarkcurrent to activebookmark (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24872
diff
changeset
|
253 label = repo._activebookmark or parent.branch() or 'default' |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
254 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
255 # slashes aren't allowed in filenames, therefore we rename it |
20937
c0bf8bea10dd
shelve: remove unused variable caught by pyflakes
Sean Farley <sean.michael.farley@gmail.com>
parents:
20149
diff
changeset
|
256 label = label.replace('/', '_') |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
257 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
258 def gennames(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
259 yield label |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
260 for i in xrange(1, 100): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
261 yield '%s-%02d' % (label, i) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
262 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
263 def commitfunc(ui, repo, message, match, opts): |
19885
6cc696179869
shelve: only save mq state if enabled
Sean Farley <sean.michael.farley@gmail.com>
parents:
19881
diff
changeset
|
264 hasmq = util.safehasattr(repo, 'mq') |
6cc696179869
shelve: only save mq state if enabled
Sean Farley <sean.michael.farley@gmail.com>
parents:
19881
diff
changeset
|
265 if hasmq: |
6cc696179869
shelve: only save mq state if enabled
Sean Farley <sean.michael.farley@gmail.com>
parents:
19881
diff
changeset
|
266 saved, repo.mq.checkapplied = repo.mq.checkapplied, False |
22040
122fa73657c6
shelve: do not retract phase boundary by hand
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22005
diff
changeset
|
267 backup = repo.ui.backupconfig('phases', 'new-commit') |
19856
28b1b7b9b4a9
shelve: allow shelving of a change with an mq patch applied
David Soria Parra <dsp@experimentalworks.net>
parents:
19855
diff
changeset
|
268 try: |
22040
122fa73657c6
shelve: do not retract phase boundary by hand
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22005
diff
changeset
|
269 repo.ui. setconfig('phases', 'new-commit', phases.secret) |
22005
dabf8fb8a91e
shelve: pass 'editform' argument to 'cmdutil.getcommiteditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21852
diff
changeset
|
270 editor = cmdutil.getcommiteditor(editform='shelve.shelve', **opts) |
21852
37a5decc6924
shelve: accept '--edit' like other commands creating new changeset
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21851
diff
changeset
|
271 return repo.commit(message, user, opts.get('date'), match, |
22005
dabf8fb8a91e
shelve: pass 'editform' argument to 'cmdutil.getcommiteditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21852
diff
changeset
|
272 editor=editor) |
19856
28b1b7b9b4a9
shelve: allow shelving of a change with an mq patch applied
David Soria Parra <dsp@experimentalworks.net>
parents:
19855
diff
changeset
|
273 finally: |
22040
122fa73657c6
shelve: do not retract phase boundary by hand
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22005
diff
changeset
|
274 repo.ui.restoreconfig(backup) |
19885
6cc696179869
shelve: only save mq state if enabled
Sean Farley <sean.michael.farley@gmail.com>
parents:
19881
diff
changeset
|
275 if hasmq: |
6cc696179869
shelve: only save mq state if enabled
Sean Farley <sean.michael.farley@gmail.com>
parents:
19881
diff
changeset
|
276 repo.mq.checkapplied = saved |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
277 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
278 if parent.node() != nullid: |
20411
66359d8b8d7e
shelve: add 'changes to' prefix to default shelve message
Mads Kiilerich <madski@unity3d.com>
parents:
20410
diff
changeset
|
279 desc = "changes to '%s'" % parent.description().split('\n', 1)[0] |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
280 else: |
20411
66359d8b8d7e
shelve: add 'changes to' prefix to default shelve message
Mads Kiilerich <madski@unity3d.com>
parents:
20410
diff
changeset
|
281 desc = '(changes in empty repository)' |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
282 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
283 if not opts['message']: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
284 opts['message'] = desc |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
285 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
286 name = opts['name'] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
287 |
26520
46dec89fe888
bookmarks: use recordchange instead of writing if transaction is active
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26507
diff
changeset
|
288 wlock = lock = tr = None |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
289 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
290 wlock = repo.wlock() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
291 lock = repo.lock() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
292 |
19951
d51c4d85ec23
spelling: random spell checker fixes
Mads Kiilerich <madski@unity3d.com>
parents:
19943
diff
changeset
|
293 # use an uncommitted transaction to generate the bundle to avoid |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
294 # pull races. ensure we don't print the abort message to stderr. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
295 tr = repo.transaction('commit', report=lambda x: None) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
296 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
297 if name: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
298 if shelvedfile(repo, name, 'hg').exists(): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
299 raise error.Abort(_("a shelved change named '%s' already exists" |
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
300 ) % name) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
301 else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
302 for n in gennames(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
303 if not shelvedfile(repo, n, 'hg').exists(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
304 name = n |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
305 break |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
306 else: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
307 raise error.Abort(_("too many shelved changes named '%s'") % |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
308 label) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
309 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
310 # ensure we are not creating a subdirectory or a hidden file |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
311 if '/' in name or '\\' in name: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
312 raise error.Abort(_('shelved change names may not contain slashes')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
313 if name.startswith('.'): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
314 raise error.Abort(_("shelved change names may not start with '.'")) |
24477
325f03de849d
shelve: add interactive mode command line option
Laurent Charignon <lcharignon@fb.com>
parents:
23895
diff
changeset
|
315 interactive = opts.get('interactive', False) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
316 |
24478
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
317 def interactivecommitfunc(ui, repo, *pats, **opts): |
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
318 match = scmutil.match(repo['.'], pats, {}) |
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
319 message = opts['message'] |
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
320 return commitfunc(ui, repo, message, match, opts) |
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
321 if not interactive: |
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
322 node = cmdutil.commit(ui, repo, commitfunc, pats, opts) |
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
323 else: |
25799
0eb093e40813
shelve: omit incorrect 'commit' suggestion at 'hg shelve -i'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25774
diff
changeset
|
324 node = cmdutil.dorecord(ui, repo, interactivecommitfunc, None, |
24478
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
325 False, cmdutil.recordfilter, *pats, **opts) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
326 if not node: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
327 stat = repo.status(match=scmutil.match(repo[None], pats, opts)) |
22922
ebef5fcf7bd0
shelve: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22898
diff
changeset
|
328 if stat.deleted: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
329 ui.status(_("nothing changed (%d missing files, see " |
22922
ebef5fcf7bd0
shelve: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22898
diff
changeset
|
330 "'hg status')\n") % len(stat.deleted)) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
331 else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
332 ui.status(_("nothing changed\n")) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
333 return 1 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
334 |
26602
c062a9c0293c
shelve: rename 'publicancestors' to something accurate (issue4737)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26587
diff
changeset
|
335 bases = list(mutableancestors(repo[node])) |
26506
edecf059fda6
shelve: move changegroup generation inside writebundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26505
diff
changeset
|
336 shelvedfile(repo, name, 'hg').writebundle(bases, node) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
337 cmdutil.export(repo, [node], |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
338 fp=shelvedfile(repo, name, 'patch').opener('wb'), |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
339 opts=mdiff.diffopts(git=True)) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
340 |
19874
5836edcbdc2e
shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents:
19856
diff
changeset
|
341 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
342 if ui.formatted(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
343 desc = util.ellipsis(desc, ui.termwidth()) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
344 ui.status(_('shelved as %s\n') % name) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
345 hg.update(repo, parent.node()) |
26523
1d23bf6cd90a
shelve: restore shelved dirstate explicitly after aborting transaction
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26522
diff
changeset
|
346 |
1d23bf6cd90a
shelve: restore shelved dirstate explicitly after aborting transaction
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26522
diff
changeset
|
347 _aborttransaction(repo) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
348 finally: |
26523
1d23bf6cd90a
shelve: restore shelved dirstate explicitly after aborting transaction
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26522
diff
changeset
|
349 lockmod.release(tr, lock, wlock) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
350 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
351 def cleanupcmd(ui, repo): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
352 """subcommand that deletes all shelves""" |
19909
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
353 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
354 wlock = None |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
355 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
356 wlock = repo.wlock() |
22199
b3e51675f98e
cleanup: avoid _ for local unused tmp variables - that is reserved for i18n
Mads Kiilerich <madski@unity3d.com>
parents:
22184
diff
changeset
|
357 for (name, _type) in repo.vfs.readdir('shelved'): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
358 suffix = name.rsplit('.', 1)[-1] |
22581
c5ece02fb211
shelve: avoid writing file that is never read from
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22202
diff
changeset
|
359 if suffix in ('hg', 'patch'): |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
360 shelvedfile(repo, name).movetobackup() |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
361 cleanupoldbackups(repo) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
362 finally: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
363 lockmod.release(wlock) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
364 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
365 def deletecmd(ui, repo, pats): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
366 """subcommand that deletes a specific shelve""" |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
367 if not pats: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
368 raise error.Abort(_('no shelved changes specified!')) |
25080
68f456f2f425
shelve: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24947
diff
changeset
|
369 wlock = repo.wlock() |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
370 try: |
25080
68f456f2f425
shelve: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24947
diff
changeset
|
371 for name in pats: |
68f456f2f425
shelve: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24947
diff
changeset
|
372 for suffix in 'hg patch'.split(): |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
373 shelvedfile(repo, name, suffix).movetobackup() |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
374 cleanupoldbackups(repo) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25260
diff
changeset
|
375 except OSError as err: |
25080
68f456f2f425
shelve: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24947
diff
changeset
|
376 if err.errno != errno.ENOENT: |
68f456f2f425
shelve: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24947
diff
changeset
|
377 raise |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
378 raise error.Abort(_("shelved change '%s' not found") % name) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
379 finally: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
380 lockmod.release(wlock) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
381 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
382 def listshelves(repo): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
383 """return all shelves in repo as list of (time, filename)""" |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
384 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
385 names = repo.vfs.readdir('shelved') |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25260
diff
changeset
|
386 except OSError as err: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
387 if err.errno != errno.ENOENT: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
388 raise |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
389 return [] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
390 info = [] |
22199
b3e51675f98e
cleanup: avoid _ for local unused tmp variables - that is reserved for i18n
Mads Kiilerich <madski@unity3d.com>
parents:
22184
diff
changeset
|
391 for (name, _type) in names: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
392 pfx, sfx = name.rsplit('.', 1) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
393 if not pfx or sfx != 'patch': |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
394 continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
395 st = shelvedfile(repo, name).stat() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
396 info.append((st.st_mtime, shelvedfile(repo, pfx).filename())) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
397 return sorted(info, reverse=True) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
398 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
399 def listcmd(ui, repo, pats, opts): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
400 """subcommand that displays the list of shelves""" |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
401 pats = set(pats) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
402 width = 80 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
403 if not ui.plain(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
404 width = ui.termwidth() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
405 namelabel = 'shelve.newest' |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
406 for mtime, name in listshelves(repo): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
407 sname = util.split(name)[1] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
408 if pats and sname not in pats: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
409 continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
410 ui.write(sname, label=namelabel) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
411 namelabel = 'shelve.name' |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
412 if ui.quiet: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
413 ui.write('\n') |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
414 continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
415 ui.write(' ' * (16 - len(sname))) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
416 used = 16 |
19855
a3b285882724
shelve: new output format for shelve listings
David Soria Parra <dsp@experimentalworks.net>
parents:
19854
diff
changeset
|
417 age = '(%s)' % templatefilters.age(util.makedate(mtime), abbrev=True) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
418 ui.write(age, label='shelve.age') |
19855
a3b285882724
shelve: new output format for shelve listings
David Soria Parra <dsp@experimentalworks.net>
parents:
19854
diff
changeset
|
419 ui.write(' ' * (12 - len(age))) |
a3b285882724
shelve: new output format for shelve listings
David Soria Parra <dsp@experimentalworks.net>
parents:
19854
diff
changeset
|
420 used += 12 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
421 fp = open(name + '.patch', 'rb') |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
422 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
423 while True: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
424 line = fp.readline() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
425 if not line: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
426 break |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
427 if not line.startswith('#'): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
428 desc = line.rstrip() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
429 if ui.formatted(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
430 desc = util.ellipsis(desc, width - used) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
431 ui.write(desc) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
432 break |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
433 ui.write('\n') |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
434 if not (opts['patch'] or opts['stat']): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
435 continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
436 difflines = fp.readlines() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
437 if opts['patch']: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
438 for chunk, label in patch.difflabel(iter, difflines): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
439 ui.write(chunk, label=label) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
440 if opts['stat']: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
441 for chunk, label in patch.diffstatui(difflines, width=width, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
442 git=True): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
443 ui.write(chunk, label=label) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
444 finally: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
445 fp.close() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
446 |
25104
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
447 def singlepatchcmds(ui, repo, pats, opts, subcommand): |
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
448 """subcommand that displays a single shelf""" |
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
449 if len(pats) != 1: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
450 raise error.Abort(_("--%s expects a single shelf") % subcommand) |
25104
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
451 shelfname = pats[0] |
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
452 |
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
453 if not shelvedfile(repo, shelfname, 'patch').exists(): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
454 raise error.Abort(_("cannot find shelf %s") % shelfname) |
25104
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
455 |
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
456 listcmd(ui, repo, pats, opts) |
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
457 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
458 def checkparents(repo, state): |
19909
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
459 """check parent while resuming an unshelve""" |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
460 if state.parents != repo.dirstate.parents(): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
461 raise error.Abort(_('working directory parents do not match unshelve ' |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
462 'state')) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
463 |
19943
4de116871044
shelve: make unshelve work even if it don't run in repository root
Takumi IINO <trot.thunder@gmail.com>
parents:
19911
diff
changeset
|
464 def pathtofiles(repo, files): |
4de116871044
shelve: make unshelve work even if it don't run in repository root
Takumi IINO <trot.thunder@gmail.com>
parents:
19911
diff
changeset
|
465 cwd = repo.getcwd() |
4de116871044
shelve: make unshelve work even if it don't run in repository root
Takumi IINO <trot.thunder@gmail.com>
parents:
19911
diff
changeset
|
466 return [repo.pathto(f, cwd) for f in files] |
4de116871044
shelve: make unshelve work even if it don't run in repository root
Takumi IINO <trot.thunder@gmail.com>
parents:
19911
diff
changeset
|
467 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
468 def unshelveabort(ui, repo, state, opts): |
19909
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
469 """subcommand that abort an in-progress unshelve""" |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
470 wlock = repo.wlock() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
471 lock = None |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
472 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
473 checkparents(repo, state) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
474 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
475 util.rename(repo.join('unshelverebasestate'), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
476 repo.join('rebasestate')) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
477 try: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
478 rebase.rebase(ui, repo, **{ |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
479 'abort' : True |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
480 }) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
481 except Exception: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
482 util.rename(repo.join('rebasestate'), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
483 repo.join('unshelverebasestate')) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
484 raise |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
485 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
486 lock = repo.lock() |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
487 |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
488 mergefiles(ui, repo, state.wctx, state.pendingctx) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
489 |
22057
445472225ccd
strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22042
diff
changeset
|
490 repair.strip(ui, repo, state.stripnodes, backup=False, topic='shelve') |
26681
ca8170b5d370
shelve: delete shelve statefile on any exception during abort
Christian Delahousse <cdelahousse@fb.com>
parents:
26602
diff
changeset
|
491 finally: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
492 shelvedstate.clear(repo) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
493 ui.warn(_("unshelve of '%s' aborted\n") % state.name) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
494 lockmod.release(lock, wlock) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
495 |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
496 def mergefiles(ui, repo, wctx, shelvectx): |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
497 """updates to wctx and merges the changes from shelvectx into the |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
498 dirstate.""" |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
499 oldquiet = ui.quiet |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
500 try: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
501 ui.quiet = True |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
502 hg.update(repo, wctx.node()) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
503 files = [] |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
504 files.extend(shelvectx.files()) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
505 files.extend(shelvectx.parents()[0].files()) |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
506 |
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
507 # revert will overwrite unknown files, so move them out of the way |
22922
ebef5fcf7bd0
shelve: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22898
diff
changeset
|
508 for file in repo.status(unknown=True).unknown: |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
509 if file in files: |
26942
d55d22840592
shelve: choose where .orig file locations are kept
Christian Delahousse <cdelahousse@fb.com>
parents:
26799
diff
changeset
|
510 util.rename(file, cmdutil.origpath(ui, repo, file)) |
22184
fb8065de47b0
unshelve: silence internal revert
Matt Mackall <mpm@selenic.com>
parents:
22057
diff
changeset
|
511 ui.pushbuffer(True) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
512 cmdutil.revert(ui, repo, shelvectx, repo.dirstate.parents(), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
513 *pathtofiles(repo, files), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
514 **{'no_backup': True}) |
22184
fb8065de47b0
unshelve: silence internal revert
Matt Mackall <mpm@selenic.com>
parents:
22057
diff
changeset
|
515 ui.popbuffer() |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
516 finally: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
517 ui.quiet = oldquiet |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
518 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
519 def unshelvecleanup(ui, repo, name, opts): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
520 """remove related files after an unshelve""" |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
521 if not opts['keep']: |
22581
c5ece02fb211
shelve: avoid writing file that is never read from
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22202
diff
changeset
|
522 for filetype in 'hg patch'.split(): |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
523 shelvedfile(repo, name, filetype).movetobackup() |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
524 cleanupoldbackups(repo) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
525 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
526 def unshelvecontinue(ui, repo, state, opts): |
19909
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
527 """subcommand to continue an in-progress unshelve""" |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
528 # We're finishing off a merge. First parent is our original |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
529 # parent, second is the temporary "fake" commit we're unshelving. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
530 wlock = repo.wlock() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
531 lock = None |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
532 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
533 checkparents(repo, state) |
26992
b3b5ed560283
shelve: switch to mergestate.read()
Siddharth Agarwal <sid0@fb.com>
parents:
26942
diff
changeset
|
534 ms = merge.mergestate.read(repo) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
535 if [f for f in ms if ms[f] == 'u']: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
536 raise error.Abort( |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
537 _("unresolved conflicts, can't continue"), |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
538 hint=_("see 'hg resolve', then 'hg unshelve --continue'")) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
539 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
540 lock = repo.lock() |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
541 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
542 util.rename(repo.join('unshelverebasestate'), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
543 repo.join('rebasestate')) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
544 try: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
545 rebase.rebase(ui, repo, **{ |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
546 'continue' : True |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
547 }) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
548 except Exception: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
549 util.rename(repo.join('rebasestate'), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
550 repo.join('unshelverebasestate')) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
551 raise |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
552 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
553 shelvectx = repo['tip'] |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
554 if not shelvectx in state.pendingctx.children(): |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
555 # rebase was a no-op, so it produced no child commit |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
556 shelvectx = state.pendingctx |
22842
d43d116a118c
shelve: don't delete "." when rebase is a no-op (issue4398)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21852
diff
changeset
|
557 else: |
d43d116a118c
shelve: don't delete "." when rebase is a no-op (issue4398)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21852
diff
changeset
|
558 # only strip the shelvectx if the rebase produced it |
d43d116a118c
shelve: don't delete "." when rebase is a no-op (issue4398)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21852
diff
changeset
|
559 state.stripnodes.append(shelvectx.node()) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
560 |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
561 mergefiles(ui, repo, state.wctx, shelvectx) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
562 |
22057
445472225ccd
strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22042
diff
changeset
|
563 repair.strip(ui, repo, state.stripnodes, backup=False, topic='shelve') |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
564 shelvedstate.clear(repo) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
565 unshelvecleanup(ui, repo, state.name, opts) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
566 ui.status(_("unshelve of '%s' complete\n") % state.name) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
567 finally: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
568 lockmod.release(lock, wlock) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
569 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
570 @command('unshelve', |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
571 [('a', 'abort', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
572 _('abort an incomplete unshelve operation')), |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
573 ('c', 'continue', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
574 _('continue an incomplete unshelve operation')), |
27019
5cf184398ee7
unshelve: add -k as short form of --keep
Siddharth Agarwal <sid0@fb.com>
parents:
26992
diff
changeset
|
575 ('k', 'keep', None, |
20960
8e5b21ce8ee9
shelve: introduce secret option for using fixed date for temporary commit
Mads Kiilerich <madski@unity3d.com>
parents:
20958
diff
changeset
|
576 _('keep shelve after unshelving')), |
27021
f2554154509f
unshelve: add support for custom merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
27020
diff
changeset
|
577 ('t', 'tool', '', _('specify merge tool')), |
20960
8e5b21ce8ee9
shelve: introduce secret option for using fixed date for temporary commit
Mads Kiilerich <madski@unity3d.com>
parents:
20958
diff
changeset
|
578 ('', 'date', '', |
8e5b21ce8ee9
shelve: introduce secret option for using fixed date for temporary commit
Mads Kiilerich <madski@unity3d.com>
parents:
20958
diff
changeset
|
579 _('set date for temporary commits (DEPRECATED)'), _('DATE'))], |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
580 _('hg unshelve [SHELVED]')) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
581 def unshelve(ui, repo, *shelved, **opts): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
582 """restore a shelved change to the working directory |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
583 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
584 This command accepts an optional name of a shelved change to |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
585 restore. If none is given, the most recent shelved change is used. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
586 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
587 If a shelved change is applied successfully, the bundle that |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
588 contains the shelved changes is moved to a backup location |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
589 (.hg/shelve-backup). |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
590 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
591 Since you can restore a shelved change on top of an arbitrary |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
592 commit, it is possible that unshelving will result in a conflict |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
593 between your changes and the commits you are unshelving onto. If |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
594 this occurs, you must resolve the conflict, then use |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
595 ``--continue`` to complete the unshelve operation. (The bundle |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
596 will not be moved until you successfully complete the unshelve.) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
597 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
598 (Alternatively, you can use ``--abort`` to abandon an unshelve |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
599 that causes a conflict. This reverts the unshelved changes, and |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
600 leaves the bundle in place.) |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
601 |
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
602 After a successful unshelve, the shelved changes are stored in a |
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
603 backup directory. Only the N most recent backups are kept. N |
25852
870e361e049c
shelve: make maxbackup doc check-config friendly
Matt Mackall <mpm@selenic.com>
parents:
25799
diff
changeset
|
604 defaults to 10 but can be overridden using the ``shelve.maxbackups`` |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
605 configuration option. |
25774
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
606 |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
607 .. container:: verbose |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
608 |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
609 Timestamp in seconds is used to decide order of backups. More |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
610 than ``maxbackups`` backups are kept, if same timestamp |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
611 prevents from deciding exact order of them, for safety. |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
612 """ |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
613 abortf = opts['abort'] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
614 continuef = opts['continue'] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
615 if not abortf and not continuef: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
616 cmdutil.checkunfinished(repo) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
617 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
618 if abortf or continuef: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
619 if abortf and continuef: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
620 raise error.Abort(_('cannot use both abort and continue')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
621 if shelved: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
622 raise error.Abort(_('cannot combine abort/continue with ' |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
623 'naming a shelved change')) |
27021
f2554154509f
unshelve: add support for custom merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
27020
diff
changeset
|
624 if abortf and opts.get('tool', False): |
f2554154509f
unshelve: add support for custom merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
27020
diff
changeset
|
625 ui.warn(_('tool option will be ignored\n')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
626 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
627 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
628 state = shelvedstate.load(repo) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25260
diff
changeset
|
629 except IOError as err: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
630 if err.errno != errno.ENOENT: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
631 raise |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
632 raise error.Abort(_('no unshelve operation underway')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
633 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
634 if abortf: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
635 return unshelveabort(ui, repo, state, opts) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
636 elif continuef: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
637 return unshelvecontinue(ui, repo, state, opts) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
638 elif len(shelved) > 1: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
639 raise error.Abort(_('can only unshelve one change at a time')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
640 elif not shelved: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
641 shelved = listshelves(repo) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
642 if not shelved: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
643 raise error.Abort(_('no shelved changes to apply!')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
644 basename = util.split(shelved[0][1])[1] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
645 ui.status(_("unshelving change '%s'\n") % basename) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
646 else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
647 basename = shelved[0] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
648 |
22581
c5ece02fb211
shelve: avoid writing file that is never read from
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22202
diff
changeset
|
649 if not shelvedfile(repo, basename, 'patch').exists(): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
650 raise error.Abort(_("shelved change '%s' not found") % basename) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
651 |
20412
e584fc30456b
shelve: be quiet when unshelve pulls from the shelve bundle
Mads Kiilerich <madski@unity3d.com>
parents:
20411
diff
changeset
|
652 oldquiet = ui.quiet |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
653 wlock = lock = tr = None |
27021
f2554154509f
unshelve: add support for custom merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
27020
diff
changeset
|
654 forcemerge = ui.backupconfig('ui', 'forcemerge') |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
655 try: |
27021
f2554154509f
unshelve: add support for custom merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
27020
diff
changeset
|
656 ui.setconfig('ui', 'forcemerge', opts.get('tool', ''), 'unshelve') |
24704
03f92741487f
shelve: acquire lock in the right order
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24478
diff
changeset
|
657 wlock = repo.wlock() |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
658 lock = repo.lock() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
659 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
660 tr = repo.transaction('unshelve', report=lambda x: None) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
661 oldtiprev = len(repo) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
662 |
20958
df33c9014430
shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents:
20942
diff
changeset
|
663 pctx = repo['.'] |
df33c9014430
shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents:
20942
diff
changeset
|
664 tmpwctx = pctx |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
665 # The goal is to have a commit structure like so: |
20958
df33c9014430
shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents:
20942
diff
changeset
|
666 # ...-> pctx -> tmpwctx -> shelvectx |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
667 # where tmpwctx is an optional commit with the user's pending changes |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
668 # and shelvectx is the unshelved changes. Then we merge it all down |
20958
df33c9014430
shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents:
20942
diff
changeset
|
669 # to the original pctx. |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
670 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
671 # Store pending changes in a commit |
22922
ebef5fcf7bd0
shelve: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22898
diff
changeset
|
672 s = repo.status() |
ebef5fcf7bd0
shelve: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22898
diff
changeset
|
673 if s.modified or s.added or s.removed or s.deleted: |
20413
0ac94c0a3a38
shelve: status messages from unshelve
Mads Kiilerich <madski@unity3d.com>
parents:
20412
diff
changeset
|
674 ui.status(_("temporarily committing pending changes " |
0ac94c0a3a38
shelve: status messages from unshelve
Mads Kiilerich <madski@unity3d.com>
parents:
20412
diff
changeset
|
675 "(restore with 'hg unshelve --abort')\n")) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
676 def commitfunc(ui, repo, message, match, opts): |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
677 hasmq = util.safehasattr(repo, 'mq') |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
678 if hasmq: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
679 saved, repo.mq.checkapplied = repo.mq.checkapplied, False |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
680 |
22040
122fa73657c6
shelve: do not retract phase boundary by hand
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22005
diff
changeset
|
681 backup = repo.ui.backupconfig('phases', 'new-commit') |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
682 try: |
27020
cc2049184ece
unshelve: shed spurious space
Siddharth Agarwal <sid0@fb.com>
parents:
27019
diff
changeset
|
683 repo.ui.setconfig('phases', 'new-commit', phases.secret) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
684 return repo.commit(message, 'shelve@localhost', |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
685 opts.get('date'), match) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
686 finally: |
22040
122fa73657c6
shelve: do not retract phase boundary by hand
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22005
diff
changeset
|
687 repo.ui.restoreconfig(backup) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
688 if hasmq: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
689 repo.mq.checkapplied = saved |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
690 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
691 tempopts = {} |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
692 tempopts['message'] = "pending changes temporary commit" |
20960
8e5b21ce8ee9
shelve: introduce secret option for using fixed date for temporary commit
Mads Kiilerich <madski@unity3d.com>
parents:
20958
diff
changeset
|
693 tempopts['date'] = opts.get('date') |
20412
e584fc30456b
shelve: be quiet when unshelve pulls from the shelve bundle
Mads Kiilerich <madski@unity3d.com>
parents:
20411
diff
changeset
|
694 ui.quiet = True |
e584fc30456b
shelve: be quiet when unshelve pulls from the shelve bundle
Mads Kiilerich <madski@unity3d.com>
parents:
20411
diff
changeset
|
695 node = cmdutil.commit(ui, repo, commitfunc, [], tempopts) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
696 tmpwctx = repo[node] |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
697 |
20982
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
698 ui.quiet = True |
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
699 shelvedfile(repo, basename, 'hg').applybundle() |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
700 |
20412
e584fc30456b
shelve: be quiet when unshelve pulls from the shelve bundle
Mads Kiilerich <madski@unity3d.com>
parents:
20411
diff
changeset
|
701 ui.quiet = oldquiet |
e584fc30456b
shelve: be quiet when unshelve pulls from the shelve bundle
Mads Kiilerich <madski@unity3d.com>
parents:
20411
diff
changeset
|
702 |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
703 shelvectx = repo['tip'] |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
704 |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
705 # If the shelve is not immediately on top of the commit |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
706 # we'll be merging with, rebase it to be on top. |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
707 if tmpwctx.node() != shelvectx.parents()[0].node(): |
20413
0ac94c0a3a38
shelve: status messages from unshelve
Mads Kiilerich <madski@unity3d.com>
parents:
20412
diff
changeset
|
708 ui.status(_('rebasing shelved changes\n')) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
709 try: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
710 rebase.rebase(ui, repo, **{ |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
711 'rev' : [shelvectx.rev()], |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
712 'dest' : str(tmpwctx.rev()), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
713 'keep' : True, |
27021
f2554154509f
unshelve: add support for custom merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
27020
diff
changeset
|
714 'tool' : opts.get('tool', ''), |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
715 }) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
716 except error.InterventionRequired: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
717 tr.close() |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
718 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
719 stripnodes = [repo.changelog.node(rev) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
720 for rev in xrange(oldtiprev, len(repo))] |
20958
df33c9014430
shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents:
20942
diff
changeset
|
721 shelvedstate.save(repo, basename, pctx, tmpwctx, stripnodes) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
722 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
723 util.rename(repo.join('rebasestate'), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
724 repo.join('unshelverebasestate')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
725 raise error.InterventionRequired( |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
726 _("unresolved conflicts (see 'hg resolve', then " |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
727 "'hg unshelve --continue')")) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
728 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
729 # refresh ctx after rebase completes |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
730 shelvectx = repo['tip'] |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
731 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
732 if not shelvectx in tmpwctx.children(): |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
733 # rebase was a no-op, so it produced no child commit |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
734 shelvectx = tmpwctx |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
735 |
20958
df33c9014430
shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents:
20942
diff
changeset
|
736 mergefiles(ui, repo, pctx, shelvectx) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
737 shelvedstate.clear(repo) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
738 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
739 # The transaction aborting will strip all the commits for us, |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
740 # but it doesn't update the inmemory structures, so addchangegroup |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
741 # hooks still fire and try to operate on the missing commits. |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
742 # Clean up manually to prevent this. |
20064
99c4b8f79324
shelve: unshelve using an unfiltered repository
David Soria Parra <davidsp@fb.com>
parents:
19970
diff
changeset
|
743 repo.unfiltered().changelog.strip(oldtiprev, tr) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
744 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
745 unshelvecleanup(ui, repo, basename, opts) |
26524
61c295d9d402
shelve: restore unshelved dirstate explicitly after aborting transaction
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26523
diff
changeset
|
746 |
61c295d9d402
shelve: restore unshelved dirstate explicitly after aborting transaction
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26523
diff
changeset
|
747 _aborttransaction(repo) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
748 finally: |
20412
e584fc30456b
shelve: be quiet when unshelve pulls from the shelve bundle
Mads Kiilerich <madski@unity3d.com>
parents:
20411
diff
changeset
|
749 ui.quiet = oldquiet |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
750 if tr: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
751 tr.release() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
752 lockmod.release(lock, wlock) |
27021
f2554154509f
unshelve: add support for custom merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
27020
diff
changeset
|
753 ui.restoreconfig(forcemerge) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
754 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
755 @command('shelve', |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
756 [('A', 'addremove', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
757 _('mark new/missing files as added/removed before shelving')), |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
758 ('', 'cleanup', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
759 _('delete all shelved changes')), |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
760 ('', 'date', '', |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
761 _('shelve with the specified commit date'), _('DATE')), |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
762 ('d', 'delete', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
763 _('delete the named shelved change(s)')), |
21852
37a5decc6924
shelve: accept '--edit' like other commands creating new changeset
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21851
diff
changeset
|
764 ('e', 'edit', False, |
37a5decc6924
shelve: accept '--edit' like other commands creating new changeset
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21851
diff
changeset
|
765 _('invoke editor on commit messages')), |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
766 ('l', 'list', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
767 _('list current shelves')), |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
768 ('m', 'message', '', |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
769 _('use text as shelve message'), _('TEXT')), |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
770 ('n', 'name', '', |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
771 _('use the given name for the shelved commit'), _('NAME')), |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
772 ('p', 'patch', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
773 _('show patch')), |
24477
325f03de849d
shelve: add interactive mode command line option
Laurent Charignon <lcharignon@fb.com>
parents:
23895
diff
changeset
|
774 ('i', 'interactive', None, |
25260
8fa3e995a375
selve: make 'shelve --interactive' not experimental
Laurent Charignon <lcharignon@fb.com>
parents:
25186
diff
changeset
|
775 _('interactive mode, only works while creating a shelve')), |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
776 ('', 'stat', None, |
20409
0b7a9940a397
shelve: mention walk options in help
Mads Kiilerich <madski@unity3d.com>
parents:
20408
diff
changeset
|
777 _('output diffstat-style summary of changes'))] + commands.walkopts, |
20410
fc5354648224
shelve: mention FILE options in help
Mads Kiilerich <madski@unity3d.com>
parents:
20409
diff
changeset
|
778 _('hg shelve [OPTION]... [FILE]...')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
779 def shelvecmd(ui, repo, *pats, **opts): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
780 '''save and set aside changes from the working directory |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
781 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
782 Shelving takes files that "hg status" reports as not clean, saves |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
783 the modifications to a bundle (a shelved change), and reverts the |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
784 files so that their state in the working directory becomes clean. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
785 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
786 To restore these changes to the working directory, using "hg |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
787 unshelve"; this will work even if you switch to a different |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
788 commit. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
789 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
790 When no files are specified, "hg shelve" saves all not-clean |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
791 files. If specific files or directories are named, only changes to |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
792 those files are shelved. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
793 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
794 Each shelved change has a name that makes it easier to find later. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
795 The name of a shelved change defaults to being based on the active |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
796 bookmark, or if there is no active bookmark, the current named |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
797 branch. To specify a different name, use ``--name``. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
798 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
799 To see a list of existing shelved changes, use the ``--list`` |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
800 option. For each shelved change, this will print its name, age, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
801 and description; use ``--patch`` or ``--stat`` for more details. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
802 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
803 To delete specific shelved changes, use ``--delete``. To delete |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
804 all shelved changes, use ``--cleanup``. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
805 ''' |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
806 cmdutil.checkunfinished(repo) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
807 |
21851
aad28ff87788
shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21064
diff
changeset
|
808 allowables = [ |
25103
ce00b2e96d09
shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents:
25080
diff
changeset
|
809 ('addremove', set(['create'])), # 'create' is pseudo action |
ce00b2e96d09
shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents:
25080
diff
changeset
|
810 ('cleanup', set(['cleanup'])), |
ce00b2e96d09
shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents:
25080
diff
changeset
|
811 # ('date', set(['create'])), # ignored for passing '--date "0 0"' in tests |
ce00b2e96d09
shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents:
25080
diff
changeset
|
812 ('delete', set(['delete'])), |
ce00b2e96d09
shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents:
25080
diff
changeset
|
813 ('edit', set(['create'])), |
ce00b2e96d09
shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents:
25080
diff
changeset
|
814 ('list', set(['list'])), |
ce00b2e96d09
shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents:
25080
diff
changeset
|
815 ('message', set(['create'])), |
ce00b2e96d09
shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents:
25080
diff
changeset
|
816 ('name', set(['create'])), |
25104
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
817 ('patch', set(['patch', 'list'])), |
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
818 ('stat', set(['stat', 'list'])), |
21851
aad28ff87788
shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21064
diff
changeset
|
819 ] |
aad28ff87788
shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21064
diff
changeset
|
820 def checkopt(opt): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
821 if opts[opt]: |
21851
aad28ff87788
shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21064
diff
changeset
|
822 for i, allowable in allowables: |
25103
ce00b2e96d09
shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents:
25080
diff
changeset
|
823 if opts[i] and opt not in allowable: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
824 raise error.Abort(_("options '--%s' and '--%s' may not be " |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
825 "used together") % (opt, i)) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
826 return True |
21851
aad28ff87788
shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21064
diff
changeset
|
827 if checkopt('cleanup'): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
828 if pats: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
829 raise error.Abort(_("cannot specify names when using '--cleanup'")) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
830 return cleanupcmd(ui, repo) |
21851
aad28ff87788
shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21064
diff
changeset
|
831 elif checkopt('delete'): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
832 return deletecmd(ui, repo, pats) |
21851
aad28ff87788
shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21064
diff
changeset
|
833 elif checkopt('list'): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
834 return listcmd(ui, repo, pats, opts) |
25104
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
835 elif checkopt('patch'): |
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
836 return singlepatchcmds(ui, repo, pats, opts, subcommand='patch') |
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
837 elif checkopt('stat'): |
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
838 return singlepatchcmds(ui, repo, pats, opts, subcommand='stat') |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
839 else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
840 return createcmd(ui, repo, pats, opts) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
841 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
842 def extsetup(ui): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
843 cmdutil.unfinishedstates.append( |
19963
6f29cc567845
shelve: disallow commit while unshelve is in progress
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19961
diff
changeset
|
844 [shelvedstate._filename, False, False, |
6f29cc567845
shelve: disallow commit while unshelve is in progress
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19961
diff
changeset
|
845 _('unshelve already in progress'), |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
846 _("use 'hg unshelve --continue' or 'hg unshelve --abort'")]) |