Mercurial > hg-stable
annotate hgext/shelve.py @ 20409:0b7a9940a397
shelve: mention walk options in help
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Mon, 10 Feb 2014 00:53:25 +0100 |
parents | 3392695abd68 |
children | fc5354648224 |
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 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
24 from mercurial.i18n import _ |
20407
955547eb2e20
shelve: publicancestors do not have to visit nullrev
Mads Kiilerich <madski@unity3d.com>
parents:
20149
diff
changeset
|
25 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
|
26 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
|
27 from mercurial import error, hg, mdiff, merge, patch, repair, util |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
28 from mercurial import templatefilters |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
29 from mercurial import lock as lockmod |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
30 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
|
31 import errno |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
32 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
33 cmdtable = {} |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
34 command = cmdutil.command(cmdtable) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
35 testedwith = 'internal' |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
36 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
37 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
|
38 """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
|
39 |
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
40 Handles common functions on shelve files (.hg/.files/.patch) using |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
41 the vfs layer""" |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
42 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
|
43 self.repo = repo |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
44 self.name = name |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
45 self.vfs = scmutil.vfs(repo.join('shelved')) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
46 if filetype: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
47 self.fname = name + '.' + filetype |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
48 else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
49 self.fname = name |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
50 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
51 def exists(self): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
52 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
|
53 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
54 def filename(self): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
55 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
|
56 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
57 def unlink(self): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
58 util.unlink(self.filename()) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
59 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
60 def stat(self): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
61 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
|
62 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
63 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
|
64 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
65 return self.vfs(self.fname, mode) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
66 except IOError, err: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
67 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
|
68 raise |
19964
ff38dfbce4f8
shelve: remove useless and incorrect code paths for file access
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19963
diff
changeset
|
69 raise util.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
|
70 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
71 class shelvedstate(object): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
72 """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
|
73 |
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
74 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
|
75 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
|
76 """ |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
77 _version = 1 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
78 _filename = 'shelvedstate' |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
79 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
80 @classmethod |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
81 def load(cls, repo): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
82 fp = repo.opener(cls._filename) |
19904
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
83 try: |
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
84 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
|
85 |
19904
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
86 if version != cls._version: |
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
87 raise util.Abort(_('this version of shelve is incompatible ' |
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
88 '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
|
89 name = fp.readline().strip() |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
90 wctx = fp.readline().strip() |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
91 pendingctx = fp.readline().strip() |
19904
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
92 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
|
93 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
|
94 finally: |
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
95 fp.close() |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
96 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
97 obj = cls() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
98 obj.name = name |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
99 obj.wctx = repo[bin(wctx)] |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
100 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
|
101 obj.parents = parents |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
102 obj.stripnodes = stripnodes |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
103 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
104 return obj |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
105 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
106 @classmethod |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
107 def save(cls, repo, name, originalwctx, pendingctx, stripnodes): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
108 fp = repo.opener(cls._filename, 'wb') |
19904
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
109 fp.write('%i\n' % cls._version) |
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
110 fp.write('%s\n' % name) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
111 fp.write('%s\n' % hex(originalwctx.node())) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
112 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
|
113 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
|
114 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
|
115 fp.close() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
116 |
19908
07ee5c8867ca
shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19904
diff
changeset
|
117 @classmethod |
07ee5c8867ca
shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19904
diff
changeset
|
118 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
|
119 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
|
120 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
121 def createcmd(ui, repo, pats, opts): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
122 """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
|
123 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
124 def publicancestors(ctx): |
20408
3392695abd68
shelve: really pass publicancestors to changegroupsubset - not the parents
Mads Kiilerich <madski@unity3d.com>
parents:
20407
diff
changeset
|
125 """Compute the public ancestors of a commit. |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
126 |
20408
3392695abd68
shelve: really pass publicancestors to changegroupsubset - not the parents
Mads Kiilerich <madski@unity3d.com>
parents:
20407
diff
changeset
|
127 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
|
128 seen = set([nullrev]) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
129 visit = util.deque() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
130 visit.append(ctx) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
131 while visit: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
132 ctx = visit.popleft() |
20408
3392695abd68
shelve: really pass publicancestors to changegroupsubset - not the parents
Mads Kiilerich <madski@unity3d.com>
parents:
20407
diff
changeset
|
133 yield ctx.node() |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
134 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
|
135 rev = parent.rev() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
136 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
|
137 seen.add(rev) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
138 if parent.mutable(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
139 visit.append(parent) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
140 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
141 wctx = repo[None] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
142 parents = wctx.parents() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
143 if len(parents) > 1: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
144 raise util.Abort(_('cannot shelve while merging')) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
145 parent = parents[0] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
146 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
147 # 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
|
148 user = 'shelve@localhost' |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
149 label = repo._bookmarkcurrent or parent.branch() or 'default' |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
150 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
151 # slashes aren't allowed in filenames, therefore we rename it |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
152 origlabel, label = label, label.replace('/', '_') |
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 def gennames(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
155 yield label |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
156 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
|
157 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
|
158 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
159 shelvedfiles = [] |
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 def commitfunc(ui, repo, message, match, opts): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
162 # check modified, added, removed, deleted only |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
163 for flist in repo.status(match=match)[:4]: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
164 shelvedfiles.extend(flist) |
19885
6cc696179869
shelve: only save mq state if enabled
Sean Farley <sean.michael.farley@gmail.com>
parents:
19881
diff
changeset
|
165 hasmq = util.safehasattr(repo, 'mq') |
6cc696179869
shelve: only save mq state if enabled
Sean Farley <sean.michael.farley@gmail.com>
parents:
19881
diff
changeset
|
166 if hasmq: |
6cc696179869
shelve: only save mq state if enabled
Sean Farley <sean.michael.farley@gmail.com>
parents:
19881
diff
changeset
|
167 saved, repo.mq.checkapplied = repo.mq.checkapplied, False |
19856
28b1b7b9b4a9
shelve: allow shelving of a change with an mq patch applied
David Soria Parra <dsp@experimentalworks.net>
parents:
19855
diff
changeset
|
168 try: |
28b1b7b9b4a9
shelve: allow shelving of a change with an mq patch applied
David Soria Parra <dsp@experimentalworks.net>
parents:
19855
diff
changeset
|
169 return repo.commit(message, user, opts.get('date'), match) |
28b1b7b9b4a9
shelve: allow shelving of a change with an mq patch applied
David Soria Parra <dsp@experimentalworks.net>
parents:
19855
diff
changeset
|
170 finally: |
19885
6cc696179869
shelve: only save mq state if enabled
Sean Farley <sean.michael.farley@gmail.com>
parents:
19881
diff
changeset
|
171 if hasmq: |
6cc696179869
shelve: only save mq state if enabled
Sean Farley <sean.michael.farley@gmail.com>
parents:
19881
diff
changeset
|
172 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
|
173 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
174 if parent.node() != nullid: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
175 desc = parent.description().split('\n', 1)[0] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
176 else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
177 desc = '(empty repository)' |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
178 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
179 if not opts['message']: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
180 opts['message'] = desc |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
181 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
182 name = opts['name'] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
183 |
19874
5836edcbdc2e
shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents:
19856
diff
changeset
|
184 wlock = lock = tr = bms = None |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
185 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
186 wlock = repo.wlock() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
187 lock = repo.lock() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
188 |
19874
5836edcbdc2e
shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents:
19856
diff
changeset
|
189 bms = repo._bookmarks.copy() |
19951
d51c4d85ec23
spelling: random spell checker fixes
Mads Kiilerich <madski@unity3d.com>
parents:
19943
diff
changeset
|
190 # 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
|
191 # 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
|
192 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
|
193 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
194 if name: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
195 if shelvedfile(repo, name, 'hg').exists(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
196 raise util.Abort(_("a shelved change named '%s' already exists") |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
197 % name) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
198 else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
199 for n in gennames(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
200 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
|
201 name = n |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
202 break |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
203 else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
204 raise util.Abort(_("too many shelved changes named '%s'") % |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
205 label) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
206 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
207 # 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
|
208 if '/' in name or '\\' in name: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
209 raise util.Abort(_('shelved change names may not contain slashes')) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
210 if name.startswith('.'): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
211 raise util.Abort(_("shelved change names may not start with '.'")) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
212 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
213 node = cmdutil.commit(ui, repo, commitfunc, pats, opts) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
214 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
215 if not node: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
216 stat = repo.status(match=scmutil.match(repo[None], pats, opts)) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
217 if stat[3]: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
218 ui.status(_("nothing changed (%d missing files, see " |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
219 "'hg status')\n") % len(stat[3])) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
220 else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
221 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
|
222 return 1 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
223 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
224 phases.retractboundary(repo, phases.secret, [node]) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
225 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
226 fp = shelvedfile(repo, name, 'files').opener('wb') |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
227 fp.write('\0'.join(shelvedfiles)) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
228 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
229 bases = list(publicancestors(repo[node])) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
230 cg = repo.changegroupsubset(bases, [node], 'shelve') |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
231 changegroup.writebundle(cg, shelvedfile(repo, name, 'hg').filename(), |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
232 'HG10UN') |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
233 cmdutil.export(repo, [node], |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
234 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
|
235 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
|
236 |
19874
5836edcbdc2e
shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents:
19856
diff
changeset
|
237 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
238 if ui.formatted(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
239 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
|
240 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
|
241 hg.update(repo, parent.node()) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
242 finally: |
19874
5836edcbdc2e
shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents:
19856
diff
changeset
|
243 if bms: |
5836edcbdc2e
shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents:
19856
diff
changeset
|
244 # restore old bookmarks |
5836edcbdc2e
shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents:
19856
diff
changeset
|
245 repo._bookmarks.update(bms) |
5836edcbdc2e
shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents:
19856
diff
changeset
|
246 repo._bookmarks.write() |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
247 if tr: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
248 tr.abort() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
249 lockmod.release(lock, wlock) |
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 def cleanupcmd(ui, repo): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
252 """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
|
253 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
254 wlock = None |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
255 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
256 wlock = repo.wlock() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
257 for (name, _) in repo.vfs.readdir('shelved'): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
258 suffix = name.rsplit('.', 1)[-1] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
259 if suffix in ('hg', 'files', 'patch'): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
260 shelvedfile(repo, name).unlink() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
261 finally: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
262 lockmod.release(wlock) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
263 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
264 def deletecmd(ui, repo, pats): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
265 """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
|
266 if not pats: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
267 raise util.Abort(_('no shelved changes specified!')) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
268 wlock = None |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
269 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
270 wlock = repo.wlock() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
271 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
272 for name in pats: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
273 for suffix in 'hg files patch'.split(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
274 shelvedfile(repo, name, suffix).unlink() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
275 except OSError, err: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
276 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
|
277 raise |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
278 raise util.Abort(_("shelved change '%s' not found") % name) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
279 finally: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
280 lockmod.release(wlock) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
281 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
282 def listshelves(repo): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
283 """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
|
284 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
285 names = repo.vfs.readdir('shelved') |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
286 except OSError, err: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
287 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
|
288 raise |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
289 return [] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
290 info = [] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
291 for (name, _) in names: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
292 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
|
293 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
|
294 continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
295 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
|
296 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
|
297 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
|
298 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
299 def listcmd(ui, repo, pats, opts): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
300 """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
|
301 pats = set(pats) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
302 width = 80 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
303 if not ui.plain(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
304 width = ui.termwidth() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
305 namelabel = 'shelve.newest' |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
306 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
|
307 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
|
308 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
|
309 continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
310 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
|
311 namelabel = 'shelve.name' |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
312 if ui.quiet: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
313 ui.write('\n') |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
314 continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
315 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
|
316 used = 16 |
19855
a3b285882724
shelve: new output format for shelve listings
David Soria Parra <dsp@experimentalworks.net>
parents:
19854
diff
changeset
|
317 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
|
318 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
|
319 ui.write(' ' * (12 - len(age))) |
a3b285882724
shelve: new output format for shelve listings
David Soria Parra <dsp@experimentalworks.net>
parents:
19854
diff
changeset
|
320 used += 12 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
321 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
|
322 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
323 while True: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
324 line = fp.readline() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
325 if not line: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
326 break |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
327 if not line.startswith('#'): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
328 desc = line.rstrip() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
329 if ui.formatted(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
330 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
|
331 ui.write(desc) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
332 break |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
333 ui.write('\n') |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
334 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
|
335 continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
336 difflines = fp.readlines() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
337 if opts['patch']: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
338 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
|
339 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
|
340 if opts['stat']: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
341 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
|
342 git=True): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
343 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
|
344 finally: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
345 fp.close() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
346 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
347 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
|
348 """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
|
349 if state.parents != repo.dirstate.parents(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
350 raise util.Abort(_('working directory parents do not match unshelve ' |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
351 'state')) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
352 |
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
|
353 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
|
354 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
|
355 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
|
356 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
357 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
|
358 """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
|
359 wlock = repo.wlock() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
360 lock = None |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
361 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
362 checkparents(repo, state) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
363 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
364 util.rename(repo.join('unshelverebasestate'), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
365 repo.join('rebasestate')) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
366 try: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
367 rebase.rebase(ui, repo, **{ |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
368 'abort' : True |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
369 }) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
370 except Exception: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
371 util.rename(repo.join('rebasestate'), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
372 repo.join('unshelverebasestate')) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
373 raise |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
374 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
375 lock = repo.lock() |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
376 |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
377 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
|
378 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
379 repair.strip(ui, repo, state.stripnodes, backup='none', topic='shelve') |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
380 shelvedstate.clear(repo) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
381 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
|
382 finally: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
383 lockmod.release(lock, wlock) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
384 |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
385 def mergefiles(ui, repo, wctx, shelvectx): |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
386 """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
|
387 dirstate.""" |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
388 oldquiet = ui.quiet |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
389 try: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
390 ui.quiet = True |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
391 hg.update(repo, wctx.node()) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
392 files = [] |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
393 files.extend(shelvectx.files()) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
394 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
|
395 |
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
396 # revert will overwrite unknown files, so move them out of the way |
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
397 m, a, r, d, u = repo.status(unknown=True)[:5] |
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
398 for file in u: |
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
399 if file in files: |
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
400 util.rename(file, file + ".orig") |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
401 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
|
402 *pathtofiles(repo, files), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
403 **{'no_backup': True}) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
404 finally: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
405 ui.quiet = oldquiet |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
406 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
407 def unshelvecleanup(ui, repo, name, opts): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
408 """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
|
409 if not opts['keep']: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
410 for filetype in 'hg files patch'.split(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
411 shelvedfile(repo, name, filetype).unlink() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
412 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
413 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
|
414 """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
|
415 # 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
|
416 # 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
|
417 wlock = repo.wlock() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
418 lock = None |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
419 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
420 checkparents(repo, state) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
421 ms = merge.mergestate(repo) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
422 if [f for f in ms if ms[f] == 'u']: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
423 raise util.Abort( |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
424 _("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
|
425 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
|
426 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
427 lock = repo.lock() |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
428 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
429 util.rename(repo.join('unshelverebasestate'), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
430 repo.join('rebasestate')) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
431 try: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
432 rebase.rebase(ui, repo, **{ |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
433 'continue' : True |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
434 }) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
435 except Exception: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
436 util.rename(repo.join('rebasestate'), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
437 repo.join('unshelverebasestate')) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
438 raise |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
439 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
440 shelvectx = repo['tip'] |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
441 if not shelvectx in state.pendingctx.children(): |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
442 # 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
|
443 shelvectx = state.pendingctx |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
444 |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
445 mergefiles(ui, repo, state.wctx, shelvectx) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
446 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
447 state.stripnodes.append(shelvectx.node()) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
448 repair.strip(ui, repo, state.stripnodes, backup='none', topic='shelve') |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
449 shelvedstate.clear(repo) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
450 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
|
451 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
|
452 finally: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
453 lockmod.release(lock, wlock) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
454 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
455 @command('unshelve', |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
456 [('a', 'abort', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
457 _('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
|
458 ('c', 'continue', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
459 _('continue an incomplete unshelve operation')), |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
460 ('', 'keep', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
461 _('keep shelve after unshelving'))], |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
462 _('hg unshelve [SHELVED]')) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
463 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
|
464 """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
|
465 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
466 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
|
467 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
|
468 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
469 If a shelved change is applied successfully, the bundle that |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
470 contains the shelved changes is deleted afterwards. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
471 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
472 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
|
473 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
|
474 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
|
475 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
|
476 ``--continue`` to complete the unshelve operation. (The bundle |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
477 will not be deleted until you successfully complete the unshelve.) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
478 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
479 (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
|
480 that causes a conflict. This reverts the unshelved changes, and |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
481 does not delete the bundle.) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
482 """ |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
483 abortf = opts['abort'] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
484 continuef = opts['continue'] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
485 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
|
486 cmdutil.checkunfinished(repo) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
487 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
488 if abortf or continuef: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
489 if abortf and continuef: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
490 raise util.Abort(_('cannot use both abort and continue')) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
491 if shelved: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
492 raise util.Abort(_('cannot combine abort/continue with ' |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
493 'naming a shelved change')) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
494 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
495 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
496 state = shelvedstate.load(repo) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
497 except IOError, err: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
498 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
|
499 raise |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
500 raise util.Abort(_('no unshelve operation underway')) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
501 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
502 if abortf: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
503 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
|
504 elif continuef: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
505 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
|
506 elif len(shelved) > 1: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
507 raise util.Abort(_('can only unshelve one change at a time')) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
508 elif not shelved: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
509 shelved = listshelves(repo) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
510 if not shelved: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
511 raise util.Abort(_('no shelved changes to apply!')) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
512 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
|
513 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
|
514 else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
515 basename = shelved[0] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
516 |
19970
065e6f1c9259
shelve: remove unused variable assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19964
diff
changeset
|
517 if not shelvedfile(repo, basename, 'files').exists(): |
065e6f1c9259
shelve: remove unused variable assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19964
diff
changeset
|
518 raise util.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
|
519 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
520 wlock = lock = tr = None |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
521 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
522 lock = repo.lock() |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
523 wlock = repo.wlock() |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
524 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
525 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
|
526 oldtiprev = len(repo) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
527 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
528 wctx = repo['.'] |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
529 tmpwctx = wctx |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
530 # The goal is to have a commit structure like so: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
531 # ...-> wctx -> tmpwctx -> shelvectx |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
532 # 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
|
533 # and shelvectx is the unshelved changes. Then we merge it all down |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
534 # to the original wctx. |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
535 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
536 # Store pending changes in a commit |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
537 m, a, r, d = repo.status()[:4] |
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
538 if m or a or r or d: |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
539 def commitfunc(ui, repo, message, match, opts): |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
540 hasmq = util.safehasattr(repo, 'mq') |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
541 if hasmq: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
542 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
|
543 |
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 return repo.commit(message, 'shelve@localhost', |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
546 opts.get('date'), match) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
547 finally: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
548 if hasmq: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
549 repo.mq.checkapplied = saved |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
550 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
551 tempopts = {} |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
552 tempopts['message'] = "pending changes temporary commit" |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
553 oldquiet = ui.quiet |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
554 try: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
555 ui.quiet = True |
20103
b3483223f734
shelve: fix bad argument interaction with largefiles (issue4111)
Matt Mackall <mpm@selenic.com>
parents:
20064
diff
changeset
|
556 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
|
557 finally: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
558 ui.quiet = oldquiet |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
559 tmpwctx = repo[node] |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
560 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
561 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
562 fp = shelvedfile(repo, basename, 'hg').opener() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
563 gen = changegroup.readbundle(fp, fp.name) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
564 repo.addchangegroup(gen, 'unshelve', 'bundle:' + fp.name) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
565 nodes = [ctx.node() for ctx in repo.set('%d:', oldtiprev)] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
566 phases.retractboundary(repo, phases.secret, nodes) |
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 fp.close() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
569 |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
570 shelvectx = repo['tip'] |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
571 |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
572 # 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
|
573 # 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
|
574 if tmpwctx.node() != shelvectx.parents()[0].node(): |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
575 try: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
576 rebase.rebase(ui, repo, **{ |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
577 'rev' : [shelvectx.rev()], |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
578 'dest' : str(tmpwctx.rev()), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
579 'keep' : True, |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
580 }) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
581 except error.InterventionRequired: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
582 tr.close() |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
583 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
584 stripnodes = [repo.changelog.node(rev) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
585 for rev in xrange(oldtiprev, len(repo))] |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
586 shelvedstate.save(repo, basename, wctx, tmpwctx, stripnodes) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
587 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
588 util.rename(repo.join('rebasestate'), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
589 repo.join('unshelverebasestate')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
590 raise error.InterventionRequired( |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
591 _("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
|
592 "'hg unshelve --continue')")) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
593 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
594 # refresh ctx after rebase completes |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
595 shelvectx = repo['tip'] |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
596 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
597 if not shelvectx in tmpwctx.children(): |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
598 # 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
|
599 shelvectx = tmpwctx |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
600 |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
601 mergefiles(ui, repo, wctx, shelvectx) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
602 shelvedstate.clear(repo) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
603 |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
604 # 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
|
605 # 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
|
606 # 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
|
607 # Clean up manually to prevent this. |
20064
99c4b8f79324
shelve: unshelve using an unfiltered repository
David Soria Parra <davidsp@fb.com>
parents:
19970
diff
changeset
|
608 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
|
609 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
610 unshelvecleanup(ui, repo, basename, opts) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
611 finally: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
612 if tr: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
613 tr.release() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
614 lockmod.release(lock, wlock) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
615 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
616 @command('shelve', |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
617 [('A', 'addremove', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
618 _('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
|
619 ('', 'cleanup', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
620 _('delete all shelved changes')), |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
621 ('', 'date', '', |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
622 _('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
|
623 ('d', 'delete', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
624 _('delete the named shelved change(s)')), |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
625 ('l', 'list', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
626 _('list current shelves')), |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
627 ('m', 'message', '', |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
628 _('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
|
629 ('n', 'name', '', |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
630 _('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
|
631 ('p', 'patch', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
632 _('show patch')), |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
633 ('', 'stat', None, |
20409
0b7a9940a397
shelve: mention walk options in help
Mads Kiilerich <madski@unity3d.com>
parents:
20408
diff
changeset
|
634 _('output diffstat-style summary of changes'))] + commands.walkopts, |
0b7a9940a397
shelve: mention walk options in help
Mads Kiilerich <madski@unity3d.com>
parents:
20408
diff
changeset
|
635 _('hg shelve [OPTION]...')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
636 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
|
637 '''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
|
638 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
639 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
|
640 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
|
641 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
|
642 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
643 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
|
644 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
|
645 commit. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
646 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
647 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
|
648 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
|
649 those files are shelved. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
650 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
651 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
|
652 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
|
653 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
|
654 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
|
655 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
656 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
|
657 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
|
658 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
|
659 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
660 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
|
661 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
|
662 ''' |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
663 cmdutil.checkunfinished(repo) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
664 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
665 def checkopt(opt, incompatible): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
666 if opts[opt]: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
667 for i in incompatible.split(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
668 if opts[i]: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
669 raise util.Abort(_("options '--%s' and '--%s' may not be " |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
670 "used together") % (opt, i)) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
671 return True |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
672 if checkopt('cleanup', 'addremove delete list message name patch stat'): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
673 if pats: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
674 raise util.Abort(_("cannot specify names when using '--cleanup'")) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
675 return cleanupcmd(ui, repo) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
676 elif checkopt('delete', 'addremove cleanup list message name patch stat'): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
677 return deletecmd(ui, repo, pats) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
678 elif checkopt('list', 'addremove cleanup delete message name'): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
679 return listcmd(ui, repo, pats, opts) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
680 else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
681 for i in ('patch', 'stat'): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
682 if opts[i]: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
683 raise util.Abort(_("option '--%s' may not be " |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
684 "used when shelving a change") % (i,)) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
685 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
|
686 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
687 def extsetup(ui): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
688 cmdutil.unfinishedstates.append( |
19963
6f29cc567845
shelve: disallow commit while unshelve is in progress
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19961
diff
changeset
|
689 [shelvedstate._filename, False, False, |
6f29cc567845
shelve: disallow commit while unshelve is in progress
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19961
diff
changeset
|
690 _('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
|
691 _("use 'hg unshelve --continue' or 'hg unshelve --abort'")]) |