Mercurial > hg-stable
annotate hgext/shelve.py @ 42536:5f2f6912c9e6
states: moved cmdutil.unfinishedstates to state.py
This moves `cmdutil.unfinishedstates`, `checkunfinished()`,`clearunfinished()`
to `state.py`. the already existing users of this module are updated accordingly.
Test results remain unchanged.
Differential Revision: https://phab.mercurial-scm.org/D6484
author | Taapas Agrawal <taapas2897@gmail.com> |
---|---|
date | Sat, 08 Jun 2019 23:43:53 +0530 |
parents | 9c7f58180878 |
children | dc3fdd1b5af4 |
rev | line source |
---|---|
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1 # shelve.py - save/restore working directory state |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
2 # |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
3 # Copyright 2013 Facebook, Inc. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
4 # |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
7 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
8 """save and restore changes to the working directory |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
9 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
10 The "hg shelve" command saves changes made to the working directory |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
11 and reverts those changes, resetting the working directory to a clean |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
12 state. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
13 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
14 Later on, the "hg unshelve" command restores the changes saved by "hg |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
15 shelve". Changes can be restored even after updating to a different |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
16 parent, in which case Mercurial's merge machinery will resolve any |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
17 conflicts if necessary. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
18 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
19 You can have more than one shelved change outstanding at a time; each |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
20 shelved change has a distinct name. For details, see the help for "hg |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
21 shelve". |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
22 """ |
28378
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
23 from __future__ import absolute_import |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
24 |
25113
0ca8410ea345
util: drop alias for collections.deque
Martin von Zweigbergk <martinvonz@google.com>
parents:
25104
diff
changeset
|
25 import collections |
28378
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
26 import errno |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
27 import itertools |
36789
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36636
diff
changeset
|
28 import stat |
29205
a0939666b836
py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents:
28862
diff
changeset
|
29 |
a0939666b836
py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents:
28862
diff
changeset
|
30 from mercurial.i18n import _ |
28378
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
31 from mercurial import ( |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
32 bookmarks, |
28378
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
33 bundle2, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
34 bundlerepo, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
35 changegroup, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
36 cmdutil, |
34112
f7d41b85bbf6
changegroup: replace changegroupsubset with makechangegroup
Durham Goode <durham@fb.com>
parents:
33440
diff
changeset
|
37 discovery, |
28378
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
38 error, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
39 exchange, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
40 hg, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
41 lock as lockmod, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
42 mdiff, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
43 merge, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
44 node as nodemod, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
45 patch, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
46 phases, |
35046
aad6b9fdfc75
py3: handle keyword arguments in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34496
diff
changeset
|
47 pycompat, |
32376
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32331
diff
changeset
|
48 registrar, |
28378
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
49 repair, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
50 scmutil, |
42536
5f2f6912c9e6
states: moved cmdutil.unfinishedstates to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents:
42325
diff
changeset
|
51 state as statemod, |
28378
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
52 templatefilters, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
53 util, |
31254
636f55b9ba23
vfs: use 'vfs' module directly in 'hgext.shelve'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31113
diff
changeset
|
54 vfs as vfsmod, |
28378
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
55 ) |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
56 |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
57 from . import ( |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
58 rebase, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
59 ) |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36789
diff
changeset
|
60 from mercurial.utils import ( |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36789
diff
changeset
|
61 dateutil, |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36789
diff
changeset
|
62 stringutil, |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36789
diff
changeset
|
63 ) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
64 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
65 cmdtable = {} |
32376
46ba2cdda476
registrar: move cmdutil.command to registrar module (API)
Yuya Nishihara <yuya@tcha.org>
parents:
32331
diff
changeset
|
66 command = registrar.command(cmdtable) |
29852
d5883fd055c6
extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents:
29536
diff
changeset
|
67 # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
25186
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
25113
diff
changeset
|
68 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
25113
diff
changeset
|
69 # be specifying the version(s) of Mercurial they are tested with, or |
80c5b2666a96
extensions: document that `testedwith = 'internal'` is special
Augie Fackler <augie@google.com>
parents:
25113
diff
changeset
|
70 # leave the attribute unspecified. |
29852
d5883fd055c6
extensions: change magic "shipped with hg" string
Augie Fackler <augie@google.com>
parents:
29536
diff
changeset
|
71 testedwith = 'ships-with-hg-core' |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
72 |
34496
18cd210535b3
configitems: register the 'shelve.maxbackups' config
Boris Feld <boris.feld@octobus.net>
parents:
34112
diff
changeset
|
73 configtable = {} |
18cd210535b3
configitems: register the 'shelve.maxbackups' config
Boris Feld <boris.feld@octobus.net>
parents:
34112
diff
changeset
|
74 configitem = registrar.configitem(configtable) |
18cd210535b3
configitems: register the 'shelve.maxbackups' config
Boris Feld <boris.feld@octobus.net>
parents:
34112
diff
changeset
|
75 |
18cd210535b3
configitems: register the 'shelve.maxbackups' config
Boris Feld <boris.feld@octobus.net>
parents:
34112
diff
changeset
|
76 configitem('shelve', 'maxbackups', |
18cd210535b3
configitems: register the 'shelve.maxbackups' config
Boris Feld <boris.feld@octobus.net>
parents:
34112
diff
changeset
|
77 default=10, |
18cd210535b3
configitems: register the 'shelve.maxbackups' config
Boris Feld <boris.feld@octobus.net>
parents:
34112
diff
changeset
|
78 ) |
18cd210535b3
configitems: register the 'shelve.maxbackups' config
Boris Feld <boris.feld@octobus.net>
parents:
34112
diff
changeset
|
79 |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
80 backupdir = 'shelve-backup' |
28862
39130afcce60
shelve: refactor directory name into constant
Oleg Afanasyev <olegaf@fb.com>
parents:
28666
diff
changeset
|
81 shelvedir = 'shelved' |
39399
da121c9dc0f2
shelve: store shelved node in a new data file
Boris Feld <boris.feld@octobus.net>
parents:
39371
diff
changeset
|
82 shelvefileextensions = ['hg', 'patch', 'shelve'] |
30560
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30551
diff
changeset
|
83 # universal extension is present in all types of shelves |
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30551
diff
changeset
|
84 patchextension = 'patch' |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
85 |
30391
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
86 # we never need the user, so we use a |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
87 # generic user for all shelve operations |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
88 shelveuser = 'shelve@localhost' |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
89 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
90 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
|
91 """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
|
92 |
22581
c5ece02fb211
shelve: avoid writing file that is never read from
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22202
diff
changeset
|
93 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
|
94 the vfs layer""" |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
95 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
|
96 self.repo = repo |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
97 self.name = name |
31344
3acc7af5859c
shelve: directly use repo.vfs.join
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31321
diff
changeset
|
98 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir)) |
3acc7af5859c
shelve: directly use repo.vfs.join
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31321
diff
changeset
|
99 self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir)) |
23895
cda18ded2c48
changegroup.writebundle: provide ui
Eric Sumner <ericsumner@fb.com>
parents:
23877
diff
changeset
|
100 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
|
101 if filetype: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
102 self.fname = name + '.' + filetype |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
103 else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
104 self.fname = name |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
105 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
106 def exists(self): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
107 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
|
108 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
109 def filename(self): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
110 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
|
111 |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
112 def backupfilename(self): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
113 def gennames(base): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
114 yield base |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
115 base, ext = base.rsplit('.', 1) |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
116 for i in itertools.count(1): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
117 yield '%s-%d.%s' % (base, i, ext) |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
118 |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
119 name = self.backupvfs.join(self.fname) |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
120 for n in gennames(name): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
121 if not self.backupvfs.exists(n): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
122 return n |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
123 |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
124 def movetobackup(self): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
125 if not self.backupvfs.isdir(): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
126 self.backupvfs.makedir() |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
127 util.rename(self.filename(), self.backupfilename()) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
128 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
129 def stat(self): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
130 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
|
131 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
132 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
|
133 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
134 return self.vfs(self.fname, mode) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25260
diff
changeset
|
135 except IOError as err: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
136 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
|
137 raise |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
138 raise error.Abort(_("shelved change '%s' not found") % self.name) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
139 |
41017
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40872
diff
changeset
|
140 def applybundle(self, tr): |
20982
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
141 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
|
142 try: |
39536
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
143 targetphase = phases.internal |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
144 if not phases.supportinternal(self.repo): |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
145 targetphase = phases.secret |
21064
4d9d490d7bbe
bundle2: add a ui argument to readbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21063
diff
changeset
|
146 gen = exchange.readbundle(self.repo.ui, fp, self.fname, self.vfs) |
39894
d9ba836fc234
shelve: find shelvedctx from bundle even if they are already in the repo
Boris Feld <boris.feld@octobus.net>
parents:
39893
diff
changeset
|
147 pretip = self.repo['tip'] |
d9ba836fc234
shelve: find shelvedctx from bundle even if they are already in the repo
Boris Feld <boris.feld@octobus.net>
parents:
39893
diff
changeset
|
148 bundle2.applybundle(self.repo, gen, tr, |
33055
18c2489ac96d
bundle: make applybundle() delegate v1 bundles to applybundle1()
Martin von Zweigbergk <martinvonz@google.com>
parents:
33051
diff
changeset
|
149 source='unshelve', |
18c2489ac96d
bundle: make applybundle() delegate v1 bundles to applybundle1()
Martin von Zweigbergk <martinvonz@google.com>
parents:
33051
diff
changeset
|
150 url='bundle:' + self.vfs.join(self.fname), |
39536
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
151 targetphase=targetphase) |
39894
d9ba836fc234
shelve: find shelvedctx from bundle even if they are already in the repo
Boris Feld <boris.feld@octobus.net>
parents:
39893
diff
changeset
|
152 shelvectx = self.repo['tip'] |
d9ba836fc234
shelve: find shelvedctx from bundle even if they are already in the repo
Boris Feld <boris.feld@octobus.net>
parents:
39893
diff
changeset
|
153 if pretip == shelvectx: |
d9ba836fc234
shelve: find shelvedctx from bundle even if they are already in the repo
Boris Feld <boris.feld@octobus.net>
parents:
39893
diff
changeset
|
154 shelverev = tr.changes['revduplicates'][-1] |
d9ba836fc234
shelve: find shelvedctx from bundle even if they are already in the repo
Boris Feld <boris.feld@octobus.net>
parents:
39893
diff
changeset
|
155 shelvectx = self.repo[shelverev] |
d9ba836fc234
shelve: find shelvedctx from bundle even if they are already in the repo
Boris Feld <boris.feld@octobus.net>
parents:
39893
diff
changeset
|
156 return shelvectx |
20982
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
157 finally: |
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
158 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
|
159 |
22898
43816070284e
shelve: add a bundlerepo method
Matt Mackall <mpm@selenic.com>
parents:
22844
diff
changeset
|
160 def bundlerepo(self): |
39617
84d6e9a2b104
shelve: use bundlerepo.instance() to construct a repo object
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39536
diff
changeset
|
161 path = self.vfs.join(self.fname) |
84d6e9a2b104
shelve: use bundlerepo.instance() to construct a repo object
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39536
diff
changeset
|
162 return bundlerepo.instance(self.repo.baseui, |
84d6e9a2b104
shelve: use bundlerepo.instance() to construct a repo object
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39536
diff
changeset
|
163 'bundle://%s+%s' % (self.repo.root, path)) |
84d6e9a2b104
shelve: use bundlerepo.instance() to construct a repo object
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39536
diff
changeset
|
164 |
26506
edecf059fda6
shelve: move changegroup generation inside writebundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26505
diff
changeset
|
165 def writebundle(self, bases, node): |
27931
1289a122cf3f
shelve: use cg3 for treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
27921
diff
changeset
|
166 cgversion = changegroup.safeversion(self.repo) |
1289a122cf3f
shelve: use cg3 for treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
27921
diff
changeset
|
167 if cgversion == '01': |
1289a122cf3f
shelve: use cg3 for treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
27921
diff
changeset
|
168 btype = 'HG10BZ' |
1289a122cf3f
shelve: use cg3 for treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
27921
diff
changeset
|
169 compression = None |
1289a122cf3f
shelve: use cg3 for treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
27921
diff
changeset
|
170 else: |
26507
ae29cffa05db
shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26506
diff
changeset
|
171 btype = 'HG20' |
ae29cffa05db
shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26506
diff
changeset
|
172 compression = 'BZ' |
ae29cffa05db
shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26506
diff
changeset
|
173 |
39400
6a71324cb68b
shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
39399
diff
changeset
|
174 repo = self.repo.unfiltered() |
6a71324cb68b
shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
39399
diff
changeset
|
175 |
6a71324cb68b
shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
39399
diff
changeset
|
176 outgoing = discovery.outgoing(repo, missingroots=bases, |
34112
f7d41b85bbf6
changegroup: replace changegroupsubset with makechangegroup
Durham Goode <durham@fb.com>
parents:
33440
diff
changeset
|
177 missingheads=[node]) |
39400
6a71324cb68b
shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
39399
diff
changeset
|
178 cg = changegroup.makechangegroup(repo, outgoing, cgversion, 'shelve') |
34112
f7d41b85bbf6
changegroup: replace changegroupsubset with makechangegroup
Durham Goode <durham@fb.com>
parents:
33440
diff
changeset
|
179 |
28666
ae53ecc47414
bundle: move writebundle() from changegroup.py to bundle2.py (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
28573
diff
changeset
|
180 bundle2.writebundle(self.ui, cg, self.fname, btype, self.vfs, |
26507
ae29cffa05db
shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26506
diff
changeset
|
181 compression=compression) |
20983
2778616de7ce
shelve: add "writebundle()" to invoke "writebundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20982
diff
changeset
|
182 |
39370
bab58b1d87c7
shelve: rename method for data write/read
Boris Feld <boris.feld@octobus.net>
parents:
39369
diff
changeset
|
183 def writeinfo(self, info): |
31560
7485e45807e4
shelve: add an ability to write key-val data to a new type of shelve files
Kostia Balytskyi <ikostia@fb.com>
parents:
31549
diff
changeset
|
184 scmutil.simplekeyvaluefile(self.vfs, self.fname).write(info) |
7485e45807e4
shelve: add an ability to write key-val data to a new type of shelve files
Kostia Balytskyi <ikostia@fb.com>
parents:
31549
diff
changeset
|
185 |
39370
bab58b1d87c7
shelve: rename method for data write/read
Boris Feld <boris.feld@octobus.net>
parents:
39369
diff
changeset
|
186 def readinfo(self): |
31560
7485e45807e4
shelve: add an ability to write key-val data to a new type of shelve files
Kostia Balytskyi <ikostia@fb.com>
parents:
31549
diff
changeset
|
187 return scmutil.simplekeyvaluefile(self.vfs, self.fname).read() |
7485e45807e4
shelve: add an ability to write key-val data to a new type of shelve files
Kostia Balytskyi <ikostia@fb.com>
parents:
31549
diff
changeset
|
188 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
189 class shelvedstate(object): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
190 """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
|
191 |
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
192 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
|
193 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
|
194 """ |
32325
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
195 _version = 2 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
196 _filename = 'shelvedstate' |
30531
7b3136bc7bfd
shelve: make --keep option survive user intervention (issue5431)
Kostia Balytskyi <ikostia@fb.com>
parents:
30466
diff
changeset
|
197 _keep = 'keep' |
7b3136bc7bfd
shelve: make --keep option survive user intervention (issue5431)
Kostia Balytskyi <ikostia@fb.com>
parents:
30466
diff
changeset
|
198 _nokeep = 'nokeep' |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
199 # colon is essential to differentiate from a real bookmark name |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
200 _noactivebook = ':no-active-bookmark' |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
201 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
202 @classmethod |
32325
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
203 def _verifyandtransform(cls, d): |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
204 """Some basic shelvestate syntactic verification and transformation""" |
19904
5b327880a660
shelve: drop pickle usage
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19887
diff
changeset
|
205 try: |
32324
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
206 d['originalwctx'] = nodemod.bin(d['originalwctx']) |
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
207 d['pendingctx'] = nodemod.bin(d['pendingctx']) |
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
208 d['parents'] = [nodemod.bin(h) |
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
209 for h in d['parents'].split(' ')] |
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
210 d['nodestoremove'] = [nodemod.bin(h) |
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
211 for h in d['nodestoremove'].split(' ')] |
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
212 except (ValueError, TypeError, KeyError) as err: |
36526
7af7443877da
py3: replace str() with it's bytes equivalent in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36223
diff
changeset
|
213 raise error.CorruptedState(pycompat.bytestr(err)) |
32324
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
214 |
32325
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
215 @classmethod |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
216 def _getversion(cls, repo): |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
217 """Read version information from shelvestate file""" |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
218 fp = repo.vfs(cls._filename) |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
219 try: |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
220 version = int(fp.readline().strip()) |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
221 except ValueError as err: |
36526
7af7443877da
py3: replace str() with it's bytes equivalent in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36223
diff
changeset
|
222 raise error.CorruptedState(pycompat.bytestr(err)) |
32325
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
223 finally: |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
224 fp.close() |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
225 return version |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
226 |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
227 @classmethod |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
228 def _readold(cls, repo): |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
229 """Read the old position-based version of a shelvestate file""" |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
230 # Order is important, because old shelvestate file uses it |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
231 # to detemine values of fields (i.g. name is on the second line, |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
232 # originalwctx is on the third and so forth). Please do not change. |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
233 keys = ['version', 'name', 'originalwctx', 'pendingctx', 'parents', |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
234 'nodestoremove', 'branchtorestore', 'keep', 'activebook'] |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
235 # this is executed only seldomly, so it is not a big deal |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
236 # that we open this file twice |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
237 fp = repo.vfs(cls._filename) |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
238 d = {} |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
239 try: |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
240 for key in keys: |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
241 d[key] = fp.readline().strip() |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
242 finally: |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
243 fp.close() |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
244 return d |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
245 |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
246 @classmethod |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
247 def load(cls, repo): |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
248 version = cls._getversion(repo) |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
249 if version < cls._version: |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
250 d = cls._readold(repo) |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
251 elif version == cls._version: |
41768
aaad36b88298
cleanup: use () to wrap long lines instead of \
Augie Fackler <augie@google.com>
parents:
41609
diff
changeset
|
252 d = scmutil.simplekeyvaluefile( |
aaad36b88298
cleanup: use () to wrap long lines instead of \
Augie Fackler <augie@google.com>
parents:
41609
diff
changeset
|
253 repo.vfs, cls._filename).read(firstlinenonkeyval=True) |
32325
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
254 else: |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
255 raise error.Abort(_('this version of shelve is incompatible ' |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
256 'with the version used in this repo')) |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
257 |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
258 cls._verifyandtransform(d) |
29536
b17a6e3cd2ac
shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents:
29270
diff
changeset
|
259 try: |
b17a6e3cd2ac
shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents:
29270
diff
changeset
|
260 obj = cls() |
32324
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
261 obj.name = d['name'] |
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
262 obj.wctx = repo[d['originalwctx']] |
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
263 obj.pendingctx = repo[d['pendingctx']] |
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
264 obj.parents = d['parents'] |
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
265 obj.nodestoremove = d['nodestoremove'] |
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
266 obj.branchtorestore = d.get('branchtorestore', '') |
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
267 obj.keep = d.get('keep') == cls._keep |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
268 obj.activebookmark = '' |
32324
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
269 if d.get('activebook', '') != cls._noactivebook: |
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
270 obj.activebookmark = d.get('activebook', '') |
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
271 except (error.RepoLookupError, KeyError) as err: |
36526
7af7443877da
py3: replace str() with it's bytes equivalent in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36223
diff
changeset
|
272 raise error.CorruptedState(pycompat.bytestr(err)) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
273 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
274 return obj |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
275 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
276 @classmethod |
31888
1c398f7f4aa4
shelve: rename nodestoprune to nodestoremove
Kostia Balytskyi <ikostia@fb.com>
parents:
31762
diff
changeset
|
277 def save(cls, repo, name, originalwctx, pendingctx, nodestoremove, |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
278 branchtorestore, keep=False, activebook=''): |
32325
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
279 info = { |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
280 "name": name, |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
281 "originalwctx": nodemod.hex(originalwctx.node()), |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
282 "pendingctx": nodemod.hex(pendingctx.node()), |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
283 "parents": ' '.join([nodemod.hex(p) |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
284 for p in repo.dirstate.parents()]), |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
285 "nodestoremove": ' '.join([nodemod.hex(n) |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
286 for n in nodestoremove]), |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
287 "branchtorestore": branchtorestore, |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
288 "keep": cls._keep if keep else cls._nokeep, |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
289 "activebook": activebook or cls._noactivebook |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
290 } |
41768
aaad36b88298
cleanup: use () to wrap long lines instead of \
Augie Fackler <augie@google.com>
parents:
41609
diff
changeset
|
291 scmutil.simplekeyvaluefile( |
aaad36b88298
cleanup: use () to wrap long lines instead of \
Augie Fackler <augie@google.com>
parents:
41609
diff
changeset
|
292 repo.vfs, cls._filename).write(info, |
aaad36b88298
cleanup: use () to wrap long lines instead of \
Augie Fackler <augie@google.com>
parents:
41609
diff
changeset
|
293 firstline=("%d" % cls._version)) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
294 |
19908
07ee5c8867ca
shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19904
diff
changeset
|
295 @classmethod |
07ee5c8867ca
shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19904
diff
changeset
|
296 def clear(cls, repo): |
31320
f59b6cf663a9
vfs: use repo.vfs.unlinkpath
Mads Kiilerich <mads@kiilerich.com>
parents:
31254
diff
changeset
|
297 repo.vfs.unlinkpath(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
|
298 |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
299 def cleanupoldbackups(repo): |
31344
3acc7af5859c
shelve: directly use repo.vfs.join
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31321
diff
changeset
|
300 vfs = vfsmod.vfs(repo.vfs.join(backupdir)) |
34496
18cd210535b3
configitems: register the 'shelve.maxbackups' config
Boris Feld <boris.feld@octobus.net>
parents:
34112
diff
changeset
|
301 maxbackups = repo.ui.configint('shelve', 'maxbackups') |
30560
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30551
diff
changeset
|
302 hgfiles = [f for f in vfs.listdir() |
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30551
diff
changeset
|
303 if f.endswith('.' + patchextension)] |
36789
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36636
diff
changeset
|
304 hgfiles = sorted([(vfs.stat(f)[stat.ST_MTIME], f) for f in hgfiles]) |
40030
e2697acd9381
cleanup: some Yoda conditions, this patch removes
Martin von Zweigbergk <martinvonz@google.com>
parents:
39894
diff
changeset
|
305 if maxbackups > 0 and maxbackups < len(hgfiles): |
25774
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
306 bordermtime = hgfiles[-maxbackups][0] |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
307 else: |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
308 bordermtime = None |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
309 for mtime, f in hgfiles[:len(hgfiles) - maxbackups]: |
25774
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
310 if mtime == bordermtime: |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
311 # keep it, because timestamp can't decide exact order of backups |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
312 continue |
30560
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30551
diff
changeset
|
313 base = f[:-(1 + len(patchextension))] |
30388
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29852
diff
changeset
|
314 for ext in shelvefileextensions: |
31549 | 315 vfs.tryunlink(base + '.' + ext) |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
316 |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
317 def _backupactivebookmark(repo): |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
318 activebookmark = repo._activebookmark |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
319 if activebookmark: |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
320 bookmarks.deactivate(repo) |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
321 return activebookmark |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
322 |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
323 def _restoreactivebookmark(repo, mark): |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
324 if mark: |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
325 bookmarks.activate(repo, mark) |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
326 |
41017
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40872
diff
changeset
|
327 def _aborttransaction(repo, tr): |
26522
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
328 '''Abort current transaction for shelve/unshelve, but keep dirstate |
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
329 ''' |
38908
ad24b581e4d9
narrow: call narrowspec.{save,restore,clear}backup directly
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
330 dirstatebackupname = 'dirstate.shelve' |
ad24b581e4d9
narrow: call narrowspec.{save,restore,clear}backup directly
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
331 repo.dirstate.savebackup(tr, dirstatebackupname) |
29270
48b38b16a8f8
shelve: use backup functions instead of manually copying dirstate
Mateusz Kwapich <mitrandir@fb.com>
parents:
29205
diff
changeset
|
332 tr.abort() |
38908
ad24b581e4d9
narrow: call narrowspec.{save,restore,clear}backup directly
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
333 repo.dirstate.restorebackup(None, dirstatebackupname) |
26522
10f14bb22950
shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26520
diff
changeset
|
334 |
30389
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
335 def getshelvename(repo, parent, opts): |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
336 """Decide on the name this shelve is going to have""" |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
337 def gennames(): |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
338 yield label |
32986
4107eb8a5648
shelve: allow unlimited shelved changes per name
Jun Wu <quark@fb.com>
parents:
32948
diff
changeset
|
339 for i in itertools.count(1): |
30389
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
340 yield '%s-%02d' % (label, i) |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
341 name = opts.get('name') |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
342 label = repo._activebookmark or parent.branch() or 'default' |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
343 # slashes aren't allowed in filenames, therefore we rename it |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
344 label = label.replace('/', '_') |
30674
64a75655b988
shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30560
diff
changeset
|
345 label = label.replace('\\', '_') |
64a75655b988
shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30560
diff
changeset
|
346 # filenames must not start with '.' as it should not be hidden |
64a75655b988
shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30560
diff
changeset
|
347 if label.startswith('.'): |
64a75655b988
shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30560
diff
changeset
|
348 label = label.replace('.', '_', 1) |
30389
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
349 |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
350 if name: |
30560
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30551
diff
changeset
|
351 if shelvedfile(repo, name, patchextension).exists(): |
30389
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
352 e = _("a shelved change named '%s' already exists") % name |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
353 raise error.Abort(e) |
30674
64a75655b988
shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30560
diff
changeset
|
354 |
64a75655b988
shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30560
diff
changeset
|
355 # ensure we are not creating a subdirectory or a hidden file |
64a75655b988
shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30560
diff
changeset
|
356 if '/' in name or '\\' in name: |
64a75655b988
shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30560
diff
changeset
|
357 raise error.Abort(_('shelved change names can not contain slashes')) |
64a75655b988
shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30560
diff
changeset
|
358 if name.startswith('.'): |
64a75655b988
shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30560
diff
changeset
|
359 raise error.Abort(_("shelved change names can not start with '.'")) |
64a75655b988
shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30560
diff
changeset
|
360 |
30389
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
361 else: |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
362 for n in gennames(): |
30560
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30551
diff
changeset
|
363 if not shelvedfile(repo, n, patchextension).exists(): |
30389
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
364 name = n |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
365 break |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
366 |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
367 return name |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
368 |
30390
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
369 def mutableancestors(ctx): |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
370 """return all mutable ancestors for ctx (included) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
371 |
30390
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
372 Much faster than the revset ancestors(ctx) & draft()""" |
32331
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
32325
diff
changeset
|
373 seen = {nodemod.nullrev} |
30390
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
374 visit = collections.deque() |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
375 visit.append(ctx) |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
376 while visit: |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
377 ctx = visit.popleft() |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
378 yield ctx.node() |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
379 for parent in ctx.parents(): |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
380 rev = parent.rev() |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
381 if rev not in seen: |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
382 seen.add(rev) |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
383 if parent.mutable(): |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
384 visit.append(parent) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
385 |
30391
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
386 def getcommitfunc(extra, interactive, editor=False): |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
387 def commitfunc(ui, repo, message, match, opts): |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
388 hasmq = util.safehasattr(repo, 'mq') |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
389 if hasmq: |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
390 saved, repo.mq.checkapplied = repo.mq.checkapplied, False |
39536
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
391 |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
392 targetphase = phases.internal |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
393 if not phases.supportinternal(repo): |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
394 targetphase = phases.secret |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
395 overrides = {('phases', 'new-commit'): targetphase} |
30391
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
396 try: |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
397 editor_ = False |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
398 if editor: |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
399 editor_ = cmdutil.getcommiteditor(editform='shelve.shelve', |
35046
aad6b9fdfc75
py3: handle keyword arguments in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34496
diff
changeset
|
400 **pycompat.strkwargs(opts)) |
31471 | 401 with repo.ui.configoverride(overrides): |
402 return repo.commit(message, shelveuser, opts.get('date'), | |
403 match, editor=editor_, extra=extra) | |
30391
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
404 finally: |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
405 if hasmq: |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
406 repo.mq.checkapplied = saved |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
407 |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
408 def interactivecommitfunc(ui, repo, *pats, **opts): |
35046
aad6b9fdfc75
py3: handle keyword arguments in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34496
diff
changeset
|
409 opts = pycompat.byteskwargs(opts) |
30391
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
410 match = scmutil.match(repo['.'], pats, {}) |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
411 message = opts['message'] |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
412 return commitfunc(ui, repo, message, match, opts) |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
413 |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
414 return interactivecommitfunc if interactive else commitfunc |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
415 |
30392
dedf0915ca5b
shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30391
diff
changeset
|
416 def _nothingtoshelvemessaging(ui, repo, pats, opts): |
dedf0915ca5b
shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30391
diff
changeset
|
417 stat = repo.status(match=scmutil.match(repo[None], pats, opts)) |
dedf0915ca5b
shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30391
diff
changeset
|
418 if stat.deleted: |
dedf0915ca5b
shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30391
diff
changeset
|
419 ui.status(_("nothing changed (%d missing files, see " |
dedf0915ca5b
shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30391
diff
changeset
|
420 "'hg status')\n") % len(stat.deleted)) |
dedf0915ca5b
shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30391
diff
changeset
|
421 else: |
dedf0915ca5b
shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30391
diff
changeset
|
422 ui.status(_("nothing changed\n")) |
dedf0915ca5b
shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30391
diff
changeset
|
423 |
42012
9b78bbb76111
shelve: refactor _shelvecreatedcommit's match object into calling site
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42011
diff
changeset
|
424 def _shelvecreatedcommit(repo, node, name, match): |
39399
da121c9dc0f2
shelve: store shelved node in a new data file
Boris Feld <boris.feld@octobus.net>
parents:
39371
diff
changeset
|
425 info = {'node': nodemod.hex(node)} |
da121c9dc0f2
shelve: store shelved node in a new data file
Boris Feld <boris.feld@octobus.net>
parents:
39371
diff
changeset
|
426 shelvedfile(repo, name, 'shelve').writeinfo(info) |
30393
455f7856db20
shelve: move actual created commit shelving to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30392
diff
changeset
|
427 bases = list(mutableancestors(repo[node])) |
455f7856db20
shelve: move actual created commit shelving to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30392
diff
changeset
|
428 shelvedfile(repo, name, 'hg').writebundle(bases, node) |
37603
678d760c71ff
export: extract function to write patch to file object (API)
Yuya Nishihara <yuya@tcha.org>
parents:
37087
diff
changeset
|
429 with shelvedfile(repo, name, patchextension).opener('wb') as fp: |
40672
29e4a77b5305
shelve: use matcher to restrict prefetch to just the modified files
Kyle Lippincott <spectral@google.com>
parents:
40366
diff
changeset
|
430 cmdutil.exportfile(repo, [node], fp, opts=mdiff.diffopts(git=True), |
29e4a77b5305
shelve: use matcher to restrict prefetch to just the modified files
Kyle Lippincott <spectral@google.com>
parents:
40366
diff
changeset
|
431 match=match) |
30393
455f7856db20
shelve: move actual created commit shelving to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30392
diff
changeset
|
432 |
30394
21a75b63c10e
shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30393
diff
changeset
|
433 def _includeunknownfiles(repo, pats, opts, extra): |
21a75b63c10e
shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30393
diff
changeset
|
434 s = repo.status(match=scmutil.match(repo[None], pats, opts), |
21a75b63c10e
shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30393
diff
changeset
|
435 unknown=True) |
21a75b63c10e
shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30393
diff
changeset
|
436 if s.unknown: |
21a75b63c10e
shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30393
diff
changeset
|
437 extra['shelve_unknown'] = '\0'.join(s.unknown) |
21a75b63c10e
shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30393
diff
changeset
|
438 repo[None].add(s.unknown) |
21a75b63c10e
shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30393
diff
changeset
|
439 |
41017
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40872
diff
changeset
|
440 def _finishshelve(repo, tr): |
39760
52dfa1eb0ad4
shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents:
39617
diff
changeset
|
441 if phases.supportinternal(repo): |
52dfa1eb0ad4
shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents:
39617
diff
changeset
|
442 tr.close() |
52dfa1eb0ad4
shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents:
39617
diff
changeset
|
443 else: |
41017
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40872
diff
changeset
|
444 _aborttransaction(repo, tr) |
30395
b573d7ca31c4
shelve: move shelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30394
diff
changeset
|
445 |
39369
d52fa7ddd1ac
shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents:
38908
diff
changeset
|
446 def createcmd(ui, repo, pats, opts): |
d52fa7ddd1ac
shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents:
38908
diff
changeset
|
447 """subcommand that creates a new shelve""" |
d52fa7ddd1ac
shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents:
38908
diff
changeset
|
448 with repo.wlock(): |
d52fa7ddd1ac
shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents:
38908
diff
changeset
|
449 cmdutil.checkunfinished(repo) |
d52fa7ddd1ac
shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents:
38908
diff
changeset
|
450 return _docreatecmd(ui, repo, pats, opts) |
d52fa7ddd1ac
shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents:
38908
diff
changeset
|
451 |
30390
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
452 def _docreatecmd(ui, repo, pats, opts): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
453 wctx = repo[None] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
454 parents = wctx.parents() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
455 if len(parents) > 1: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
456 raise error.Abort(_('cannot shelve while merging')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
457 parent = parents[0] |
28571
3f0e25e89e28
shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28401
diff
changeset
|
458 origbranch = wctx.branch() |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
459 |
28378
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
460 if parent.node() != nodemod.nullid: |
27092
156985f2dec0
shelve: use colon instead of quotes in 'changes to' description
Siddharth Agarwal <sid0@fb.com>
parents:
27021
diff
changeset
|
461 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
|
462 else: |
20411
66359d8b8d7e
shelve: add 'changes to' prefix to default shelve message
Mads Kiilerich <madski@unity3d.com>
parents:
20410
diff
changeset
|
463 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
|
464 |
28401
2565fe39a76c
shelve: changes getting opts values by get method
liscju <piotr.listkiewicz@gmail.com>
parents:
28378
diff
changeset
|
465 if not opts.get('message'): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
466 opts['message'] = desc |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
467 |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
468 lock = tr = activebookmark = None |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
469 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
470 lock = repo.lock() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
471 |
19951
d51c4d85ec23
spelling: random spell checker fixes
Mads Kiilerich <madski@unity3d.com>
parents:
19943
diff
changeset
|
472 # 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
|
473 # pull races. ensure we don't print the abort message to stderr. |
40872
236af7cfa4c3
shelve: change transaction description from "commit" to "shelve"
Martin von Zweigbergk <martinvonz@google.com>
parents:
40871
diff
changeset
|
474 tr = repo.transaction('shelve', report=lambda x: None) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
475 |
24477
325f03de849d
shelve: add interactive mode command line option
Laurent Charignon <lcharignon@fb.com>
parents:
23895
diff
changeset
|
476 interactive = opts.get('interactive', False) |
27908
d73a5ab18015
shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents:
27888
diff
changeset
|
477 includeunknown = (opts.get('unknown', False) and |
d73a5ab18015
shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents:
27888
diff
changeset
|
478 not opts.get('addremove', False)) |
d73a5ab18015
shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents:
27888
diff
changeset
|
479 |
30389
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
480 name = getshelvename(repo, parent, opts) |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
481 activebookmark = _backupactivebookmark(repo) |
39403
5f8282f368b2
shelve: add an "internal" extra
Boris Feld <boris.feld@octobus.net>
parents:
39402
diff
changeset
|
482 extra = {'internal': 'shelve'} |
27908
d73a5ab18015
shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents:
27888
diff
changeset
|
483 if includeunknown: |
30394
21a75b63c10e
shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30393
diff
changeset
|
484 _includeunknownfiles(repo, pats, opts, extra) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
485 |
28572
43c204ddf333
shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents:
28571
diff
changeset
|
486 if _iswctxonnewbranch(repo) and not _isbareshelve(pats, opts): |
43c204ddf333
shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents:
28571
diff
changeset
|
487 # In non-bare shelve we don't store newly created branch |
43c204ddf333
shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents:
28571
diff
changeset
|
488 # at bundled commit |
43c204ddf333
shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents:
28571
diff
changeset
|
489 repo.dirstate.setbranch(repo['.'].branch()) |
43c204ddf333
shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents:
28571
diff
changeset
|
490 |
30391
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
491 commitfunc = getcommitfunc(extra, interactive, editor=True) |
24478
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
492 if not interactive: |
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
493 node = cmdutil.commit(ui, repo, commitfunc, pats, opts) |
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
494 else: |
30391
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
495 node = cmdutil.dorecord(ui, repo, commitfunc, None, |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
496 False, cmdutil.recordfilter, *pats, |
35046
aad6b9fdfc75
py3: handle keyword arguments in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34496
diff
changeset
|
497 **pycompat.strkwargs(opts)) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
498 if not node: |
30392
dedf0915ca5b
shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30391
diff
changeset
|
499 _nothingtoshelvemessaging(ui, repo, pats, opts) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
500 return 1 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
501 |
42012
9b78bbb76111
shelve: refactor _shelvecreatedcommit's match object into calling site
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42011
diff
changeset
|
502 # Create a matcher so that prefetch doesn't attempt to fetch |
42013
50d5e64ec561
shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42012
diff
changeset
|
503 # the entire repository pointlessly, and as an optimisation |
50d5e64ec561
shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42012
diff
changeset
|
504 # for movedirstate, if needed. |
42012
9b78bbb76111
shelve: refactor _shelvecreatedcommit's match object into calling site
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42011
diff
changeset
|
505 match = scmutil.matchfiles(repo, repo[node].files()) |
9b78bbb76111
shelve: refactor _shelvecreatedcommit's match object into calling site
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42011
diff
changeset
|
506 _shelvecreatedcommit(repo, node, name, match) |
19874
5836edcbdc2e
shelve: copy bookmarks and restore them after a commit
David Soria Parra <dsp@experimentalworks.net>
parents:
19856
diff
changeset
|
507 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
508 if ui.formatted(): |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36789
diff
changeset
|
509 desc = stringutil.ellipsis(desc, ui.termwidth()) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
510 ui.status(_('shelved as %s\n') % name) |
42013
50d5e64ec561
shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42012
diff
changeset
|
511 if opts['keep']: |
50d5e64ec561
shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42012
diff
changeset
|
512 with repo.dirstate.parentchange(): |
50d5e64ec561
shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42012
diff
changeset
|
513 scmutil.movedirstate(repo, parent, match) |
50d5e64ec561
shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42012
diff
changeset
|
514 else: |
50d5e64ec561
shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42012
diff
changeset
|
515 hg.update(repo, parent.node()) |
28571
3f0e25e89e28
shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28401
diff
changeset
|
516 if origbranch != repo['.'].branch() and not _isbareshelve(pats, opts): |
3f0e25e89e28
shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28401
diff
changeset
|
517 repo.dirstate.setbranch(origbranch) |
26523
1d23bf6cd90a
shelve: restore shelved dirstate explicitly after aborting transaction
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
26522
diff
changeset
|
518 |
41017
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40872
diff
changeset
|
519 _finishshelve(repo, tr) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
520 finally: |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
521 _restoreactivebookmark(repo, activebookmark) |
27197
6df3ec5bb813
shelve: widen wlock scope of shelve for consistency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27092
diff
changeset
|
522 lockmod.release(tr, lock) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
523 |
28571
3f0e25e89e28
shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28401
diff
changeset
|
524 def _isbareshelve(pats, opts): |
3f0e25e89e28
shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28401
diff
changeset
|
525 return (not pats |
3f0e25e89e28
shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28401
diff
changeset
|
526 and not opts.get('interactive', False) |
3f0e25e89e28
shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28401
diff
changeset
|
527 and not opts.get('include', False) |
3f0e25e89e28
shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28401
diff
changeset
|
528 and not opts.get('exclude', False)) |
3f0e25e89e28
shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28401
diff
changeset
|
529 |
28572
43c204ddf333
shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents:
28571
diff
changeset
|
530 def _iswctxonnewbranch(repo): |
43c204ddf333
shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents:
28571
diff
changeset
|
531 return repo[None].branch() != repo['.'].branch() |
43c204ddf333
shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents:
28571
diff
changeset
|
532 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
533 def cleanupcmd(ui, repo): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
534 """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
|
535 |
27835
c448d7e00bf9
with: use context manager for wlock in shelve cleanupcmd
Bryan O'Sullivan <bryano@fb.com>
parents:
27834
diff
changeset
|
536 with repo.wlock(): |
28862
39130afcce60
shelve: refactor directory name into constant
Oleg Afanasyev <olegaf@fb.com>
parents:
28666
diff
changeset
|
537 for (name, _type) in repo.vfs.readdir(shelvedir): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
538 suffix = name.rsplit('.', 1)[-1] |
30388
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29852
diff
changeset
|
539 if suffix in shelvefileextensions: |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
540 shelvedfile(repo, name).movetobackup() |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
541 cleanupoldbackups(repo) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
542 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
543 def deletecmd(ui, repo, pats): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
544 """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
|
545 if not pats: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
546 raise error.Abort(_('no shelved changes specified!')) |
27836
1c2408c28aff
with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents:
27835
diff
changeset
|
547 with repo.wlock(): |
1c2408c28aff
with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents:
27835
diff
changeset
|
548 try: |
1c2408c28aff
with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents:
27835
diff
changeset
|
549 for name in pats: |
30388
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29852
diff
changeset
|
550 for suffix in shelvefileextensions: |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29852
diff
changeset
|
551 shfile = shelvedfile(repo, name, suffix) |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29852
diff
changeset
|
552 # patch file is necessary, as it should |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29852
diff
changeset
|
553 # be present for any kind of shelve, |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29852
diff
changeset
|
554 # but the .hg file is optional as in future we |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29852
diff
changeset
|
555 # will add obsolete shelve with does not create a |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29852
diff
changeset
|
556 # bundle |
30560
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30551
diff
changeset
|
557 if shfile.exists() or suffix == patchextension: |
30388
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29852
diff
changeset
|
558 shfile.movetobackup() |
27836
1c2408c28aff
with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents:
27835
diff
changeset
|
559 cleanupoldbackups(repo) |
1c2408c28aff
with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents:
27835
diff
changeset
|
560 except OSError as err: |
1c2408c28aff
with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents:
27835
diff
changeset
|
561 if err.errno != errno.ENOENT: |
1c2408c28aff
with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents:
27835
diff
changeset
|
562 raise |
1c2408c28aff
with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents:
27835
diff
changeset
|
563 raise error.Abort(_("shelved change '%s' not found") % name) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
564 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
565 def listshelves(repo): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
566 """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
|
567 try: |
28862
39130afcce60
shelve: refactor directory name into constant
Oleg Afanasyev <olegaf@fb.com>
parents:
28666
diff
changeset
|
568 names = repo.vfs.readdir(shelvedir) |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25260
diff
changeset
|
569 except OSError as err: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
570 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
|
571 raise |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
572 return [] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
573 info = [] |
22199
b3e51675f98e
cleanup: avoid _ for local unused tmp variables - that is reserved for i18n
Mads Kiilerich <madski@unity3d.com>
parents:
22184
diff
changeset
|
574 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
|
575 pfx, sfx = name.rsplit('.', 1) |
30560
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30551
diff
changeset
|
576 if not pfx or sfx != patchextension: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
577 continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
578 st = shelvedfile(repo, name).stat() |
36789
ffa3026d4196
cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents:
36636
diff
changeset
|
579 info.append((st[stat.ST_MTIME], shelvedfile(repo, pfx).filename())) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
580 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
|
581 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
582 def listcmd(ui, repo, pats, opts): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
583 """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
|
584 pats = set(pats) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
585 width = 80 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
586 if not ui.plain(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
587 width = ui.termwidth() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
588 namelabel = 'shelve.newest' |
31113
356937ea7a02
pager: add support to --patch, --list and --stat options of hg shelve
Pulkit Goyal <7895pulkit@gmail.com>
parents:
31041
diff
changeset
|
589 ui.pager('shelve') |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
590 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
|
591 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
|
592 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
|
593 continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
594 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
|
595 namelabel = 'shelve.name' |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
596 if ui.quiet: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
597 ui.write('\n') |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
598 continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
599 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
|
600 used = 16 |
36636
c6061cadb400
util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents:
36526
diff
changeset
|
601 date = dateutil.makedate(mtime) |
c6061cadb400
util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents:
36526
diff
changeset
|
602 age = '(%s)' % templatefilters.age(date, abbrev=True) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
603 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
|
604 ui.write(' ' * (12 - len(age))) |
a3b285882724
shelve: new output format for shelve listings
David Soria Parra <dsp@experimentalworks.net>
parents:
19854
diff
changeset
|
605 used += 12 |
30560
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30551
diff
changeset
|
606 with open(name + '.' + patchextension, 'rb') as fp: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
607 while True: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
608 line = fp.readline() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
609 if not line: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
610 break |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
611 if not line.startswith('#'): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
612 desc = line.rstrip() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
613 if ui.formatted(): |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36789
diff
changeset
|
614 desc = stringutil.ellipsis(desc, width - used) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
615 ui.write(desc) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
616 break |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
617 ui.write('\n') |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
618 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
|
619 continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
620 difflines = fp.readlines() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
621 if opts['patch']: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
622 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
|
623 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
|
624 if opts['stat']: |
30417
e1677cc29da6
patch: remove unused git parameter from patch.diffstat()
Henning Schild <henning@hennsch.de>
parents:
30395
diff
changeset
|
625 for chunk, label in patch.diffstatui(difflines, width=width): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
626 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
|
627 |
38715
905b66681004
shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents:
38714
diff
changeset
|
628 def patchcmds(ui, repo, pats, opts): |
30823
806a830e6612
shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30674
diff
changeset
|
629 """subcommand that displays shelves""" |
806a830e6612
shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30674
diff
changeset
|
630 if len(pats) == 0: |
38715
905b66681004
shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents:
38714
diff
changeset
|
631 shelves = listshelves(repo) |
905b66681004
shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents:
38714
diff
changeset
|
632 if not shelves: |
905b66681004
shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents:
38714
diff
changeset
|
633 raise error.Abort(_("there are no shelves to show")) |
905b66681004
shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents:
38714
diff
changeset
|
634 mtime, name = shelves[0] |
905b66681004
shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents:
38714
diff
changeset
|
635 sname = util.split(name)[1] |
905b66681004
shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents:
38714
diff
changeset
|
636 pats = [sname] |
25104
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
637 |
30823
806a830e6612
shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30674
diff
changeset
|
638 for shelfname in pats: |
806a830e6612
shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30674
diff
changeset
|
639 if not shelvedfile(repo, shelfname, patchextension).exists(): |
806a830e6612
shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30674
diff
changeset
|
640 raise error.Abort(_("cannot find shelf %s") % shelfname) |
25104
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
641 |
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
642 listcmd(ui, repo, pats, opts) |
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
643 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
644 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
|
645 """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
|
646 if state.parents != repo.dirstate.parents(): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
647 raise error.Abort(_('working directory parents do not match unshelve ' |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
648 'state')) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
649 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
650 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
|
651 """subcommand that abort an in-progress unshelve""" |
27841
83995fdde225
with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents:
27838
diff
changeset
|
652 with repo.lock(): |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
653 try: |
27841
83995fdde225
with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents:
27838
diff
changeset
|
654 checkparents(repo, state) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
655 |
40366
b14fdf1fb615
update: clarify update() call sites by specifying argument names
Martin von Zweigbergk <martinvonz@google.com>
parents:
40293
diff
changeset
|
656 merge.update(repo, state.pendingctx, branchmerge=False, force=True) |
38466
61e4cf1be5b2
shelve: directly handle the abort process
Boris Feld <boris.feld@octobus.net>
parents:
38011
diff
changeset
|
657 if (state.activebookmark |
61e4cf1be5b2
shelve: directly handle the abort process
Boris Feld <boris.feld@octobus.net>
parents:
38011
diff
changeset
|
658 and state.activebookmark in repo._bookmarks): |
61e4cf1be5b2
shelve: directly handle the abort process
Boris Feld <boris.feld@octobus.net>
parents:
38011
diff
changeset
|
659 bookmarks.activate(repo, state.activebookmark) |
61e4cf1be5b2
shelve: directly handle the abort process
Boris Feld <boris.feld@octobus.net>
parents:
38011
diff
changeset
|
660 |
61e4cf1be5b2
shelve: directly handle the abort process
Boris Feld <boris.feld@octobus.net>
parents:
38011
diff
changeset
|
661 if repo.vfs.exists('unshelverebasestate'): |
61e4cf1be5b2
shelve: directly handle the abort process
Boris Feld <boris.feld@octobus.net>
parents:
38011
diff
changeset
|
662 repo.vfs.rename('unshelverebasestate', 'rebasestate') |
61e4cf1be5b2
shelve: directly handle the abort process
Boris Feld <boris.feld@octobus.net>
parents:
38011
diff
changeset
|
663 rebase.clearstatus(repo) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
664 |
27841
83995fdde225
with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents:
27838
diff
changeset
|
665 mergefiles(ui, repo, state.wctx, state.pendingctx) |
39760
52dfa1eb0ad4
shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents:
39617
diff
changeset
|
666 if not phases.supportinternal(repo): |
52dfa1eb0ad4
shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents:
39617
diff
changeset
|
667 repair.strip(ui, repo, state.nodestoremove, backup=False, |
52dfa1eb0ad4
shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents:
39617
diff
changeset
|
668 topic='shelve') |
27841
83995fdde225
with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents:
27838
diff
changeset
|
669 finally: |
83995fdde225
with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents:
27838
diff
changeset
|
670 shelvedstate.clear(repo) |
83995fdde225
with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents:
27838
diff
changeset
|
671 ui.warn(_("unshelve of '%s' aborted\n") % state.name) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
672 |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
673 def mergefiles(ui, repo, wctx, shelvectx): |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
674 """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
|
675 dirstate.""" |
31762
473f2fcc7629
shelve: move ui.quiet manipulations to configoverride
Kostia Balytskyi <ikostia@fb.com>
parents:
31669
diff
changeset
|
676 with ui.configoverride({('ui', 'quiet'): True}): |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
677 hg.update(repo, wctx.node()) |
22184
fb8065de47b0
unshelve: silence internal revert
Matt Mackall <mpm@selenic.com>
parents:
22057
diff
changeset
|
678 ui.pushbuffer(True) |
42038
e08559769bc6
shelve: let cmdutil.revert() take care of backing up untracked files
Martin von Zweigbergk <martinvonz@google.com>
parents:
42037
diff
changeset
|
679 cmdutil.revert(ui, repo, shelvectx, repo.dirstate.parents()) |
22184
fb8065de47b0
unshelve: silence internal revert
Matt Mackall <mpm@selenic.com>
parents:
22057
diff
changeset
|
680 ui.popbuffer() |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
681 |
28573
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
682 def restorebranch(ui, repo, branchtorestore): |
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
683 if branchtorestore and branchtorestore != repo.dirstate.branch(): |
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
684 repo.dirstate.setbranch(branchtorestore) |
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
685 ui.status(_('marked working directory as branch %s\n') |
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
686 % branchtorestore) |
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
687 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
688 def unshelvecleanup(ui, repo, name, opts): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
689 """remove related files after an unshelve""" |
28401
2565fe39a76c
shelve: changes getting opts values by get method
liscju <piotr.listkiewicz@gmail.com>
parents:
28378
diff
changeset
|
690 if not opts.get('keep'): |
30388
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29852
diff
changeset
|
691 for filetype in shelvefileextensions: |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29852
diff
changeset
|
692 shfile = shelvedfile(repo, name, filetype) |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29852
diff
changeset
|
693 if shfile.exists(): |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29852
diff
changeset
|
694 shfile.movetobackup() |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
695 cleanupoldbackups(repo) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
696 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
697 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
|
698 """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
|
699 # 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
|
700 # parent, second is the temporary "fake" commit we're unshelving. |
27838
60b850b7e4ef
with: use context manager for lock in continue
Bryan O'Sullivan <bryano@fb.com>
parents:
27837
diff
changeset
|
701 with repo.lock(): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
702 checkparents(repo, state) |
26992
b3b5ed560283
shelve: switch to mergestate.read()
Siddharth Agarwal <sid0@fb.com>
parents:
26942
diff
changeset
|
703 ms = merge.mergestate.read(repo) |
33313
ea03b3223611
shelve: don't reimplement mergestate.unresolved()
Martin von Zweigbergk <martinvonz@google.com>
parents:
33055
diff
changeset
|
704 if list(ms.unresolved()): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
705 raise error.Abort( |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
706 _("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
|
707 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
|
708 |
38467
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
709 shelvectx = repo[state.parents[1]] |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
710 pendingctx = state.pendingctx |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
711 |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
712 with repo.dirstate.parentchange(): |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
713 repo.setparents(state.pendingctx.node(), nodemod.nullid) |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
714 repo.dirstate.write(repo.currenttransaction()) |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
715 |
39536
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
716 targetphase = phases.internal |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
717 if not phases.supportinternal(repo): |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
718 targetphase = phases.secret |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
719 overrides = {('phases', 'new-commit'): targetphase} |
38467
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
720 with repo.ui.configoverride(overrides, 'unshelve'): |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
721 with repo.dirstate.parentchange(): |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
722 repo.setparents(state.parents[0], nodemod.nullid) |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
723 newnode = repo.commit(text=shelvectx.description(), |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
724 extra=shelvectx.extra(), |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
725 user=shelvectx.user(), |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
726 date=shelvectx.date()) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
727 |
38467
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
728 if newnode is None: |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
729 # If it ended up being a no-op commit, then the normal |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
730 # merge state clean-up path doesn't happen, so do it |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
731 # here. Fix issue5494 |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
732 merge.mergestate.clean(repo) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
733 shelvectx = state.pendingctx |
38467
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
734 msg = _('note: unshelved changes already existed ' |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
735 'in the working copy\n') |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
736 ui.status(msg) |
22842
d43d116a118c
shelve: don't delete "." when rebase is a no-op (issue4398)
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
21852
diff
changeset
|
737 else: |
38467
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
738 # only strip the shelvectx if we produced one |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
739 state.nodestoremove.append(newnode) |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
740 shelvectx = repo[newnode] |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
741 |
38512
39db5a01cd53
cleanup: pass in overwrite flag to hg.updaterepo() as named argument
Yuya Nishihara <yuya@tcha.org>
parents:
38467
diff
changeset
|
742 hg.updaterepo(repo, pendingctx.node(), overwrite=False) |
38467
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
743 |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
744 if repo.vfs.exists('unshelverebasestate'): |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
745 repo.vfs.rename('unshelverebasestate', 'rebasestate') |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
746 rebase.clearstatus(repo) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
747 |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
748 mergefiles(ui, repo, state.wctx, shelvectx) |
28573
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
749 restorebranch(ui, repo, state.branchtorestore) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
750 |
39760
52dfa1eb0ad4
shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents:
39617
diff
changeset
|
751 if not phases.supportinternal(repo): |
52dfa1eb0ad4
shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents:
39617
diff
changeset
|
752 repair.strip(ui, repo, state.nodestoremove, backup=False, |
52dfa1eb0ad4
shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents:
39617
diff
changeset
|
753 topic='shelve') |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
754 _restoreactivebookmark(repo, state.activebookmark) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
755 shelvedstate.clear(repo) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
756 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
|
757 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
|
758 |
30462
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
759 def _commitworkingcopychanges(ui, repo, opts, tmpwctx): |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
760 """Temporarily commit working copy changes before moving unshelve commit""" |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
761 # Store pending changes in a commit and remember added in case a shelve |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
762 # contains unknown files that are part of the pending change |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
763 s = repo.status() |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
764 addedbefore = frozenset(s.added) |
30846
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
765 if not (s.modified or s.added or s.removed): |
30462
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
766 return tmpwctx, addedbefore |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
767 ui.status(_("temporarily committing pending changes " |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
768 "(restore with 'hg unshelve --abort')\n")) |
39403
5f8282f368b2
shelve: add an "internal" extra
Boris Feld <boris.feld@octobus.net>
parents:
39402
diff
changeset
|
769 extra = {'internal': 'shelve'} |
5f8282f368b2
shelve: add an "internal" extra
Boris Feld <boris.feld@octobus.net>
parents:
39402
diff
changeset
|
770 commitfunc = getcommitfunc(extra=extra, interactive=False, |
30462
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
771 editor=False) |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
772 tempopts = {} |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
773 tempopts['message'] = "pending changes temporary commit" |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
774 tempopts['date'] = opts.get('date') |
31762
473f2fcc7629
shelve: move ui.quiet manipulations to configoverride
Kostia Balytskyi <ikostia@fb.com>
parents:
31669
diff
changeset
|
775 with ui.configoverride({('ui', 'quiet'): True}): |
473f2fcc7629
shelve: move ui.quiet manipulations to configoverride
Kostia Balytskyi <ikostia@fb.com>
parents:
31669
diff
changeset
|
776 node = cmdutil.commit(ui, repo, commitfunc, [], tempopts) |
30462
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
777 tmpwctx = repo[node] |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
778 return tmpwctx, addedbefore |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
779 |
41017
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40872
diff
changeset
|
780 def _unshelverestorecommit(ui, repo, tr, basename): |
30463
672026aece64
shelve: move commit restoration logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30462
diff
changeset
|
781 """Recreate commit in the repository during the unshelve""" |
39400
6a71324cb68b
shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
39399
diff
changeset
|
782 repo = repo.unfiltered() |
39414
da84cca65036
shelve: fix crash on unshelve without .shelve metadata file
Yuya Nishihara <yuya@tcha.org>
parents:
39403
diff
changeset
|
783 node = None |
39401
c67c94c0e7ae
shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents:
39400
diff
changeset
|
784 if shelvedfile(repo, basename, 'shelve').exists(): |
c67c94c0e7ae
shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents:
39400
diff
changeset
|
785 node = shelvedfile(repo, basename, 'shelve').readinfo()['node'] |
c67c94c0e7ae
shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents:
39400
diff
changeset
|
786 if node is None or node not in repo: |
c67c94c0e7ae
shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents:
39400
diff
changeset
|
787 with ui.configoverride({('ui', 'quiet'): True}): |
41017
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40872
diff
changeset
|
788 shelvectx = shelvedfile(repo, basename, 'hg').applybundle(tr) |
39402
38373da1af02
shelve: write metadata file on the fly if they are missing
Boris Feld <boris.feld@octobus.net>
parents:
39401
diff
changeset
|
789 # We might not strip the unbundled changeset, so we should keep track of |
38373da1af02
shelve: write metadata file on the fly if they are missing
Boris Feld <boris.feld@octobus.net>
parents:
39401
diff
changeset
|
790 # the unshelve node in case we need to reuse it (eg: unshelve --keep) |
38373da1af02
shelve: write metadata file on the fly if they are missing
Boris Feld <boris.feld@octobus.net>
parents:
39401
diff
changeset
|
791 if node is None: |
39414
da84cca65036
shelve: fix crash on unshelve without .shelve metadata file
Yuya Nishihara <yuya@tcha.org>
parents:
39403
diff
changeset
|
792 info = {'node': nodemod.hex(shelvectx.node())} |
39402
38373da1af02
shelve: write metadata file on the fly if they are missing
Boris Feld <boris.feld@octobus.net>
parents:
39401
diff
changeset
|
793 shelvedfile(repo, basename, 'shelve').writeinfo(info) |
39401
c67c94c0e7ae
shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents:
39400
diff
changeset
|
794 else: |
c67c94c0e7ae
shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents:
39400
diff
changeset
|
795 shelvectx = repo[node] |
c67c94c0e7ae
shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents:
39400
diff
changeset
|
796 |
30463
672026aece64
shelve: move commit restoration logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30462
diff
changeset
|
797 return repo, shelvectx |
672026aece64
shelve: move commit restoration logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30462
diff
changeset
|
798 |
30464
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30463
diff
changeset
|
799 def _rebaserestoredcommit(ui, repo, opts, tr, oldtiprev, basename, pctx, |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
800 tmpwctx, shelvectx, branchtorestore, |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
801 activebookmark): |
30464
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30463
diff
changeset
|
802 """Rebase restored commit from its original location to a destination""" |
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30463
diff
changeset
|
803 # If the shelve is not immediately on top of the commit |
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30463
diff
changeset
|
804 # we'll be merging with, rebase it to be on top. |
41419
0bd56c291359
cleanup: use p1() and p2() instead of parents()[0] and parents()[1]
Martin von Zweigbergk <martinvonz@google.com>
parents:
41018
diff
changeset
|
805 if tmpwctx.node() == shelvectx.p1().node(): |
30464
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30463
diff
changeset
|
806 return shelvectx |
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30463
diff
changeset
|
807 |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
808 overrides = { |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
809 ('ui', 'forcemerge'): opts.get('tool', ''), |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
810 ('phases', 'new-commit'): phases.secret, |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
811 } |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
812 with repo.ui.configoverride(overrides, 'unshelve'): |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
813 ui.status(_('rebasing shelved changes\n')) |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
814 stats = merge.graft(repo, shelvectx, shelvectx.p1(), |
38619
9b077e5fa8ba
shelve: use more accurate description in conflict marker
Boris Feld <boris.feld@octobus.net>
parents:
38618
diff
changeset
|
815 labels=['shelve', 'working-copy'], |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
816 keepconflictparent=True) |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
817 if stats.unresolvedcount: |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
818 tr.close() |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
819 |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
820 nodestoremove = [repo.changelog.node(rev) |
38823
e7aa113b14f7
global: use pycompat.xrange()
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38715
diff
changeset
|
821 for rev in pycompat.xrange(oldtiprev, len(repo))] |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
822 shelvedstate.save(repo, basename, pctx, tmpwctx, nodestoremove, |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
823 branchtorestore, opts.get('keep'), activebookmark) |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
824 raise error.InterventionRequired( |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
825 _("unresolved conflicts (see 'hg resolve', then " |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
826 "'hg unshelve --continue')")) |
30464
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30463
diff
changeset
|
827 |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
828 with repo.dirstate.parentchange(): |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
829 repo.setparents(tmpwctx.node(), nodemod.nullid) |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
830 newnode = repo.commit(text=shelvectx.description(), |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
831 extra=shelvectx.extra(), |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
832 user=shelvectx.user(), |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
833 date=shelvectx.date()) |
30464
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30463
diff
changeset
|
834 |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
835 if newnode is None: |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
836 # If it ended up being a no-op commit, then the normal |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
837 # merge state clean-up path doesn't happen, so do it |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
838 # here. Fix issue5494 |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
839 merge.mergestate.clean(repo) |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
840 shelvectx = tmpwctx |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
841 msg = _('note: unshelved changes already existed ' |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
842 'in the working copy\n') |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
843 ui.status(msg) |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
844 else: |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
845 shelvectx = repo[newnode] |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
846 hg.updaterepo(repo, tmpwctx.node(), False) |
30464
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30463
diff
changeset
|
847 |
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30463
diff
changeset
|
848 return shelvectx |
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30463
diff
changeset
|
849 |
30465
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30464
diff
changeset
|
850 def _forgetunknownfiles(repo, shelvectx, addedbefore): |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30464
diff
changeset
|
851 # Forget any files that were unknown before the shelve, unknown before |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30464
diff
changeset
|
852 # unshelve started, but are now added. |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30464
diff
changeset
|
853 shelveunknown = shelvectx.extra().get('shelve_unknown') |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30464
diff
changeset
|
854 if not shelveunknown: |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30464
diff
changeset
|
855 return |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30464
diff
changeset
|
856 shelveunknown = frozenset(shelveunknown.split('\0')) |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30464
diff
changeset
|
857 addedafter = frozenset(repo.status().added) |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30464
diff
changeset
|
858 toforget = (addedafter & shelveunknown) - addedbefore |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30464
diff
changeset
|
859 repo[None].forget(toforget) |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30464
diff
changeset
|
860 |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
861 def _finishunshelve(repo, oldtiprev, tr, activebookmark): |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
862 _restoreactivebookmark(repo, activebookmark) |
30466
893be22cdb38
shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30465
diff
changeset
|
863 # The transaction aborting will strip all the commits for us, |
893be22cdb38
shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30465
diff
changeset
|
864 # but it doesn't update the inmemory structures, so addchangegroup |
893be22cdb38
shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30465
diff
changeset
|
865 # hooks still fire and try to operate on the missing commits. |
893be22cdb38
shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30465
diff
changeset
|
866 # Clean up manually to prevent this. |
893be22cdb38
shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30465
diff
changeset
|
867 repo.unfiltered().changelog.strip(oldtiprev, tr) |
41017
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40872
diff
changeset
|
868 _aborttransaction(repo, tr) |
30466
893be22cdb38
shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30465
diff
changeset
|
869 |
30846
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
870 def _checkunshelveuntrackedproblems(ui, repo, shelvectx): |
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
871 """Check potential problems which may result from working |
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
872 copy having untracked changes.""" |
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
873 wcdeleted = set(repo.status().deleted) |
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
874 shelvetouched = set(shelvectx.files()) |
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
875 intersection = wcdeleted.intersection(shelvetouched) |
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
876 if intersection: |
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
877 m = _("shelved change touches missing files") |
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
878 hint = _("run hg status to see which files are missing") |
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
879 raise error.Abort(m, hint=hint) |
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
880 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
881 @command('unshelve', |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
882 [('a', 'abort', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
883 _('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
|
884 ('c', 'continue', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
885 _('continue an incomplete unshelve operation')), |
27019
5cf184398ee7
unshelve: add -k as short form of --keep
Siddharth Agarwal <sid0@fb.com>
parents:
26992
diff
changeset
|
886 ('k', 'keep', None, |
20960
8e5b21ce8ee9
shelve: introduce secret option for using fixed date for temporary commit
Mads Kiilerich <madski@unity3d.com>
parents:
20958
diff
changeset
|
887 _('keep shelve after unshelving')), |
31041
4189d790e8a4
shelve: add -n/--name option to unshelve (issue5475)
liscju <piotr.listkiewicz@gmail.com>
parents:
30846
diff
changeset
|
888 ('n', 'name', '', |
4189d790e8a4
shelve: add -n/--name option to unshelve (issue5475)
liscju <piotr.listkiewicz@gmail.com>
parents:
30846
diff
changeset
|
889 _('restore shelved change with given name'), _('NAME')), |
27021
f2554154509f
unshelve: add support for custom merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
27020
diff
changeset
|
890 ('t', 'tool', '', _('specify merge tool')), |
20960
8e5b21ce8ee9
shelve: introduce secret option for using fixed date for temporary commit
Mads Kiilerich <madski@unity3d.com>
parents:
20958
diff
changeset
|
891 ('', 'date', '', |
8e5b21ce8ee9
shelve: introduce secret option for using fixed date for temporary commit
Mads Kiilerich <madski@unity3d.com>
parents:
20958
diff
changeset
|
892 _('set date for temporary commits (DEPRECATED)'), _('DATE'))], |
40293
c303d65d2e34
help: assigning categories to existing commands
rdamazio@google.com
parents:
40030
diff
changeset
|
893 _('hg unshelve [[-n] SHELVED]'), |
c303d65d2e34
help: assigning categories to existing commands
rdamazio@google.com
parents:
40030
diff
changeset
|
894 helpcategory=command.CATEGORY_WORKING_DIRECTORY) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
895 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
|
896 """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
|
897 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
898 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
|
899 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
|
900 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
901 If a shelved change is applied successfully, the bundle that |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
902 contains the shelved changes is moved to a backup location |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
903 (.hg/shelve-backup). |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
904 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
905 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
|
906 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
|
907 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
|
908 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
|
909 ``--continue`` to complete the unshelve operation. (The bundle |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
910 will not be moved until you successfully complete the unshelve.) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
911 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
912 (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
|
913 that causes a conflict. This reverts the unshelved changes, and |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
914 leaves the bundle in place.) |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
915 |
42325
9c7f58180878
unshelve: add space to help
timeless <timeless@mozdev.org>
parents:
42050
diff
changeset
|
916 If bare shelved change (when no files are specified, without interactive, |
28573
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
917 include and exclude option) was done on newly created branch it would |
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
918 restore branch information to the working directory. |
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
919 |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
920 After a successful unshelve, the shelved changes are stored in a |
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
921 backup directory. Only the N most recent backups are kept. N |
25852
870e361e049c
shelve: make maxbackup doc check-config friendly
Matt Mackall <mpm@selenic.com>
parents:
25799
diff
changeset
|
922 defaults to 10 but can be overridden using the ``shelve.maxbackups`` |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
923 configuration option. |
25774
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
924 |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
925 .. container:: verbose |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
926 |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
927 Timestamp in seconds is used to decide order of backups. More |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
928 than ``maxbackups`` backups are kept, if same timestamp |
4f8c20fe66f0
shelve: keep old backups if timestamp can't decide exact order of them
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
25713
diff
changeset
|
929 prevents from deciding exact order of them, for safety. |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
930 """ |
27837
496ca4deddc5
with: use context manager for wlock in unshelve
Bryan O'Sullivan <bryano@fb.com>
parents:
27836
diff
changeset
|
931 with repo.wlock(): |
27287
c9ceea3f2d8e
shelve: widen wlock scope of unshelve for consistency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27198
diff
changeset
|
932 return _dounshelve(ui, repo, *shelved, **opts) |
c9ceea3f2d8e
shelve: widen wlock scope of unshelve for consistency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27198
diff
changeset
|
933 |
c9ceea3f2d8e
shelve: widen wlock scope of unshelve for consistency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27198
diff
changeset
|
934 def _dounshelve(ui, repo, *shelved, **opts): |
35046
aad6b9fdfc75
py3: handle keyword arguments in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34496
diff
changeset
|
935 opts = pycompat.byteskwargs(opts) |
28401
2565fe39a76c
shelve: changes getting opts values by get method
liscju <piotr.listkiewicz@gmail.com>
parents:
28378
diff
changeset
|
936 abortf = opts.get('abort') |
2565fe39a76c
shelve: changes getting opts values by get method
liscju <piotr.listkiewicz@gmail.com>
parents:
28378
diff
changeset
|
937 continuef = opts.get('continue') |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
938 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
|
939 cmdutil.checkunfinished(repo) |
31041
4189d790e8a4
shelve: add -n/--name option to unshelve (issue5475)
liscju <piotr.listkiewicz@gmail.com>
parents:
30846
diff
changeset
|
940 shelved = list(shelved) |
4189d790e8a4
shelve: add -n/--name option to unshelve (issue5475)
liscju <piotr.listkiewicz@gmail.com>
parents:
30846
diff
changeset
|
941 if opts.get("name"): |
4189d790e8a4
shelve: add -n/--name option to unshelve (issue5475)
liscju <piotr.listkiewicz@gmail.com>
parents:
30846
diff
changeset
|
942 shelved.append(opts["name"]) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
943 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
944 if abortf or continuef: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
945 if abortf and continuef: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
946 raise error.Abort(_('cannot use both abort and continue')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
947 if shelved: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
948 raise error.Abort(_('cannot combine abort/continue with ' |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
949 'naming a shelved change')) |
27021
f2554154509f
unshelve: add support for custom merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
27020
diff
changeset
|
950 if abortf and opts.get('tool', False): |
f2554154509f
unshelve: add support for custom merge tools
Siddharth Agarwal <sid0@fb.com>
parents:
27020
diff
changeset
|
951 ui.warn(_('tool option will be ignored\n')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
952 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
953 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
954 state = shelvedstate.load(repo) |
30531
7b3136bc7bfd
shelve: make --keep option survive user intervention (issue5431)
Kostia Balytskyi <ikostia@fb.com>
parents:
30466
diff
changeset
|
955 if opts.get('keep') is None: |
7b3136bc7bfd
shelve: make --keep option survive user intervention (issue5431)
Kostia Balytskyi <ikostia@fb.com>
parents:
30466
diff
changeset
|
956 opts['keep'] = state.keep |
25660
328739ea70c3
global: mass rewrite to use modern exception syntax
Gregory Szorc <gregory.szorc@gmail.com>
parents:
25260
diff
changeset
|
957 except IOError as err: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
958 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
|
959 raise |
28124
983365382465
shelve: suggest the correct tool to continue (not unshelve)
timeless <timeless@mozdev.org>
parents:
27931
diff
changeset
|
960 cmdutil.wrongtooltocontinue(repo, _('unshelve')) |
29536
b17a6e3cd2ac
shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents:
29270
diff
changeset
|
961 except error.CorruptedState as err: |
36526
7af7443877da
py3: replace str() with it's bytes equivalent in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
36223
diff
changeset
|
962 ui.debug(pycompat.bytestr(err) + '\n') |
29536
b17a6e3cd2ac
shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents:
29270
diff
changeset
|
963 if continuef: |
b17a6e3cd2ac
shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents:
29270
diff
changeset
|
964 msg = _('corrupted shelved state file') |
b17a6e3cd2ac
shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents:
29270
diff
changeset
|
965 hint = _('please run hg unshelve --abort to abort unshelve ' |
b17a6e3cd2ac
shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents:
29270
diff
changeset
|
966 'operation') |
b17a6e3cd2ac
shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents:
29270
diff
changeset
|
967 raise error.Abort(msg, hint=hint) |
b17a6e3cd2ac
shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents:
29270
diff
changeset
|
968 elif abortf: |
b17a6e3cd2ac
shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents:
29270
diff
changeset
|
969 msg = _('could not read shelved state file, your working copy ' |
b17a6e3cd2ac
shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents:
29270
diff
changeset
|
970 'may be in an unexpected state\nplease update to some ' |
b17a6e3cd2ac
shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents:
29270
diff
changeset
|
971 'commit\n') |
b17a6e3cd2ac
shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents:
29270
diff
changeset
|
972 ui.warn(msg) |
b17a6e3cd2ac
shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents:
29270
diff
changeset
|
973 shelvedstate.clear(repo) |
b17a6e3cd2ac
shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents:
29270
diff
changeset
|
974 return |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
975 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
976 if abortf: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
977 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
|
978 elif continuef: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
979 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
|
980 elif len(shelved) > 1: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
981 raise error.Abort(_('can only unshelve one change at a time')) |
42050
03f6480bfdda
unshelve: disable unshelve during merge (issue5123)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42038
diff
changeset
|
982 |
03f6480bfdda
unshelve: disable unshelve during merge (issue5123)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42038
diff
changeset
|
983 # abort unshelve while merging (issue5123) |
03f6480bfdda
unshelve: disable unshelve during merge (issue5123)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42038
diff
changeset
|
984 parents = repo[None].parents() |
03f6480bfdda
unshelve: disable unshelve during merge (issue5123)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42038
diff
changeset
|
985 if len(parents) > 1: |
03f6480bfdda
unshelve: disable unshelve during merge (issue5123)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42038
diff
changeset
|
986 raise error.Abort(_('cannot unshelve while merging')) |
03f6480bfdda
unshelve: disable unshelve during merge (issue5123)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42038
diff
changeset
|
987 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
988 elif not shelved: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
989 shelved = listshelves(repo) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
990 if not shelved: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
991 raise error.Abort(_('no shelved changes to apply!')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
992 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
|
993 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
|
994 else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
995 basename = shelved[0] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
996 |
30560
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30551
diff
changeset
|
997 if not shelvedfile(repo, basename, patchextension).exists(): |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
998 raise error.Abort(_("shelved change '%s' not found") % basename) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
999 |
39400
6a71324cb68b
shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
39399
diff
changeset
|
1000 repo = repo.unfiltered() |
27287
c9ceea3f2d8e
shelve: widen wlock scope of unshelve for consistency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27198
diff
changeset
|
1001 lock = tr = None |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1002 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1003 lock = repo.lock() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1004 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
|
1005 oldtiprev = len(repo) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
1006 |
20958
df33c9014430
shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents:
20942
diff
changeset
|
1007 pctx = repo['.'] |
df33c9014430
shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents:
20942
diff
changeset
|
1008 tmpwctx = pctx |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
1009 # 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
|
1010 # ...-> pctx -> tmpwctx -> shelvectx |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
1011 # 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
|
1012 # 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
|
1013 # to the original pctx. |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
1014 |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
1015 activebookmark = _backupactivebookmark(repo) |
38011
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1016 tmpwctx, addedbefore = _commitworkingcopychanges(ui, repo, opts, |
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1017 tmpwctx) |
41017
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40872
diff
changeset
|
1018 repo, shelvectx = _unshelverestorecommit(ui, repo, tr, basename) |
38011
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1019 _checkunshelveuntrackedproblems(ui, repo, shelvectx) |
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1020 branchtorestore = '' |
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1021 if shelvectx.branch() != shelvectx.p1().branch(): |
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1022 branchtorestore = shelvectx.branch() |
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1023 |
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1024 shelvectx = _rebaserestoredcommit(ui, repo, opts, tr, oldtiprev, |
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1025 basename, pctx, tmpwctx, |
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1026 shelvectx, branchtorestore, |
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1027 activebookmark) |
31471 | 1028 overrides = {('ui', 'forcemerge'): opts.get('tool', '')} |
1029 with ui.configoverride(overrides, 'unshelve'): | |
38011
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1030 mergefiles(ui, repo, pctx, shelvectx) |
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1031 restorebranch(ui, repo, branchtorestore) |
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1032 _forgetunknownfiles(repo, shelvectx, addedbefore) |
27908
d73a5ab18015
shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents:
27888
diff
changeset
|
1033 |
38011
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1034 shelvedstate.clear(repo) |
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1035 _finishunshelve(repo, oldtiprev, tr, activebookmark) |
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1036 unshelvecleanup(ui, repo, basename, opts) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1037 finally: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1038 if tr: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1039 tr.release() |
27287
c9ceea3f2d8e
shelve: widen wlock scope of unshelve for consistency while processing
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
27198
diff
changeset
|
1040 lockmod.release(lock) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1041 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1042 @command('shelve', |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1043 [('A', 'addremove', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1044 _('mark new/missing files as added/removed before shelving')), |
27908
d73a5ab18015
shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents:
27888
diff
changeset
|
1045 ('u', 'unknown', None, |
27921
158bdc896572
shelve: lowercase flag description
timeless <timeless@mozdev.org>
parents:
27908
diff
changeset
|
1046 _('store unknown files in the shelve')), |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1047 ('', 'cleanup', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1048 _('delete all shelved changes')), |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1049 ('', 'date', '', |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1050 _('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
|
1051 ('d', 'delete', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1052 _('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
|
1053 ('e', 'edit', False, |
37a5decc6924
shelve: accept '--edit' like other commands creating new changeset
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21851
diff
changeset
|
1054 _('invoke editor on commit messages')), |
42011
22278dae287c
shelve: new keep option
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
41768
diff
changeset
|
1055 ('k', 'keep', False, |
22278dae287c
shelve: new keep option
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
41768
diff
changeset
|
1056 _('shelve, but keep changes in the working directory')), |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1057 ('l', 'list', None, |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1058 _('list current shelves')), |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1059 ('m', 'message', '', |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1060 _('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
|
1061 ('n', 'name', '', |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1062 _('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
|
1063 ('p', 'patch', None, |
38714
abcf500d527c
shelve: improve help text for --patch and --stat
Danny Hooper <hooper@google.com>
parents:
38619
diff
changeset
|
1064 _('output patches for changes (provide the names of the shelved ' |
abcf500d527c
shelve: improve help text for --patch and --stat
Danny Hooper <hooper@google.com>
parents:
38619
diff
changeset
|
1065 'changes as positional arguments)')), |
24477
325f03de849d
shelve: add interactive mode command line option
Laurent Charignon <lcharignon@fb.com>
parents:
23895
diff
changeset
|
1066 ('i', 'interactive', None, |
25260
8fa3e995a375
selve: make 'shelve --interactive' not experimental
Laurent Charignon <lcharignon@fb.com>
parents:
25186
diff
changeset
|
1067 _('interactive mode, only works while creating a shelve')), |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1068 ('', 'stat', None, |
38714
abcf500d527c
shelve: improve help text for --patch and --stat
Danny Hooper <hooper@google.com>
parents:
38619
diff
changeset
|
1069 _('output diffstat-style summary of changes (provide the names of ' |
abcf500d527c
shelve: improve help text for --patch and --stat
Danny Hooper <hooper@google.com>
parents:
38619
diff
changeset
|
1070 'the shelved changes as positional arguments)') |
abcf500d527c
shelve: improve help text for --patch and --stat
Danny Hooper <hooper@google.com>
parents:
38619
diff
changeset
|
1071 )] + cmdutil.walkopts, |
40293
c303d65d2e34
help: assigning categories to existing commands
rdamazio@google.com
parents:
40030
diff
changeset
|
1072 _('hg shelve [OPTION]... [FILE]...'), |
c303d65d2e34
help: assigning categories to existing commands
rdamazio@google.com
parents:
40030
diff
changeset
|
1073 helpcategory=command.CATEGORY_WORKING_DIRECTORY) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1074 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
|
1075 '''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
|
1076 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1077 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
|
1078 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
|
1079 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
|
1080 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1081 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
|
1082 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
|
1083 commit. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1084 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1085 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
|
1086 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
|
1087 those files are shelved. |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1088 |
30256
819f96b82fa4
shelve: add missing space in help text
Mads Kiilerich <madski@unity3d.com>
parents:
29852
diff
changeset
|
1089 In bare shelve (when no files are specified, without interactive, |
28573
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
1090 include and exclude option), shelving remembers information if the |
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
1091 working directory was on newly created branch, in other words working |
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
1092 directory was on different branch than its first parent. In this |
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
1093 situation unshelving restores branch information to the working directory. |
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
1094 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1095 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
|
1096 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
|
1097 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
|
1098 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
|
1099 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1100 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
|
1101 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
|
1102 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
|
1103 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1104 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
|
1105 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
|
1106 ''' |
35046
aad6b9fdfc75
py3: handle keyword arguments in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34496
diff
changeset
|
1107 opts = pycompat.byteskwargs(opts) |
21851
aad28ff87788
shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21064
diff
changeset
|
1108 allowables = [ |
32331
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
32325
diff
changeset
|
1109 ('addremove', {'create'}), # 'create' is pseudo action |
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
32325
diff
changeset
|
1110 ('unknown', {'create'}), |
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
32325
diff
changeset
|
1111 ('cleanup', {'cleanup'}), |
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
32325
diff
changeset
|
1112 # ('date', {'create'}), # ignored for passing '--date "0 0"' in tests |
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
32325
diff
changeset
|
1113 ('delete', {'delete'}), |
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
32325
diff
changeset
|
1114 ('edit', {'create'}), |
42020
00c1ee0f746a
shelve: add --keep to list of allowables
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
42013
diff
changeset
|
1115 ('keep', {'create'}), |
32331
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
32325
diff
changeset
|
1116 ('list', {'list'}), |
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
32325
diff
changeset
|
1117 ('message', {'create'}), |
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
32325
diff
changeset
|
1118 ('name', {'create'}), |
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
32325
diff
changeset
|
1119 ('patch', {'patch', 'list'}), |
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
32325
diff
changeset
|
1120 ('stat', {'stat', 'list'}), |
21851
aad28ff87788
shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21064
diff
changeset
|
1121 ] |
aad28ff87788
shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21064
diff
changeset
|
1122 def checkopt(opt): |
28401
2565fe39a76c
shelve: changes getting opts values by get method
liscju <piotr.listkiewicz@gmail.com>
parents:
28378
diff
changeset
|
1123 if opts.get(opt): |
21851
aad28ff87788
shelve: refactor option combination check to easily add new ones
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
21064
diff
changeset
|
1124 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
|
1125 if opts[i] and opt not in allowable: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
1126 raise error.Abort(_("options '--%s' and '--%s' may not be " |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1127 "used together") % (opt, i)) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1128 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
|
1129 if checkopt('cleanup'): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1130 if pats: |
26587
56b2bcea2529
error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26577
diff
changeset
|
1131 raise error.Abort(_("cannot specify names when using '--cleanup'")) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1132 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
|
1133 elif checkopt('delete'): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1134 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
|
1135 elif checkopt('list'): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1136 return listcmd(ui, repo, pats, opts) |
38715
905b66681004
shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents:
38714
diff
changeset
|
1137 elif checkopt('patch') or checkopt('stat'): |
905b66681004
shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents:
38714
diff
changeset
|
1138 return patchcmds(ui, repo, pats, opts) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1139 else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1140 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
|
1141 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1142 def extsetup(ui): |
42536
5f2f6912c9e6
states: moved cmdutil.unfinishedstates to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents:
42325
diff
changeset
|
1143 statemod.unfinishedstates.append( |
19963
6f29cc567845
shelve: disallow commit while unshelve is in progress
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19961
diff
changeset
|
1144 [shelvedstate._filename, False, False, |
6f29cc567845
shelve: disallow commit while unshelve is in progress
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
19961
diff
changeset
|
1145 _('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
|
1146 _("use 'hg unshelve --continue' or 'hg unshelve --abort'")]) |
27694
2dc363274702
shelve: hook afterresolvedstates
timeless <timeless@mozdev.org>
parents:
27651
diff
changeset
|
1147 cmdutil.afterresolvedstates.append( |
2dc363274702
shelve: hook afterresolvedstates
timeless <timeless@mozdev.org>
parents:
27651
diff
changeset
|
1148 [shelvedstate._filename, _('hg unshelve --continue')]) |
42536
5f2f6912c9e6
states: moved cmdutil.unfinishedstates to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents:
42325
diff
changeset
|
1149 |