author | Tony Tung <tonytung@fb.com> |
Tue, 14 Apr 2015 16:23:07 -0400 | |
changeset 25103 | ce00b2e96d09 |
parent 25080 | 68f456f2f425 |
child 25104 | d6453f6fbdba |
permissions | -rw-r--r-- |
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 |
22898
43816070284e
shelve: add a bundlerepo method
Matt Mackall <mpm@selenic.com>
parents:
22844
diff
changeset
|
28 |
from mercurial import templatefilters, exchange, bundlerepo |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
29 |
from mercurial import 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 |
|
22581
c5ece02fb211
shelve: avoid writing file that is never read from
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22202
diff
changeset
|
40 |
Handles common functions on shelve files (.hg/.patch) using |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
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')) |
23895
cda18ded2c48
changegroup.writebundle: provide ui
Eric Sumner <ericsumner@fb.com>
parents:
23877
diff
changeset
|
46 |
self.ui = self.repo.ui |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
47 |
if filetype: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
48 |
self.fname = name + '.' + filetype |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
49 |
else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
50 |
self.fname = name |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
51 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
52 |
def exists(self): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
53 |
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
|
54 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
55 |
def filename(self): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
56 |
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
|
57 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
58 |
def unlink(self): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
59 |
util.unlink(self.filename()) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
60 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
61 |
def stat(self): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
62 |
return self.vfs.stat(self.fname) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
63 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
64 |
def opener(self, mode='rb'): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
65 |
try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
66 |
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
|
67 |
except IOError, err: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
68 |
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
|
69 |
raise |
19964
ff38dfbce4f8
shelve: remove useless and incorrect code paths for file access
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19963
diff
changeset
|
70 |
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
|
71 |
|
20982
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
72 |
def applybundle(self): |
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
73 |
fp = self.opener() |
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
74 |
try: |
21064
4d9d490d7bbe
bundle2: add a ui argument to readbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21063
diff
changeset
|
75 |
gen = exchange.readbundle(self.repo.ui, fp, self.fname, self.vfs) |
20982
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
76 |
changegroup.addchangegroup(self.repo, gen, 'unshelve', |
22042
8d99c107b041
shelve: use `targetphase` while unbundling
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22040
diff
changeset
|
77 |
'bundle:' + self.vfs.join(self.fname), |
8d99c107b041
shelve: use `targetphase` while unbundling
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22040
diff
changeset
|
78 |
targetphase=phases.secret) |
20982
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
79 |
finally: |
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
80 |
fp.close() |
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
81 |
|
22898
43816070284e
shelve: add a bundlerepo method
Matt Mackall <mpm@selenic.com>
parents:
22844
diff
changeset
|
82 |
def bundlerepo(self): |
43816070284e
shelve: add a bundlerepo method
Matt Mackall <mpm@selenic.com>
parents:
22844
diff
changeset
|
83 |
return bundlerepo.bundlerepository(self.repo.baseui, self.repo.root, |
43816070284e
shelve: add a bundlerepo method
Matt Mackall <mpm@selenic.com>
parents:
22844
diff
changeset
|
84 |
self.vfs.join(self.fname)) |
20983
2778616de7ce
shelve: add "writebundle()" to invoke "writebundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20982
diff
changeset
|
85 |
def writebundle(self, cg): |
23895
cda18ded2c48
changegroup.writebundle: provide ui
Eric Sumner <ericsumner@fb.com>
parents:
23877
diff
changeset
|
86 |
changegroup.writebundle(self.ui, cg, self.fname, 'HG10UN', self.vfs) |
20983
2778616de7ce
shelve: add "writebundle()" to invoke "writebundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20982
diff
changeset
|
87 |
|
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
88 |
class shelvedstate(object): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
89 |
"""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
|
90 |
|
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
91 |
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
|
92 |
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
|
93 |
""" |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
94 |
_version = 1 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
95 |
_filename = 'shelvedstate' |
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 |
@classmethod |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
98 |
def load(cls, repo): |
23877
7cc77030c557
localrepo: remove all external users of localrepo.opener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
22922
diff
changeset
|
99 |
fp = repo.vfs(cls._filename) |
19904
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
100 |
try: |
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
101 |
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
|
102 |
|
19904
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
103 |
if version != cls._version: |
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
104 |
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
|
105 |
'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
|
106 |
name = fp.readline().strip() |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
107 |
wctx = fp.readline().strip() |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
108 |
pendingctx = fp.readline().strip() |
19904
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
109 |
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
|
110 |
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
|
111 |
finally: |
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
112 |
fp.close() |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
113 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
114 |
obj = cls() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
115 |
obj.name = name |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
116 |
obj.wctx = repo[bin(wctx)] |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
117 |
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
|
118 |
obj.parents = parents |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
119 |
obj.stripnodes = stripnodes |
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 |
return obj |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
122 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
123 |
@classmethod |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
124 |
def save(cls, repo, name, originalwctx, pendingctx, stripnodes): |
23877
7cc77030c557
localrepo: remove all external users of localrepo.opener
Angel Ezquerra <angel.ezquerra@gmail.com>
parents:
22922
diff
changeset
|
125 |
fp = repo.vfs(cls._filename, 'wb') |
19904
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
126 |
fp.write('%i\n' % cls._version) |
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
127 |
fp.write('%s\n' % name) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
128 |
fp.write('%s\n' % hex(originalwctx.node())) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
129 |
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
|
130 |
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
|
131 |
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
|
132 |
fp.close() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
133 |
|
19908
07ee5c8867ca
shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19904
diff
changeset
|
134 |
@classmethod |
07ee5c8867ca
shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19904
diff
changeset
|
135 |
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
|
136 |
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
|
137 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
138 |
def createcmd(ui, repo, pats, opts): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
139 |
"""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
|
140 |
|
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
141 |
def publicancestors(ctx): |
20408
3392695abd68
shelve: really pass publicancestors to changegroupsubset - not the parents
Mads Kiilerich <madski@unity3d.com>
parents:
20407
diff
changeset
|
142 |
"""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
|
143 |
|
20408
3392695abd68
shelve: really pass publicancestors to changegroupsubset - not the parents
Mads Kiilerich <madski@unity3d.com>
parents:
20407
diff
changeset
|
144 |
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
|
145 |
seen = set([nullrev]) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
146 |
visit = util.deque() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
147 |
visit.append(ctx) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
148 |
while visit: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
149 |
ctx = visit.popleft() |
20408
3392695abd68
shelve: really pass publicancestors to changegroupsubset - not the parents
Mads Kiilerich <madski@unity3d.com>
parents:
20407
diff
changeset
|
150 |
yield ctx.node() |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
151 |
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
|
152 |
rev = parent.rev() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
153 |
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
|
154 |
seen.add(rev) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
155 |
if parent.mutable(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
156 |
visit.append(parent) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
157 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
158 |
wctx = repo[None] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
159 |
parents = wctx.parents() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
160 |
if len(parents) > 1: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
161 |
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
|
162 |
parent = parents[0] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
163 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
164 |
# 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
|
165 |
user = 'shelve@localhost' |
24947
a02d293a1079
bookmarks: rename bookmarkcurrent to activebookmark (API)
Ryan McElroy <rmcelroy@fb.com>
parents:
24872
diff
changeset
|
166 |
label = repo._activebookmark or parent.branch() or 'default' |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
167 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
168 |
# slashes aren't allowed in filenames, therefore we rename it |
20937
c0bf8bea10dd
shelve: remove unused variable caught by pyflakes
Sean Farley <sean.michael.farley@gmail.com>
parents:
20149
diff
changeset
|
169 |
label = label.replace('/', '_') |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
170 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
171 |
def gennames(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
172 |
yield label |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
173 |
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
|
174 |
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
|
175 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
176 |
def commitfunc(ui, repo, message, match, opts): |
19885
6cc696179869
shelve: only save mq state if enabled
Sean Farley <sean.michael.farley@gmail.com>
parents:
19881
diff
changeset
|
177 |
hasmq = util.safehasattr(repo, 'mq') |
6cc696179869
shelve: only save mq state if enabled
Sean Farley <sean.michael.farley@gmail.com>
parents:
19881
diff
changeset
|
178 |
if hasmq: |
6cc696179869
shelve: only save mq state if enabled
Sean Farley <sean.michael.farley@gmail.com>
parents:
19881
diff
changeset
|
179 |
saved, repo.mq.checkapplied = repo.mq.checkapplied, False |
22040
122fa73657c6
shelve: do not retract phase boundary by hand
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22005
diff
changeset
|
180 |
backup = repo.ui.backupconfig('phases', 'new-commit') |
19856
28b1b7b9b4a9
shelve: allow shelving of a change with an mq patch applied
David Soria Parra <dsp@experimentalworks.net>
parents:
19855
diff
changeset
|
181 |
try: |
22040
122fa73657c6
shelve: do not retract phase boundary by hand
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22005
diff
changeset
|
182 |
repo.ui. setconfig('phases', 'new-commit', phases.secret) |
22005
dabf8fb8a91e
shelve: pass 'editform' argument to 'cmdutil.getcommiteditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21852
diff
changeset
|
183 |
editor = cmdutil.getcommiteditor(editform='shelve.shelve', **opts) |
21852
37a5decc6924
shelve: accept '--edit' like other commands creating new changeset
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21851
diff
changeset
|
184 |
return repo.commit(message, user, opts.get('date'), match, |
22005
dabf8fb8a91e
shelve: pass 'editform' argument to 'cmdutil.getcommiteditor'
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21852
diff
changeset
|
185 |
editor=editor) |
19856
28b1b7b9b4a9
shelve: allow shelving of a change with an mq patch applied
David Soria Parra <dsp@experimentalworks.net>
parents:
19855
diff
changeset
|
186 |
finally: |
22040
122fa73657c6
shelve: do not retract phase boundary by hand
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22005
diff
changeset
|
187 |
repo.ui.restoreconfig(backup) |
19885
6cc696179869
shelve: only save mq state if enabled
Sean Farley <sean.michael.farley@gmail.com>
parents:
19881
diff
changeset
|
188 |
if hasmq: |
6cc696179869
shelve: only save mq state if enabled
Sean Farley <sean.michael.farley@gmail.com>
parents:
19881
diff
changeset
|
189 |
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
|
190 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
191 |
if parent.node() != nullid: |
20411
66359d8b8d7e
shelve: add 'changes to' prefix to default shelve message
Mads Kiilerich <madski@unity3d.com>
parents:
20410
diff
changeset
|
192 |
desc = "changes to '%s'" % parent.description().split('\n', 1)[0] |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
193 |
else: |
20411
66359d8b8d7e
shelve: add 'changes to' prefix to default shelve message
Mads Kiilerich <madski@unity3d.com>
parents:
20410
diff
changeset
|
194 |
desc = '(changes in empty repository)' |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
195 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
196 |
if not opts['message']: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
197 |
opts['message'] = desc |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
198 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
199 |
name = opts['name'] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
200 |
|
19874
5836edcbdc2e
shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents:
19856
diff
changeset
|
201 |
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
|
202 |
try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
203 |
wlock = repo.wlock() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
204 |
lock = repo.lock() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
205 |
|
19874
5836edcbdc2e
shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents:
19856
diff
changeset
|
206 |
bms = repo._bookmarks.copy() |
19951
d51c4d85ec23
spelling: random spell checker fixes
Mads Kiilerich <madski@unity3d.com>
parents:
19943
diff
changeset
|
207 |
# 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
|
208 |
# 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
|
209 |
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
|
210 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
211 |
if name: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
212 |
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
|
213 |
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
|
214 |
% name) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
215 |
else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
216 |
for n in gennames(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
217 |
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
|
218 |
name = n |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
219 |
break |
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 |
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
|
222 |
label) |
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 |
# 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
|
225 |
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
|
226 |
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
|
227 |
if name.startswith('.'): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
228 |
raise util.Abort(_("shelved change names may not start with '.'")) |
24477
325f03de849d
shelve: add interactive mode command line option
Laurent Charignon <lcharignon@fb.com>
parents:
23895
diff
changeset
|
229 |
interactive = opts.get('interactive', False) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
230 |
|
24478
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
231 |
def interactivecommitfunc(ui, repo, *pats, **opts): |
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
232 |
match = scmutil.match(repo['.'], pats, {}) |
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
233 |
message = opts['message'] |
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
234 |
return commitfunc(ui, repo, message, match, opts) |
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
235 |
if not interactive: |
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
236 |
node = cmdutil.commit(ui, repo, commitfunc, pats, opts) |
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
237 |
else: |
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
238 |
node = cmdutil.dorecord(ui, repo, interactivecommitfunc, 'commit', |
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
239 |
False, cmdutil.recordfilter, *pats, **opts) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
240 |
if not node: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
241 |
stat = repo.status(match=scmutil.match(repo[None], pats, opts)) |
22922
ebef5fcf7bd0
shelve: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22898
diff
changeset
|
242 |
if stat.deleted: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
243 |
ui.status(_("nothing changed (%d missing files, see " |
22922
ebef5fcf7bd0
shelve: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22898
diff
changeset
|
244 |
"'hg status')\n") % len(stat.deleted)) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
245 |
else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
246 |
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
|
247 |
return 1 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
248 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
249 |
bases = list(publicancestors(repo[node])) |
20927
24a443948627
localrepo: move the changegroupsubset method in changegroup module
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
20413
diff
changeset
|
250 |
cg = changegroup.changegroupsubset(repo, bases, [node], 'shelve') |
20983
2778616de7ce
shelve: add "writebundle()" to invoke "writebundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20982
diff
changeset
|
251 |
shelvedfile(repo, name, 'hg').writebundle(cg) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
252 |
cmdutil.export(repo, [node], |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
253 |
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
|
254 |
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
|
255 |
|
19874
5836edcbdc2e
shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents:
19856
diff
changeset
|
256 |
|
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
257 |
if ui.formatted(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
258 |
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
|
259 |
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
|
260 |
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
|
261 |
finally: |
19874
5836edcbdc2e
shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents:
19856
diff
changeset
|
262 |
if bms: |
5836edcbdc2e
shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents:
19856
diff
changeset
|
263 |
# restore old bookmarks |
5836edcbdc2e
shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents:
19856
diff
changeset
|
264 |
repo._bookmarks.update(bms) |
5836edcbdc2e
shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents:
19856
diff
changeset
|
265 |
repo._bookmarks.write() |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
266 |
if tr: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
267 |
tr.abort() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
268 |
lockmod.release(lock, wlock) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
269 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
270 |
def cleanupcmd(ui, repo): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
271 |
"""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
|
272 |
|
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
273 |
wlock = None |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
274 |
try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
275 |
wlock = repo.wlock() |
22199
b3e51675f98e
cleanup: avoid _ for local unused tmp variables - that is reserved for i18n
Mads Kiilerich <madski@unity3d.com>
parents:
22184
diff
changeset
|
276 |
for (name, _type) in repo.vfs.readdir('shelved'): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
277 |
suffix = name.rsplit('.', 1)[-1] |
22581
c5ece02fb211
shelve: avoid writing file that is never read from
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22202
diff
changeset
|
278 |
if suffix in ('hg', 'patch'): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
279 |
shelvedfile(repo, name).unlink() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
280 |
finally: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
281 |
lockmod.release(wlock) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
282 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
283 |
def deletecmd(ui, repo, pats): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
284 |
"""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
|
285 |
if not pats: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
286 |
raise util.Abort(_('no shelved changes specified!')) |
25080
68f456f2f425
shelve: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24947
diff
changeset
|
287 |
wlock = repo.wlock() |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
288 |
try: |
25080
68f456f2f425
shelve: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24947
diff
changeset
|
289 |
for name in pats: |
68f456f2f425
shelve: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24947
diff
changeset
|
290 |
for suffix in 'hg patch'.split(): |
68f456f2f425
shelve: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24947
diff
changeset
|
291 |
shelvedfile(repo, name, suffix).unlink() |
68f456f2f425
shelve: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24947
diff
changeset
|
292 |
except OSError, err: |
68f456f2f425
shelve: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24947
diff
changeset
|
293 |
if err.errno != errno.ENOENT: |
68f456f2f425
shelve: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24947
diff
changeset
|
294 |
raise |
68f456f2f425
shelve: use try/except/finally
Matt Mackall <mpm@selenic.com>
parents:
24947
diff
changeset
|
295 |
raise util.Abort(_("shelved change '%s' not found") % name) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
296 |
finally: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
297 |
lockmod.release(wlock) |
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 listshelves(repo): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
300 |
"""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
|
301 |
try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
302 |
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
|
303 |
except OSError, err: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
304 |
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
|
305 |
raise |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
306 |
return [] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
307 |
info = [] |
22199
b3e51675f98e
cleanup: avoid _ for local unused tmp variables - that is reserved for i18n
Mads Kiilerich <madski@unity3d.com>
parents:
22184
diff
changeset
|
308 |
for (name, _type) in names: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
309 |
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
|
310 |
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
|
311 |
continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
312 |
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
|
313 |
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
|
314 |
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
|
315 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
316 |
def listcmd(ui, repo, pats, opts): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
317 |
"""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
|
318 |
pats = set(pats) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
319 |
width = 80 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
320 |
if not ui.plain(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
321 |
width = ui.termwidth() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
322 |
namelabel = 'shelve.newest' |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
323 |
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
|
324 |
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
|
325 |
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
|
326 |
continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
327 |
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
|
328 |
namelabel = 'shelve.name' |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
329 |
if ui.quiet: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
330 |
ui.write('\n') |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
331 |
continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
332 |
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
|
333 |
used = 16 |
19855
a3b285882724
shelve: new output format for shelve listings
David Soria Parra <dsp@experimentalworks.net>
parents:
19854
diff
changeset
|
334 |
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
|
335 |
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
|
336 |
ui.write(' ' * (12 - len(age))) |
a3b285882724
shelve: new output format for shelve listings
David Soria Parra <dsp@experimentalworks.net>
parents:
19854
diff
changeset
|
337 |
used += 12 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
338 |
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
|
339 |
try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
340 |
while True: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
341 |
line = fp.readline() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
342 |
if not line: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
343 |
break |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
344 |
if not line.startswith('#'): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
345 |
desc = line.rstrip() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
346 |
if ui.formatted(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
347 |
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
|
348 |
ui.write(desc) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
349 |
break |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
350 |
ui.write('\n') |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
351 |
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
|
352 |
continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
353 |
difflines = fp.readlines() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
354 |
if opts['patch']: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
355 |
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
|
356 |
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
|
357 |
if opts['stat']: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
358 |
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
|
359 |
git=True): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
360 |
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
|
361 |
finally: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
362 |
fp.close() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
363 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
364 |
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
|
365 |
"""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
|
366 |
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
|
367 |
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
|
368 |
'state')) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
369 |
|
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
|
370 |
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
|
371 |
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
|
372 |
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
|
373 |
|
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
374 |
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
|
375 |
"""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
|
376 |
wlock = repo.wlock() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
377 |
lock = None |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
378 |
try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
379 |
checkparents(repo, state) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
380 |
|
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
381 |
util.rename(repo.join('unshelverebasestate'), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
382 |
repo.join('rebasestate')) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
383 |
try: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
384 |
rebase.rebase(ui, repo, **{ |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
385 |
'abort' : True |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
386 |
}) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
387 |
except Exception: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
388 |
util.rename(repo.join('rebasestate'), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
389 |
repo.join('unshelverebasestate')) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
390 |
raise |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
391 |
|
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
392 |
lock = repo.lock() |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
393 |
|
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
394 |
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
|
395 |
|
22057
445472225ccd
strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22042
diff
changeset
|
396 |
repair.strip(ui, repo, state.stripnodes, backup=False, topic='shelve') |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
397 |
shelvedstate.clear(repo) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
398 |
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
|
399 |
finally: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
400 |
lockmod.release(lock, wlock) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
401 |
|
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
402 |
def mergefiles(ui, repo, wctx, shelvectx): |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
403 |
"""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
|
404 |
dirstate.""" |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
405 |
oldquiet = ui.quiet |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
406 |
try: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
407 |
ui.quiet = True |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
408 |
hg.update(repo, wctx.node()) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
409 |
files = [] |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
410 |
files.extend(shelvectx.files()) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
411 |
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
|
412 |
|
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
413 |
# revert will overwrite unknown files, so move them out of the way |
22922
ebef5fcf7bd0
shelve: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22898
diff
changeset
|
414 |
for file in repo.status(unknown=True).unknown: |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
415 |
if file in files: |
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
416 |
util.rename(file, file + ".orig") |
22184
fb8065de47b0
unshelve: silence internal revert
Matt Mackall <mpm@selenic.com>
parents:
22057
diff
changeset
|
417 |
ui.pushbuffer(True) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
418 |
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
|
419 |
*pathtofiles(repo, files), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
420 |
**{'no_backup': True}) |
22184
fb8065de47b0
unshelve: silence internal revert
Matt Mackall <mpm@selenic.com>
parents:
22057
diff
changeset
|
421 |
ui.popbuffer() |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
422 |
finally: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
423 |
ui.quiet = oldquiet |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
424 |
|
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
425 |
def unshelvecleanup(ui, repo, name, opts): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
426 |
"""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
|
427 |
if not opts['keep']: |
22581
c5ece02fb211
shelve: avoid writing file that is never read from
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22202
diff
changeset
|
428 |
for filetype in 'hg patch'.split(): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
429 |
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
|
430 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
431 |
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
|
432 |
"""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
|
433 |
# 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
|
434 |
# 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
|
435 |
wlock = repo.wlock() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
436 |
lock = None |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
437 |
try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
438 |
checkparents(repo, state) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
439 |
ms = merge.mergestate(repo) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
440 |
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
|
441 |
raise util.Abort( |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
442 |
_("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
|
443 |
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
|
444 |
|
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
445 |
lock = repo.lock() |
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 |
util.rename(repo.join('unshelverebasestate'), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
448 |
repo.join('rebasestate')) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
449 |
try: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
450 |
rebase.rebase(ui, repo, **{ |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
451 |
'continue' : True |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
452 |
}) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
453 |
except Exception: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
454 |
util.rename(repo.join('rebasestate'), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
455 |
repo.join('unshelverebasestate')) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
456 |
raise |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
457 |
|
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
458 |
shelvectx = repo['tip'] |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
459 |
if not shelvectx in state.pendingctx.children(): |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
460 |
# 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
|
461 |
shelvectx = state.pendingctx |
22842
d43d116a118c
shelve: don't delete "." when rebase is a no-op (issue4398)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21852
diff
changeset
|
462 |
else: |
d43d116a118c
shelve: don't delete "." when rebase is a no-op (issue4398)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21852
diff
changeset
|
463 |
# only strip the shelvectx if the rebase produced it |
d43d116a118c
shelve: don't delete "." when rebase is a no-op (issue4398)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21852
diff
changeset
|
464 |
state.stripnodes.append(shelvectx.node()) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
465 |
|
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
466 |
mergefiles(ui, repo, state.wctx, shelvectx) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
467 |
|
22057
445472225ccd
strip: remove -b/--backup codepaths
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
22042
diff
changeset
|
468 |
repair.strip(ui, repo, state.stripnodes, backup=False, topic='shelve') |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
469 |
shelvedstate.clear(repo) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
470 |
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
|
471 |
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
|
472 |
finally: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
473 |
lockmod.release(lock, wlock) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
474 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
475 |
@command('unshelve', |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
476 |
[('a', 'abort', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
477 |
_('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
|
478 |
('c', 'continue', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
479 |
_('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
|
480 |
('', 'keep', None, |
20960
8e5b21ce8ee9
shelve: introduce secret option for using fixed date for temporary commit
Mads Kiilerich <madski@unity3d.com>
parents:
20958
diff
changeset
|
481 |
_('keep shelve after unshelving')), |
8e5b21ce8ee9
shelve: introduce secret option for using fixed date for temporary commit
Mads Kiilerich <madski@unity3d.com>
parents:
20958
diff
changeset
|
482 |
('', 'date', '', |
8e5b21ce8ee9
shelve: introduce secret option for using fixed date for temporary commit
Mads Kiilerich <madski@unity3d.com>
parents:
20958
diff
changeset
|
483 |
_('set date for temporary commits (DEPRECATED)'), _('DATE'))], |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
484 |
_('hg unshelve [SHELVED]')) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
485 |
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
|
486 |
"""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
|
487 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
488 |
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
|
489 |
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
|
490 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
491 |
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
|
492 |
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
|
493 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
494 |
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
|
495 |
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
|
496 |
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
|
497 |
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
|
498 |
``--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
|
499 |
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
|
500 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
501 |
(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
|
502 |
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
|
503 |
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
|
504 |
""" |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
505 |
abortf = opts['abort'] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
506 |
continuef = opts['continue'] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
507 |
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
|
508 |
cmdutil.checkunfinished(repo) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
509 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
510 |
if abortf or continuef: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
511 |
if abortf and continuef: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
512 |
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
|
513 |
if shelved: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
514 |
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
|
515 |
'naming a shelved change')) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
516 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
517 |
try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
518 |
state = shelvedstate.load(repo) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
519 |
except IOError, err: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
520 |
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
|
521 |
raise |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
522 |
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
|
523 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
524 |
if abortf: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
525 |
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
|
526 |
elif continuef: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
527 |
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
|
528 |
elif len(shelved) > 1: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
529 |
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
|
530 |
elif not shelved: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
531 |
shelved = listshelves(repo) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
532 |
if not shelved: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
533 |
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
|
534 |
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
|
535 |
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
|
536 |
else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
537 |
basename = shelved[0] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
538 |
|
22581
c5ece02fb211
shelve: avoid writing file that is never read from
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22202
diff
changeset
|
539 |
if not shelvedfile(repo, basename, 'patch').exists(): |
19970
065e6f1c9259
shelve: remove unused variable assignment
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19964
diff
changeset
|
540 |
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
|
541 |
|
20412
e584fc30456b
shelve: be quiet when unshelve pulls from the shelve bundle
Mads Kiilerich <madski@unity3d.com>
parents:
20411
diff
changeset
|
542 |
oldquiet = ui.quiet |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
543 |
wlock = lock = tr = None |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
544 |
try: |
24704
03f92741487f
shelve: acquire lock in the right order
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
24478
diff
changeset
|
545 |
wlock = repo.wlock() |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
546 |
lock = repo.lock() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
547 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
548 |
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
|
549 |
oldtiprev = len(repo) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
550 |
|
20958
df33c9014430
shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents:
20942
diff
changeset
|
551 |
pctx = repo['.'] |
df33c9014430
shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents:
20942
diff
changeset
|
552 |
tmpwctx = pctx |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
553 |
# The goal is to have a commit structure like so: |
20958
df33c9014430
shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents:
20942
diff
changeset
|
554 |
# ...-> pctx -> tmpwctx -> shelvectx |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
555 |
# 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
|
556 |
# and shelvectx is the unshelved changes. Then we merge it all down |
20958
df33c9014430
shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents:
20942
diff
changeset
|
557 |
# to the original pctx. |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
558 |
|
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
559 |
# Store pending changes in a commit |
22922
ebef5fcf7bd0
shelve: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22898
diff
changeset
|
560 |
s = repo.status() |
ebef5fcf7bd0
shelve: access status fields by name rather than index
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22898
diff
changeset
|
561 |
if s.modified or s.added or s.removed or s.deleted: |
20413
0ac94c0a3a38
shelve: status messages from unshelve
Mads Kiilerich <madski@unity3d.com>
parents:
20412
diff
changeset
|
562 |
ui.status(_("temporarily committing pending changes " |
0ac94c0a3a38
shelve: status messages from unshelve
Mads Kiilerich <madski@unity3d.com>
parents:
20412
diff
changeset
|
563 |
"(restore with 'hg unshelve --abort')\n")) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
564 |
def commitfunc(ui, repo, message, match, opts): |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
565 |
hasmq = util.safehasattr(repo, 'mq') |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
566 |
if hasmq: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
567 |
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
|
568 |
|
22040
122fa73657c6
shelve: do not retract phase boundary by hand
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22005
diff
changeset
|
569 |
backup = repo.ui.backupconfig('phases', 'new-commit') |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
570 |
try: |
22040
122fa73657c6
shelve: do not retract phase boundary by hand
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22005
diff
changeset
|
571 |
repo.ui. setconfig('phases', 'new-commit', phases.secret) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
572 |
return repo.commit(message, 'shelve@localhost', |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
573 |
opts.get('date'), match) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
574 |
finally: |
22040
122fa73657c6
shelve: do not retract phase boundary by hand
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
22005
diff
changeset
|
575 |
repo.ui.restoreconfig(backup) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
576 |
if hasmq: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
577 |
repo.mq.checkapplied = saved |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
578 |
|
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
579 |
tempopts = {} |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
580 |
tempopts['message'] = "pending changes temporary commit" |
20960
8e5b21ce8ee9
shelve: introduce secret option for using fixed date for temporary commit
Mads Kiilerich <madski@unity3d.com>
parents:
20958
diff
changeset
|
581 |
tempopts['date'] = opts.get('date') |
20412
e584fc30456b
shelve: be quiet when unshelve pulls from the shelve bundle
Mads Kiilerich <madski@unity3d.com>
parents:
20411
diff
changeset
|
582 |
ui.quiet = True |
e584fc30456b
shelve: be quiet when unshelve pulls from the shelve bundle
Mads Kiilerich <madski@unity3d.com>
parents:
20411
diff
changeset
|
583 |
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
|
584 |
tmpwctx = repo[node] |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
585 |
|
20982
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
586 |
ui.quiet = True |
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
587 |
shelvedfile(repo, basename, 'hg').applybundle() |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
588 |
|
20412
e584fc30456b
shelve: be quiet when unshelve pulls from the shelve bundle
Mads Kiilerich <madski@unity3d.com>
parents:
20411
diff
changeset
|
589 |
ui.quiet = oldquiet |
e584fc30456b
shelve: be quiet when unshelve pulls from the shelve bundle
Mads Kiilerich <madski@unity3d.com>
parents:
20411
diff
changeset
|
590 |
|
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
591 |
shelvectx = repo['tip'] |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
592 |
|
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
593 |
# 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
|
594 |
# 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
|
595 |
if tmpwctx.node() != shelvectx.parents()[0].node(): |
20413
0ac94c0a3a38
shelve: status messages from unshelve
Mads Kiilerich <madski@unity3d.com>
parents:
20412
diff
changeset
|
596 |
ui.status(_('rebasing shelved changes\n')) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
597 |
try: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
598 |
rebase.rebase(ui, repo, **{ |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
599 |
'rev' : [shelvectx.rev()], |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
600 |
'dest' : str(tmpwctx.rev()), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
601 |
'keep' : True, |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
602 |
}) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
603 |
except error.InterventionRequired: |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
604 |
tr.close() |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
605 |
|
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
606 |
stripnodes = [repo.changelog.node(rev) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
607 |
for rev in xrange(oldtiprev, len(repo))] |
20958
df33c9014430
shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents:
20942
diff
changeset
|
608 |
shelvedstate.save(repo, basename, pctx, tmpwctx, stripnodes) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
609 |
|
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
610 |
util.rename(repo.join('rebasestate'), |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
611 |
repo.join('unshelverebasestate')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
612 |
raise error.InterventionRequired( |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
613 |
_("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
|
614 |
"'hg unshelve --continue')")) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
615 |
|
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
616 |
# refresh ctx after rebase completes |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
617 |
shelvectx = repo['tip'] |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
618 |
|
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
619 |
if not shelvectx in tmpwctx.children(): |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
620 |
# 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
|
621 |
shelvectx = tmpwctx |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
622 |
|
20958
df33c9014430
shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents:
20942
diff
changeset
|
623 |
mergefiles(ui, repo, pctx, shelvectx) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
624 |
shelvedstate.clear(repo) |
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
625 |
|
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
626 |
# 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
|
627 |
# 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
|
628 |
# 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
|
629 |
# Clean up manually to prevent this. |
20064
99c4b8f79324
shelve: unshelve using an unfiltered repository
David Soria Parra <davidsp@fb.com>
parents:
19970
diff
changeset
|
630 |
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
|
631 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
632 |
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
|
633 |
finally: |
20412
e584fc30456b
shelve: be quiet when unshelve pulls from the shelve bundle
Mads Kiilerich <madski@unity3d.com>
parents:
20411
diff
changeset
|
634 |
ui.quiet = oldquiet |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
635 |
if tr: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
636 |
tr.release() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
637 |
lockmod.release(lock, wlock) |
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 |
@command('shelve', |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
640 |
[('A', 'addremove', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
641 |
_('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
|
642 |
('', 'cleanup', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
643 |
_('delete all shelved changes')), |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
644 |
('', 'date', '', |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
645 |
_('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
|
646 |
('d', 'delete', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
647 |
_('delete the named shelved change(s)')), |
21852
37a5decc6924
shelve: accept '--edit' like other commands creating new changeset
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21851
diff
changeset
|
648 |
('e', 'edit', False, |
37a5decc6924
shelve: accept '--edit' like other commands creating new changeset
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21851
diff
changeset
|
649 |
_('invoke editor on commit messages')), |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
650 |
('l', 'list', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
651 |
_('list current shelves')), |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
652 |
('m', 'message', '', |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
653 |
_('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
|
654 |
('n', 'name', '', |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
655 |
_('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
|
656 |
('p', 'patch', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
657 |
_('show patch')), |
24477
325f03de849d
shelve: add interactive mode command line option
Laurent Charignon <lcharignon@fb.com>
parents:
23895
diff
changeset
|
658 |
('i', 'interactive', None, |
24872
3510ec97ffdc
shelve: make the interactive mode experimental
Laurent Charignon <lcharignon@fb.com>
parents:
24704
diff
changeset
|
659 |
_('interactive mode, only works while creating a shelve' |
3510ec97ffdc
shelve: make the interactive mode experimental
Laurent Charignon <lcharignon@fb.com>
parents:
24704
diff
changeset
|
660 |
'(EXPERIMENTAL)')), |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
661 |
('', 'stat', None, |
20409
0b7a9940a397
shelve: mention walk options in help
Mads Kiilerich <madski@unity3d.com>
parents:
20408
diff
changeset
|
662 |
_('output diffstat-style summary of changes'))] + commands.walkopts, |
20410
fc5354648224
shelve: mention FILE options in help
Mads Kiilerich <madski@unity3d.com>
parents:
20409
diff
changeset
|
663 |
_('hg shelve [OPTION]... [FILE]...')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
664 |
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
|
665 |
'''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
|
666 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
667 |
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
|
668 |
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
|
669 |
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
|
670 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
671 |
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
|
672 |
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
|
673 |
commit. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
674 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
675 |
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
|
676 |
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
|
677 |
those files are shelved. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
678 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
679 |
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
|
680 |
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
|
681 |
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
|
682 |
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
|
683 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
684 |
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
|
685 |
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
|
686 |
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
|
687 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
688 |
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
|
689 |
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
|
690 |
''' |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
691 |
cmdutil.checkunfinished(repo) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
692 |
|
21851
aad28ff87788
shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21064
diff
changeset
|
693 |
allowables = [ |
25103
ce00b2e96d09
shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents:
25080
diff
changeset
|
694 |
('addremove', set(['create'])), # 'create' is pseudo action |
ce00b2e96d09
shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents:
25080
diff
changeset
|
695 |
('cleanup', set(['cleanup'])), |
ce00b2e96d09
shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents:
25080
diff
changeset
|
696 |
# ('date', set(['create'])), # ignored for passing '--date "0 0"' in tests |
ce00b2e96d09
shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents:
25080
diff
changeset
|
697 |
('delete', set(['delete'])), |
ce00b2e96d09
shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents:
25080
diff
changeset
|
698 |
('edit', set(['create'])), |
ce00b2e96d09
shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents:
25080
diff
changeset
|
699 |
('list', set(['list'])), |
ce00b2e96d09
shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents:
25080
diff
changeset
|
700 |
('message', set(['create'])), |
ce00b2e96d09
shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents:
25080
diff
changeset
|
701 |
('name', set(['create'])), |
ce00b2e96d09
shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents:
25080
diff
changeset
|
702 |
('patch', set(['list'])), |
ce00b2e96d09
shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents:
25080
diff
changeset
|
703 |
('stat', set(['list'])), |
21851
aad28ff87788
shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21064
diff
changeset
|
704 |
] |
aad28ff87788
shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21064
diff
changeset
|
705 |
def checkopt(opt): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
706 |
if opts[opt]: |
21851
aad28ff87788
shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21064
diff
changeset
|
707 |
for i, allowable in allowables: |
25103
ce00b2e96d09
shelve: refactor allowables to specify sets of valid operations
Tony Tung <tonytung@fb.com>
parents:
25080
diff
changeset
|
708 |
if opts[i] and opt not in allowable: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
709 |
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
|
710 |
"used together") % (opt, i)) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
711 |
return True |
21851
aad28ff87788
shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21064
diff
changeset
|
712 |
if checkopt('cleanup'): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
713 |
if pats: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
714 |
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
|
715 |
return cleanupcmd(ui, repo) |
21851
aad28ff87788
shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21064
diff
changeset
|
716 |
elif checkopt('delete'): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
717 |
return deletecmd(ui, repo, pats) |
21851
aad28ff87788
shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21064
diff
changeset
|
718 |
elif checkopt('list'): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
719 |
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
|
720 |
else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
721 |
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
|
722 |
if opts[i]: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
723 |
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
|
724 |
"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
|
725 |
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
|
726 |
|
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
727 |
def extsetup(ui): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
728 |
cmdutil.unfinishedstates.append( |
19963
6f29cc567845
shelve: disallow commit while unshelve is in progress
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19961
diff
changeset
|
729 |
[shelvedstate._filename, False, False, |
6f29cc567845
shelve: disallow commit while unshelve is in progress
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19961
diff
changeset
|
730 |
_('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
|
731 |
_("use 'hg unshelve --continue' or 'hg unshelve --abort'")]) |