Mercurial > public > mercurial-scm > hg-stable
annotate mercurial/shelve.py @ 43077:687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Done with
python3.7 contrib/byteify-strings.py -i $(hg files 'set:mercurial/**.py - mercurial/thirdparty/** + hgext/**.py - hgext/fsmonitor/pywatchman/** - mercurial/__init__.py')
black -l 80 -t py33 -S $(hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**" - hgext/fsmonitor/pywatchman/**')
# skip-blame mass-reformatting only
Differential Revision: https://phab.mercurial-scm.org/D6972
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 06 Oct 2019 09:48:39 -0400 |
parents | 2372284d9457 |
children | eef9a2d67051 |
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 |
42548
3de4f17f4824
shelve: move shelve extension to core
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42547
diff
changeset
|
30 from .i18n import _ |
3de4f17f4824
shelve: move shelve extension to core
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42547
diff
changeset
|
31 from . 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, |
28378
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
48 repair, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
49 scmutil, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
50 templatefilters, |
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
51 util, |
31254
636f55b9ba23
vfs: use 'vfs' module directly in 'hgext.shelve'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31113
diff
changeset
|
52 vfs as vfsmod, |
28378
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
53 ) |
42548
3de4f17f4824
shelve: move shelve extension to core
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42547
diff
changeset
|
54 from .utils import ( |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36789
diff
changeset
|
55 dateutil, |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36789
diff
changeset
|
56 stringutil, |
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36789
diff
changeset
|
57 ) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
58 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
59 backupdir = b'shelve-backup' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
60 shelvedir = b'shelved' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
61 shelvefileextensions = [b'hg', b'patch', b'shelve'] |
30560
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30551
diff
changeset
|
62 # universal extension is present in all types of shelves |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
63 patchextension = b'patch' |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
64 |
30391
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
65 # 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
|
66 # generic user for all shelve operations |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
67 shelveuser = b'shelve@localhost' |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
68 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
69 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
70 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
|
71 """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
|
72 |
22581
c5ece02fb211
shelve: avoid writing file that is never read from
Martin von Zweigbergk <martinvonz@gmail.com>
parents:
22202
diff
changeset
|
73 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
|
74 the vfs layer""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
75 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
76 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
|
77 self.repo = repo |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
78 self.name = name |
31344
3acc7af5859c
shelve: directly use repo.vfs.join
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31321
diff
changeset
|
79 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
|
80 self.backupvfs = vfsmod.vfs(repo.vfs.join(backupdir)) |
23895
cda18ded2c48
changegroup.writebundle: provide ui
Eric Sumner <ericsumner@fb.com>
parents:
23877
diff
changeset
|
81 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
|
82 if filetype: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
83 self.fname = name + b'.' + filetype |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
84 else: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
85 self.fname = name |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
86 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
87 def exists(self): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
88 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
|
89 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
90 def filename(self): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
91 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
|
92 |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
93 def backupfilename(self): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
94 def gennames(base): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
95 yield base |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
96 base, ext = base.rsplit(b'.', 1) |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
97 for i in itertools.count(1): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
98 yield b'%s-%d.%s' % (base, i, ext) |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
99 |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
100 name = self.backupvfs.join(self.fname) |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
101 for n in gennames(name): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
102 if not self.backupvfs.exists(n): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
103 return n |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
104 |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
105 def movetobackup(self): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
106 if not self.backupvfs.isdir(): |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
107 self.backupvfs.makedir() |
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
108 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
|
109 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
110 def stat(self): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
111 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
|
112 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
113 def opener(self, mode=b'rb'): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
114 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 raise |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
119 raise error.Abort(_(b"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
|
120 |
41017
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40872
diff
changeset
|
121 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
|
122 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
|
123 try: |
39536
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
124 targetphase = phases.internal |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
125 if not phases.supportinternal(self.repo): |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
126 targetphase = phases.secret |
21064
4d9d490d7bbe
bundle2: add a ui argument to readbundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
21063
diff
changeset
|
127 gen = exchange.readbundle(self.repo.ui, fp, self.fname, self.vfs) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
128 pretip = self.repo[b'tip'] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
129 bundle2.applybundle( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
130 self.repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
131 gen, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
132 tr, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
133 source=b'unshelve', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
134 url=b'bundle:' + self.vfs.join(self.fname), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
135 targetphase=targetphase, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
136 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
137 shelvectx = self.repo[b'tip'] |
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
|
138 if pretip == shelvectx: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
139 shelverev = tr.changes[b'revduplicates'][-1] |
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
|
140 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
|
141 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
|
142 finally: |
1df99f1ea28d
shelve: add "applybundle()" to invoke "readbundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20960
diff
changeset
|
143 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
|
144 |
22898
43816070284e
shelve: add a bundlerepo method
Matt Mackall <mpm@selenic.com>
parents:
22844
diff
changeset
|
145 def bundlerepo(self): |
39617
84d6e9a2b104
shelve: use bundlerepo.instance() to construct a repo object
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39536
diff
changeset
|
146 path = self.vfs.join(self.fname) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
147 return bundlerepo.instance( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
148 self.repo.baseui, b'bundle://%s+%s' % (self.repo.root, path) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
149 ) |
39617
84d6e9a2b104
shelve: use bundlerepo.instance() to construct a repo object
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39536
diff
changeset
|
150 |
26506
edecf059fda6
shelve: move changegroup generation inside writebundle
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26505
diff
changeset
|
151 def writebundle(self, bases, node): |
27931
1289a122cf3f
shelve: use cg3 for treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
27921
diff
changeset
|
152 cgversion = changegroup.safeversion(self.repo) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
153 if cgversion == b'01': |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
154 btype = b'HG10BZ' |
27931
1289a122cf3f
shelve: use cg3 for treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
27921
diff
changeset
|
155 compression = None |
1289a122cf3f
shelve: use cg3 for treemanifests
Martin von Zweigbergk <martinvonz@google.com>
parents:
27921
diff
changeset
|
156 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
157 btype = b'HG20' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
158 compression = b'BZ' |
26507
ae29cffa05db
shelve: bundle using bundle2 if repository is general delta (issue4862)
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
26506
diff
changeset
|
159 |
39400
6a71324cb68b
shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
39399
diff
changeset
|
160 repo = self.repo.unfiltered() |
6a71324cb68b
shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
39399
diff
changeset
|
161 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
162 outgoing = discovery.outgoing( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
163 repo, missingroots=bases, missingheads=[node] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
164 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
165 cg = changegroup.makechangegroup(repo, outgoing, cgversion, b'shelve') |
34112
f7d41b85bbf6
changegroup: replace changegroupsubset with makechangegroup
Durham Goode <durham@fb.com>
parents:
33440
diff
changeset
|
166 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
167 bundle2.writebundle( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
168 self.ui, cg, self.fname, btype, self.vfs, compression=compression |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
169 ) |
20983
2778616de7ce
shelve: add "writebundle()" to invoke "writebundle()" with relative path and vfs
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
20982
diff
changeset
|
170 |
39370
bab58b1d87c7
shelve: rename method for data write/read
Boris Feld <boris.feld@octobus.net>
parents:
39369
diff
changeset
|
171 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
|
172 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
|
173 |
39370
bab58b1d87c7
shelve: rename method for data write/read
Boris Feld <boris.feld@octobus.net>
parents:
39369
diff
changeset
|
174 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
|
175 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
|
176 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
177 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
178 class shelvedstate(object): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
179 """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
|
180 |
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
181 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
|
182 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
|
183 """ |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
184 |
32325
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
185 _version = 2 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
186 _filename = b'shelvedstate' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
187 _keep = b'keep' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
188 _nokeep = b'nokeep' |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
189 # colon is essential to differentiate from a real bookmark name |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
190 _noactivebook = b':no-active-bookmark' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
191 _interactive = b'interactive' |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
192 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
193 @classmethod |
32325
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
194 def _verifyandtransform(cls, d): |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
195 """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
|
196 try: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
197 d[b'originalwctx'] = nodemod.bin(d[b'originalwctx']) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
198 d[b'pendingctx'] = nodemod.bin(d[b'pendingctx']) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
199 d[b'parents'] = [nodemod.bin(h) for h in d[b'parents'].split(b' ')] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
200 d[b'nodestoremove'] = [ |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
201 nodemod.bin(h) for h in d[b'nodestoremove'].split(b' ') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
202 ] |
32324
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
203 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
|
204 raise error.CorruptedState(pycompat.bytestr(err)) |
32324
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
205 |
32325
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
206 @classmethod |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
207 def _getversion(cls, repo): |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
208 """Read version information from shelvestate file""" |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
209 fp = repo.vfs(cls._filename) |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
210 try: |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
211 version = int(fp.readline().strip()) |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
212 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
|
213 raise error.CorruptedState(pycompat.bytestr(err)) |
32325
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
214 finally: |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
215 fp.close() |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
216 return version |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
217 |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
218 @classmethod |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
219 def _readold(cls, repo): |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
220 """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
|
221 # Order is important, because old shelvestate file uses it |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
222 # 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
|
223 # originalwctx is on the third and so forth). Please do not change. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
224 keys = [ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
225 b'version', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
226 b'name', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
227 b'originalwctx', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
228 b'pendingctx', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
229 b'parents', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
230 b'nodestoremove', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
231 b'branchtorestore', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
232 b'keep', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
233 b'activebook', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
234 ] |
32325
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: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
252 d = scmutil.simplekeyvaluefile(repo.vfs, cls._filename).read( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
253 firstlinenonkeyval=True |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
254 ) |
32325
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
255 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
256 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
257 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
258 b'this version of shelve is incompatible ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
259 b'with the version used in this repo' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
260 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
261 ) |
32325
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
262 |
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
263 cls._verifyandtransform(d) |
29536
b17a6e3cd2ac
shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents:
29270
diff
changeset
|
264 try: |
b17a6e3cd2ac
shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents:
29270
diff
changeset
|
265 obj = cls() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
266 obj.name = d[b'name'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
267 obj.wctx = repo[d[b'originalwctx']] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
268 obj.pendingctx = repo[d[b'pendingctx']] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
269 obj.parents = d[b'parents'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
270 obj.nodestoremove = d[b'nodestoremove'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
271 obj.branchtorestore = d.get(b'branchtorestore', b'') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
272 obj.keep = d.get(b'keep') == cls._keep |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
273 obj.activebookmark = b'' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
274 if d.get(b'activebook', b'') != cls._noactivebook: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
275 obj.activebookmark = d.get(b'activebook', b'') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
276 obj.interactive = d.get(b'interactive') == cls._interactive |
32324
16d424b97125
shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents:
31888
diff
changeset
|
277 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
|
278 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
|
279 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
280 return obj |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
281 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
282 @classmethod |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
283 def save( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
284 cls, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
285 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
286 name, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
287 originalwctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
288 pendingctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
289 nodestoremove, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
290 branchtorestore, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
291 keep=False, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
292 activebook=b'', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
293 interactive=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
294 ): |
32325
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
295 info = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
296 b"name": name, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
297 b"originalwctx": nodemod.hex(originalwctx.node()), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
298 b"pendingctx": nodemod.hex(pendingctx.node()), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
299 b"parents": b' '.join( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
300 [nodemod.hex(p) for p in repo.dirstate.parents()] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
301 ), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
302 b"nodestoremove": b' '.join( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
303 [nodemod.hex(n) for n in nodestoremove] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
304 ), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
305 b"branchtorestore": branchtorestore, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
306 b"keep": cls._keep if keep else cls._nokeep, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
307 b"activebook": activebook or cls._noactivebook, |
32325
fe3105e6e051
shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents:
32324
diff
changeset
|
308 } |
42691
ee86ad6f50fe
unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42690
diff
changeset
|
309 if interactive: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
310 info[b'interactive'] = cls._interactive |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
311 scmutil.simplekeyvaluefile(repo.vfs, cls._filename).write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
312 info, firstline=(b"%d" % cls._version) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
313 ) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
314 |
19908
07ee5c8867ca
shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19904
diff
changeset
|
315 @classmethod |
07ee5c8867ca
shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19904
diff
changeset
|
316 def clear(cls, repo): |
31320
f59b6cf663a9
vfs: use repo.vfs.unlinkpath
Mads Kiilerich <mads@kiilerich.com>
parents:
31254
diff
changeset
|
317 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
|
318 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
319 |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
320 def cleanupoldbackups(repo): |
31344
3acc7af5859c
shelve: directly use repo.vfs.join
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
31321
diff
changeset
|
321 vfs = vfsmod.vfs(repo.vfs.join(backupdir)) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
322 maxbackups = repo.ui.configint(b'shelve', b'maxbackups') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
323 hgfiles = [f for f in vfs.listdir() if f.endswith(b'.' + 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
|
324 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
|
325 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
|
326 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
|
327 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
|
328 bordermtime = None |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
329 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
|
330 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
|
331 # 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
|
332 continue |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
333 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
|
334 for ext in shelvefileextensions: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
335 vfs.tryunlink(base + b'.' + ext) |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
336 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
337 |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
338 def _backupactivebookmark(repo): |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
339 activebookmark = repo._activebookmark |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
340 if activebookmark: |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
341 bookmarks.deactivate(repo) |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
342 return activebookmark |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
343 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
344 |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
345 def _restoreactivebookmark(repo, mark): |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
346 if mark: |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
347 bookmarks.activate(repo, mark) |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
348 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
349 |
41017
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40872
diff
changeset
|
350 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
|
351 '''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
|
352 ''' |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
353 dirstatebackupname = b'dirstate.shelve' |
38908
ad24b581e4d9
narrow: call narrowspec.{save,restore,clear}backup directly
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
354 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
|
355 tr.abort() |
38908
ad24b581e4d9
narrow: call narrowspec.{save,restore,clear}backup directly
Martin von Zweigbergk <martinvonz@google.com>
parents:
38823
diff
changeset
|
356 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
|
357 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
358 |
30389
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
359 def getshelvename(repo, parent, opts): |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
360 """Decide on the name this shelve is going to have""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
361 |
30389
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
362 def gennames(): |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
363 yield label |
32986
4107eb8a5648
shelve: allow unlimited shelved changes per name
Jun Wu <quark@fb.com>
parents:
32948
diff
changeset
|
364 for i in itertools.count(1): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
365 yield b'%s-%02d' % (label, i) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
366 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
367 name = opts.get(b'name') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
368 label = repo._activebookmark or parent.branch() or b'default' |
30389
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
369 # slashes aren't allowed in filenames, therefore we rename it |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
370 label = label.replace(b'/', b'_') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
371 label = label.replace(b'\\', b'_') |
30674
64a75655b988
shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30560
diff
changeset
|
372 # filenames must not start with '.' as it should not be hidden |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
373 if label.startswith(b'.'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
374 label = label.replace(b'.', b'_', 1) |
30389
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
375 |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
376 if name: |
30560
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30551
diff
changeset
|
377 if shelvedfile(repo, name, patchextension).exists(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
378 e = _(b"a shelved change named '%s' already exists") % name |
30389
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
379 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
|
380 |
64a75655b988
shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30560
diff
changeset
|
381 # ensure we are not creating a subdirectory or a hidden file |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
382 if b'/' in name or b'\\' in name: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
383 raise error.Abort( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
384 _(b'shelved change names can not contain slashes') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
385 ) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
386 if name.startswith(b'.'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
387 raise error.Abort(_(b"shelved change names can not start with '.'")) |
30674
64a75655b988
shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30560
diff
changeset
|
388 |
30389
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
389 else: |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
390 for n in gennames(): |
30560
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30551
diff
changeset
|
391 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
|
392 name = n |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
393 break |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
394 |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
395 return name |
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
396 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
397 |
30390
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
398 def mutableancestors(ctx): |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
399 """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
|
400 |
30390
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
401 Much faster than the revset ancestors(ctx) & draft()""" |
32331
bd872f64a8ba
cleanup: use set literals
Martin von Zweigbergk <martinvonz@google.com>
parents:
32325
diff
changeset
|
402 seen = {nodemod.nullrev} |
30390
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
403 visit = collections.deque() |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
404 visit.append(ctx) |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
405 while visit: |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
406 ctx = visit.popleft() |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
407 yield ctx.node() |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
408 for parent in ctx.parents(): |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
409 rev = parent.rev() |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
410 if rev not in seen: |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
411 seen.add(rev) |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
412 if parent.mutable(): |
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
413 visit.append(parent) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
414 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
415 |
30391
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
416 def getcommitfunc(extra, interactive, editor=False): |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
417 def commitfunc(ui, repo, message, match, opts): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
418 hasmq = util.safehasattr(repo, b'mq') |
30391
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
419 if hasmq: |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
420 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
|
421 |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
422 targetphase = phases.internal |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
423 if not phases.supportinternal(repo): |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
424 targetphase = phases.secret |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
425 overrides = {(b'phases', b'new-commit'): targetphase} |
30391
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
426 try: |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
427 editor_ = False |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
428 if editor: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
429 editor_ = cmdutil.getcommiteditor( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
430 editform=b'shelve.shelve', **pycompat.strkwargs(opts) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
431 ) |
31471 | 432 with repo.ui.configoverride(overrides): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
433 return repo.commit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
434 message, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
435 shelveuser, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
436 opts.get(b'date'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
437 match, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
438 editor=editor_, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
439 extra=extra, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
440 ) |
30391
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
441 finally: |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
442 if hasmq: |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
443 repo.mq.checkapplied = saved |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
444 |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
445 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
|
446 opts = pycompat.byteskwargs(opts) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
447 match = scmutil.match(repo[b'.'], pats, {}) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
448 message = opts[b'message'] |
30391
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
449 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
|
450 |
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
451 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
|
452 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
453 |
30392
dedf0915ca5b
shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30391
diff
changeset
|
454 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
|
455 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
|
456 if stat.deleted: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
457 ui.status( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
458 _(b"nothing changed (%d missing files, see " b"'hg status')\n") |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
459 % len(stat.deleted) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
460 ) |
30392
dedf0915ca5b
shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30391
diff
changeset
|
461 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
462 ui.status(_(b"nothing changed\n")) |
30392
dedf0915ca5b
shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30391
diff
changeset
|
463 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
464 |
42012
9b78bbb76111
shelve: refactor _shelvecreatedcommit's match object into calling site
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
42011
diff
changeset
|
465 def _shelvecreatedcommit(repo, node, name, match): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
466 info = {b'node': nodemod.hex(node)} |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
467 shelvedfile(repo, name, b'shelve').writeinfo(info) |
30393
455f7856db20
shelve: move actual created commit shelving to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30392
diff
changeset
|
468 bases = list(mutableancestors(repo[node])) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
469 shelvedfile(repo, name, b'hg').writebundle(bases, node) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
470 with shelvedfile(repo, name, patchextension).opener(b'wb') as fp: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
471 cmdutil.exportfile( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
472 repo, [node], fp, opts=mdiff.diffopts(git=True), match=match |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
473 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
474 |
30393
455f7856db20
shelve: move actual created commit shelving to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30392
diff
changeset
|
475 |
30394
21a75b63c10e
shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30393
diff
changeset
|
476 def _includeunknownfiles(repo, pats, opts, extra): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
477 s = repo.status(match=scmutil.match(repo[None], pats, opts), unknown=True) |
30394
21a75b63c10e
shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30393
diff
changeset
|
478 if s.unknown: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
479 extra[b'shelve_unknown'] = b'\0'.join(s.unknown) |
30394
21a75b63c10e
shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30393
diff
changeset
|
480 repo[None].add(s.unknown) |
21a75b63c10e
shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30393
diff
changeset
|
481 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
482 |
41017
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40872
diff
changeset
|
483 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
|
484 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
|
485 tr.close() |
52dfa1eb0ad4
shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents:
39617
diff
changeset
|
486 else: |
41017
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40872
diff
changeset
|
487 _aborttransaction(repo, tr) |
30395
b573d7ca31c4
shelve: move shelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30394
diff
changeset
|
488 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
489 |
39369
d52fa7ddd1ac
shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents:
38908
diff
changeset
|
490 def createcmd(ui, repo, pats, opts): |
d52fa7ddd1ac
shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents:
38908
diff
changeset
|
491 """subcommand that creates a new shelve""" |
d52fa7ddd1ac
shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents:
38908
diff
changeset
|
492 with repo.wlock(): |
d52fa7ddd1ac
shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents:
38908
diff
changeset
|
493 cmdutil.checkunfinished(repo) |
d52fa7ddd1ac
shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents:
38908
diff
changeset
|
494 return _docreatecmd(ui, repo, pats, opts) |
d52fa7ddd1ac
shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents:
38908
diff
changeset
|
495 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
496 |
30390
84e8cbdbdee4
shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents:
30389
diff
changeset
|
497 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
|
498 wctx = repo[None] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
499 parents = wctx.parents() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
500 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
|
501 origbranch = wctx.branch() |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
502 |
28378
96a7368a79b6
shelve: use absolute_import
timeless <timeless@mozdev.org>
parents:
28124
diff
changeset
|
503 if parent.node() != nodemod.nullid: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
504 desc = b"changes to: %s" % parent.description().split(b'\n', 1)[0] |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
505 else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
506 desc = b'(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
|
507 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
508 if not opts.get(b'message'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
509 opts[b'message'] = desc |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
510 |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
511 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
|
512 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
513 lock = repo.lock() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
514 |
19951
d51c4d85ec23
spelling: random spell checker fixes
Mads Kiilerich <madski@unity3d.com>
parents:
19943
diff
changeset
|
515 # 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
|
516 # pull races. ensure we don't print the abort message to stderr. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
517 tr = repo.transaction(b'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
|
518 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
519 interactive = opts.get(b'interactive', False) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
520 includeunknown = opts.get(b'unknown', False) and not opts.get( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
521 b'addremove', False |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
522 ) |
27908
d73a5ab18015
shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents:
27888
diff
changeset
|
523 |
30389
684068d24658
shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30388
diff
changeset
|
524 name = getshelvename(repo, parent, opts) |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
525 activebookmark = _backupactivebookmark(repo) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
526 extra = {b'internal': b'shelve'} |
27908
d73a5ab18015
shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents:
27888
diff
changeset
|
527 if includeunknown: |
30394
21a75b63c10e
shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30393
diff
changeset
|
528 _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
|
529 |
28572
43c204ddf333
shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents:
28571
diff
changeset
|
530 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
|
531 # 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
|
532 # at bundled commit |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
533 repo.dirstate.setbranch(repo[b'.'].branch()) |
28572
43c204ddf333
shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents:
28571
diff
changeset
|
534 |
30391
caba61934721
shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30390
diff
changeset
|
535 commitfunc = getcommitfunc(extra, interactive, editor=True) |
24478
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
536 if not interactive: |
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
537 node = cmdutil.commit(ui, repo, commitfunc, pats, opts) |
95cbc77c0cad
shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents:
24477
diff
changeset
|
538 else: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
539 node = cmdutil.dorecord( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
540 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
541 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
542 commitfunc, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
543 None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
544 False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
545 cmdutil.recordfilter, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
546 *pats, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
547 **pycompat.strkwargs(opts) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
548 ) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
549 if not node: |
30392
dedf0915ca5b
shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30391
diff
changeset
|
550 _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
|
551 return 1 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
552 |
42012
9b78bbb76111
shelve: refactor _shelvecreatedcommit's match object into calling site
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
42011
diff
changeset
|
553 # 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
|
554 # 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
|
555 # 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
|
556 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
|
557 _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
|
558 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
559 if ui.formatted(): |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36789
diff
changeset
|
560 desc = stringutil.ellipsis(desc, ui.termwidth()) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
561 ui.status(_(b'shelved as %s\n') % name) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
562 if opts[b'keep']: |
42013
50d5e64ec561
shelve: do not update when keeping changes, just move the dirstate
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
42012
diff
changeset
|
563 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
|
564 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
|
565 else: |
50d5e64ec561
shelve: do not update when keeping changes, just move the dirstate
Jordi Guti?rrez Hermoso <jordigh@octave.org>
parents:
42012
diff
changeset
|
566 hg.update(repo, parent.node()) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
567 if origbranch != repo[b'.'].branch() and not _isbareshelve(pats, opts): |
28571
3f0e25e89e28
shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28401
diff
changeset
|
568 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
|
569 |
41017
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40872
diff
changeset
|
570 _finishshelve(repo, tr) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
571 finally: |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
572 _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
|
573 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
|
574 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
575 |
28571
3f0e25e89e28
shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28401
diff
changeset
|
576 def _isbareshelve(pats, opts): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
577 return ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
578 not pats |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
579 and not opts.get(b'interactive', False) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
580 and not opts.get(b'include', False) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
581 and not opts.get(b'exclude', False) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
582 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
583 |
28571
3f0e25e89e28
shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28401
diff
changeset
|
584 |
28572
43c204ddf333
shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents:
28571
diff
changeset
|
585 def _iswctxonnewbranch(repo): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
586 return repo[None].branch() != repo[b'.'].branch() |
28572
43c204ddf333
shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents:
28571
diff
changeset
|
587 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
588 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
589 def cleanupcmd(ui, repo): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
590 """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
|
591 |
27835
c448d7e00bf9
with: use context manager for wlock in shelve cleanupcmd
Bryan O'Sullivan <bryano@fb.com>
parents:
27834
diff
changeset
|
592 with repo.wlock(): |
28862
39130afcce60
shelve: refactor directory name into constant
Oleg Afanasyev <olegaf@fb.com>
parents:
28666
diff
changeset
|
593 for (name, _type) in repo.vfs.readdir(shelvedir): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
594 suffix = name.rsplit(b'.', 1)[-1] |
30388
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29852
diff
changeset
|
595 if suffix in shelvefileextensions: |
25712
8a6264a2ee60
shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents:
25660
diff
changeset
|
596 shelvedfile(repo, name).movetobackup() |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
597 cleanupoldbackups(repo) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
598 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
599 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
600 def deletecmd(ui, repo, pats): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
601 """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
|
602 if not pats: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
603 raise error.Abort(_(b'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
|
604 with repo.wlock(): |
1c2408c28aff
with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents:
27835
diff
changeset
|
605 try: |
1c2408c28aff
with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents:
27835
diff
changeset
|
606 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
|
607 for suffix in shelvefileextensions: |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29852
diff
changeset
|
608 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
|
609 # 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
|
610 # 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
|
611 # 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
|
612 # 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
|
613 # bundle |
30560
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30551
diff
changeset
|
614 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
|
615 shfile.movetobackup() |
27836
1c2408c28aff
with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents:
27835
diff
changeset
|
616 cleanupoldbackups(repo) |
1c2408c28aff
with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents:
27835
diff
changeset
|
617 except OSError as err: |
1c2408c28aff
with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents:
27835
diff
changeset
|
618 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
|
619 raise |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
620 raise error.Abort(_(b"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
|
621 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
622 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
623 def listshelves(repo): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
624 """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
|
625 try: |
28862
39130afcce60
shelve: refactor directory name into constant
Oleg Afanasyev <olegaf@fb.com>
parents:
28666
diff
changeset
|
626 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
|
627 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
|
628 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
|
629 raise |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
630 return [] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
631 info = [] |
22199
b3e51675f98e
cleanup: avoid _ for local unused tmp variables - that is reserved for i18n
Mads Kiilerich <madski@unity3d.com>
parents:
22184
diff
changeset
|
632 for (name, _type) in names: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
633 pfx, sfx = name.rsplit(b'.', 1) |
30560
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30551
diff
changeset
|
634 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
|
635 continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
636 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
|
637 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
|
638 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
|
639 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
640 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
641 def listcmd(ui, repo, pats, opts): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
642 """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
|
643 pats = set(pats) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
644 width = 80 |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
645 if not ui.plain(): |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
646 width = ui.termwidth() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
647 namelabel = b'shelve.newest' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
648 ui.pager(b'shelve') |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
649 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
|
650 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
|
651 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
|
652 continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
653 ui.write(sname, label=namelabel) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
654 namelabel = b'shelve.name' |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
655 if ui.quiet: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
656 ui.write(b'\n') |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
657 continue |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
658 ui.write(b' ' * (16 - len(sname))) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
659 used = 16 |
36636
c6061cadb400
util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents:
36526
diff
changeset
|
660 date = dateutil.makedate(mtime) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
661 age = b'(%s)' % templatefilters.age(date, abbrev=True) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
662 ui.write(age, label=b'shelve.age') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
663 ui.write(b' ' * (12 - len(age))) |
19855
a3b285882724
shelve: new output format for shelve listings
David Soria Parra <dsp@experimentalworks.net>
parents:
19854
diff
changeset
|
664 used += 12 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
665 with open(name + b'.' + patchextension, b'rb') as fp: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
666 while True: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
667 line = fp.readline() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
668 if not line: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
669 break |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
670 if not line.startswith(b'#'): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
671 desc = line.rstrip() |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
672 if ui.formatted(): |
37087
f0b6fbea00cf
stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents:
36789
diff
changeset
|
673 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
|
674 ui.write(desc) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
675 break |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
676 ui.write(b'\n') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
677 if not (opts[b'patch'] or opts[b'stat']): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
678 continue |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
679 difflines = fp.readlines() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
680 if opts[b'patch']: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
681 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
|
682 ui.write(chunk, label=label) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
683 if opts[b'stat']: |
30417
e1677cc29da6
patch: remove unused git parameter from patch.diffstat()
Henning Schild <henning@hennsch.de>
parents:
30395
diff
changeset
|
684 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
|
685 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
|
686 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
687 |
38715
905b66681004
shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents:
38714
diff
changeset
|
688 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
|
689 """subcommand that displays shelves""" |
806a830e6612
shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30674
diff
changeset
|
690 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
|
691 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
|
692 if not shelves: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
693 raise error.Abort(_(b"there are no shelves to show")) |
38715
905b66681004
shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents:
38714
diff
changeset
|
694 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
|
695 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
|
696 pats = [sname] |
25104
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
697 |
30823
806a830e6612
shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30674
diff
changeset
|
698 for shelfname in pats: |
806a830e6612
shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents:
30674
diff
changeset
|
699 if not shelvedfile(repo, shelfname, patchextension).exists(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
700 raise error.Abort(_(b"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
|
701 |
d6453f6fbdba
shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents:
25103
diff
changeset
|
702 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
|
703 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
704 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
705 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
|
706 """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
|
707 if state.parents != repo.dirstate.parents(): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
708 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
709 _(b'working directory parents do not match unshelve ' b'state') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
710 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
711 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
712 |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
713 def _loadshelvedstate(ui, repo, opts): |
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
714 try: |
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
715 state = shelvedstate.load(repo) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
716 if opts.get(b'keep') is None: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
717 opts[b'keep'] = state.keep |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
718 except IOError as err: |
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
719 if err.errno != errno.ENOENT: |
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
720 raise |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
721 cmdutil.wrongtooltocontinue(repo, _(b'unshelve')) |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
722 except error.CorruptedState as err: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
723 ui.debug(pycompat.bytestr(err) + b'\n') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
724 if opts.get(b'continue'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
725 msg = _(b'corrupted shelved state file') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
726 hint = _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
727 b'please run hg unshelve --abort to abort unshelve ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
728 b'operation' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
729 ) |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
730 raise error.Abort(msg, hint=hint) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
731 elif opts.get(b'abort'): |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
732 shelvedstate.clear(repo) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
733 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
734 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
735 b'could not read shelved state file, your ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
736 b'working copy may be in an unexpected state\n' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
737 b'please update to some commit\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
738 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
739 ) |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
740 return state |
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
741 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
742 |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
743 def unshelveabort(ui, repo, state): |
19909
df54786a3203
shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
19908
diff
changeset
|
744 """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
|
745 with repo.lock(): |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
746 try: |
27841
83995fdde225
with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents:
27838
diff
changeset
|
747 checkparents(repo, state) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
748 |
40366
b14fdf1fb615
update: clarify update() call sites by specifying argument names
Martin von Zweigbergk <martinvonz@google.com>
parents:
40293
diff
changeset
|
749 merge.update(repo, state.pendingctx, branchmerge=False, force=True) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
750 if state.activebookmark and state.activebookmark in repo._bookmarks: |
38466
61e4cf1be5b2
shelve: directly handle the abort process
Boris Feld <boris.feld@octobus.net>
parents:
38011
diff
changeset
|
751 bookmarks.activate(repo, state.activebookmark) |
27841
83995fdde225
with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents:
27838
diff
changeset
|
752 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
|
753 if not phases.supportinternal(repo): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
754 repair.strip( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
755 ui, repo, state.nodestoremove, backup=False, topic=b'shelve' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
756 ) |
27841
83995fdde225
with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents:
27838
diff
changeset
|
757 finally: |
83995fdde225
with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents:
27838
diff
changeset
|
758 shelvedstate.clear(repo) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
759 ui.warn(_(b"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
|
760 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
761 |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
762 def hgabortunshelve(ui, repo): |
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
763 """logic to abort unshelve using 'hg abort""" |
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
764 with repo.wlock(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
765 state = _loadshelvedstate(ui, repo, {b'abort': True}) |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
766 return unshelveabort(ui, repo, state) |
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
767 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
768 |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
769 def mergefiles(ui, repo, wctx, shelvectx): |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
770 """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
|
771 dirstate.""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
772 with ui.configoverride({(b'ui', b'quiet'): True}): |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
773 hg.update(repo, wctx.node()) |
22184
fb8065de47b0
unshelve: silence internal revert
Matt Mackall <mpm@selenic.com>
parents:
22057
diff
changeset
|
774 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
|
775 cmdutil.revert(ui, repo, shelvectx, repo.dirstate.parents()) |
22184
fb8065de47b0
unshelve: silence internal revert
Matt Mackall <mpm@selenic.com>
parents:
22057
diff
changeset
|
776 ui.popbuffer() |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
777 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
778 |
28573
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
779 def restorebranch(ui, repo, branchtorestore): |
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
780 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
|
781 repo.dirstate.setbranch(branchtorestore) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
782 ui.status( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
783 _(b'marked working directory as branch %s\n') % branchtorestore |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
784 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
785 |
28573
6a42564081cb
shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents:
28572
diff
changeset
|
786 |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
787 def unshelvecleanup(ui, repo, name, opts): |
19911
1c58e368fbfd
shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents:
19909
diff
changeset
|
788 """remove related files after an unshelve""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
789 if not opts.get(b'keep'): |
30388
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29852
diff
changeset
|
790 for filetype in shelvefileextensions: |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29852
diff
changeset
|
791 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
|
792 if shfile.exists(): |
c5126aab9c37
shelve: move possible shelve file extensions to a single place
Kostia Balytskyi <ikostia@fb.com>
parents:
29852
diff
changeset
|
793 shfile.movetobackup() |
25713
2ca116614cfc
shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents:
25712
diff
changeset
|
794 cleanupoldbackups(repo) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
795 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
796 |
42691
ee86ad6f50fe
unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42690
diff
changeset
|
797 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
|
798 """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
|
799 # 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
|
800 # parent, second is the temporary "fake" commit we're unshelving. |
42691
ee86ad6f50fe
unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42690
diff
changeset
|
801 interactive = state.interactive |
ee86ad6f50fe
unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42690
diff
changeset
|
802 basename = state.name |
27838
60b850b7e4ef
with: use context manager for lock in continue
Bryan O'Sullivan <bryano@fb.com>
parents:
27837
diff
changeset
|
803 with repo.lock(): |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
804 checkparents(repo, state) |
26992
b3b5ed560283
shelve: switch to mergestate.read()
Siddharth Agarwal <sid0@fb.com>
parents:
26942
diff
changeset
|
805 ms = merge.mergestate.read(repo) |
33313
ea03b3223611
shelve: don't reimplement mergestate.unresolved()
Martin von Zweigbergk <martinvonz@google.com>
parents:
33055
diff
changeset
|
806 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
|
807 raise error.Abort( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
808 _(b"unresolved conflicts, can't continue"), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
809 hint=_(b"see 'hg resolve', then 'hg unshelve --continue'"), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
810 ) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
811 |
38467
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
812 shelvectx = repo[state.parents[1]] |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
813 pendingctx = state.pendingctx |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
814 |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
815 with repo.dirstate.parentchange(): |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
816 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
|
817 repo.dirstate.write(repo.currenttransaction()) |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
818 |
39536
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
819 targetphase = phases.internal |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
820 if not phases.supportinternal(repo): |
5d69e2412ec8
shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents:
39414
diff
changeset
|
821 targetphase = phases.secret |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
822 overrides = {(b'phases', b'new-commit'): targetphase} |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
823 with repo.ui.configoverride(overrides, b'unshelve'): |
38467
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
824 with repo.dirstate.parentchange(): |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
825 repo.setparents(state.parents[0], nodemod.nullid) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
826 newnode, ispartialunshelve = _createunshelvectx( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
827 ui, repo, shelvectx, basename, interactive, opts |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
828 ) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
829 |
38467
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
830 if newnode is None: |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
831 # 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
|
832 # 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
|
833 # here. Fix issue5494 |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
834 merge.mergestate.clean(repo) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
835 shelvectx = state.pendingctx |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
836 msg = _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
837 b'note: unshelved changes already existed ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
838 b'in the working copy\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
839 ) |
38467
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
840 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
|
841 else: |
38467
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
842 # only strip the shelvectx if we produced one |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
843 state.nodestoremove.append(newnode) |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
844 shelvectx = repo[newnode] |
f4776f8b98e0
shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents:
38466
diff
changeset
|
845 |
38512
39db5a01cd53
cleanup: pass in overwrite flag to hg.updaterepo() as named argument
Yuya Nishihara <yuya@tcha.org>
parents:
38467
diff
changeset
|
846 hg.updaterepo(repo, pendingctx.node(), overwrite=False) |
20149
578b888c820e
unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents:
20103
diff
changeset
|
847 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
|
848 restorebranch(ui, repo, state.branchtorestore) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
849 |
42724
4814d993fe21
unshelve: handle stripping changesets on interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42695
diff
changeset
|
850 if not phases.supportinternal(repo): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
851 repair.strip( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
852 ui, repo, state.nodestoremove, backup=False, topic=b'shelve' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
853 ) |
42725
073cfff9aaef
unshelve: delete shelvedstate after a successful unshelve --continue
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42724
diff
changeset
|
854 shelvedstate.clear(repo) |
42616
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
855 if not ispartialunshelve: |
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
856 unshelvecleanup(ui, repo, state.name, opts) |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
857 _restoreactivebookmark(repo, state.activebookmark) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
858 ui.status(_(b"unshelve of '%s' complete\n") % state.name) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
859 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
860 |
42614
117437f3f541
continue: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42599
diff
changeset
|
861 def hgcontinueunshelve(ui, repo): |
117437f3f541
continue: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42599
diff
changeset
|
862 """logic to resume unshelve using 'hg continue'""" |
117437f3f541
continue: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42599
diff
changeset
|
863 with repo.wlock(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
864 state = _loadshelvedstate(ui, repo, {b'continue': True}) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
865 return unshelvecontinue(ui, repo, state, {b'keep': state.keep}) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
866 |
42614
117437f3f541
continue: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42599
diff
changeset
|
867 |
30462
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
868 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
|
869 """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
|
870 # 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
|
871 # 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
|
872 s = repo.status() |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
873 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
|
874 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
|
875 return tmpwctx, addedbefore |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
876 ui.status( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
877 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
878 b"temporarily committing pending changes " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
879 b"(restore with 'hg unshelve --abort')\n" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
880 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
881 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
882 extra = {b'internal': b'shelve'} |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
883 commitfunc = getcommitfunc(extra=extra, interactive=False, editor=False) |
30462
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
884 tempopts = {} |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
885 tempopts[b'message'] = b"pending changes temporary commit" |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
886 tempopts[b'date'] = opts.get(b'date') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
887 with ui.configoverride({(b'ui', b'quiet'): True}): |
31762
473f2fcc7629
shelve: move ui.quiet manipulations to configoverride
Kostia Balytskyi <ikostia@fb.com>
parents:
31669
diff
changeset
|
888 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
|
889 tmpwctx = repo[node] |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
890 return tmpwctx, addedbefore |
2e736f01a710
shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30417
diff
changeset
|
891 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
892 |
41017
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40872
diff
changeset
|
893 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
|
894 """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
|
895 repo = repo.unfiltered() |
39414
da84cca65036
shelve: fix crash on unshelve without .shelve metadata file
Yuya Nishihara <yuya@tcha.org>
parents:
39403
diff
changeset
|
896 node = None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
897 if shelvedfile(repo, basename, b'shelve').exists(): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
898 node = shelvedfile(repo, basename, b'shelve').readinfo()[b'node'] |
39401
c67c94c0e7ae
shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents:
39400
diff
changeset
|
899 if node is None or node not in repo: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
900 with ui.configoverride({(b'ui', b'quiet'): True}): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
901 shelvectx = shelvedfile(repo, basename, b'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
|
902 # 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
|
903 # 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
|
904 if node is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
905 info = {b'node': nodemod.hex(shelvectx.node())} |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
906 shelvedfile(repo, basename, b'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
|
907 else: |
c67c94c0e7ae
shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents:
39400
diff
changeset
|
908 shelvectx = repo[node] |
c67c94c0e7ae
shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents:
39400
diff
changeset
|
909 |
30463
672026aece64
shelve: move commit restoration logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30462
diff
changeset
|
910 return repo, shelvectx |
672026aece64
shelve: move commit restoration logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30462
diff
changeset
|
911 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
912 |
42688
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
913 def _createunshelvectx(ui, repo, shelvectx, basename, interactive, opts): |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
914 """Handles the creation of unshelve commit and updates the shelve if it |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
915 was partially unshelved. |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
916 |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
917 If interactive is: |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
918 |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
919 * False: Commits all the changes in the working directory. |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
920 * True: Prompts the user to select changes to unshelve and commit them. |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
921 Update the shelve with remaining changes. |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
922 |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
923 Returns the node of the new commit formed and a bool indicating whether |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
924 the shelve was partially unshelved.Creates a commit ctx to unshelve |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
925 interactively or non-interactively. |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
926 |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
927 The user might want to unshelve certain changes only from the stored |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
928 shelve in interactive. So, we would create two commits. One with requested |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
929 changes to unshelve at that time and the latter is shelved for future. |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
930 |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
931 Here, we return both the newnode which is created interactively and a |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
932 bool to know whether the shelve is partly done or completely done. |
42616
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
933 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
934 opts[b'message'] = shelvectx.description() |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
935 opts[b'interactive-unshelve'] = True |
42616
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
936 pats = [] |
42688
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
937 if not interactive: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
938 newnode = repo.commit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
939 text=shelvectx.description(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
940 extra=shelvectx.extra(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
941 user=shelvectx.user(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
942 date=shelvectx.date(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
943 ) |
42688
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
944 return newnode, False |
c9114885c14b
unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42616
diff
changeset
|
945 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
946 commitfunc = getcommitfunc(shelvectx.extra(), interactive=True, editor=True) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
947 newnode = cmdutil.dorecord( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
948 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
949 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
950 commitfunc, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
951 None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
952 False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
953 cmdutil.recordfilter, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
954 *pats, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
955 **pycompat.strkwargs(opts) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
956 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
957 snode = repo.commit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
958 text=shelvectx.description(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
959 extra=shelvectx.extra(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
960 user=shelvectx.user(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
961 ) |
42616
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
962 if snode: |
42690
d5cdce3d9164
unshelve: create a matcher only if required on creating unshelve ctx
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42689
diff
changeset
|
963 m = scmutil.matchfiles(repo, repo[snode].files()) |
42616
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
964 _shelvecreatedcommit(repo, snode, basename, m) |
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
965 |
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
966 return newnode, bool(snode) |
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
967 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
968 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
969 def _rebaserestoredcommit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
970 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
971 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
972 opts, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
973 tr, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
974 oldtiprev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
975 basename, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
976 pctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
977 tmpwctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
978 shelvectx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
979 branchtorestore, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
980 activebookmark, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
981 ): |
30464
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30463
diff
changeset
|
982 """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
|
983 # 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
|
984 # we'll be merging with, rebase it to be on top. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
985 interactive = opts.get(b'interactive') |
42616
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
986 if tmpwctx.node() == shelvectx.p1().node() and not interactive: |
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
987 # We won't skip on interactive mode because, the user might want to |
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
988 # unshelve certain changes only. |
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
989 return shelvectx, False |
30464
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30463
diff
changeset
|
990 |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
991 overrides = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
992 (b'ui', b'forcemerge'): opts.get(b'tool', b''), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
993 (b'phases', b'new-commit'): phases.secret, |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
994 } |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
995 with repo.ui.configoverride(overrides, b'unshelve'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
996 ui.status(_(b'rebasing shelved changes\n')) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
997 stats = merge.graft( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
998 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
999 shelvectx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1000 shelvectx.p1(), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1001 labels=[b'shelve', b'working-copy'], |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1002 keepconflictparent=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1003 ) |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
1004 if stats.unresolvedcount: |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
1005 tr.close() |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
1006 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1007 nodestoremove = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1008 repo.changelog.node(rev) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1009 for rev in pycompat.xrange(oldtiprev, len(repo)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1010 ] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1011 shelvedstate.save( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1012 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1013 basename, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1014 pctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1015 tmpwctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1016 nodestoremove, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1017 branchtorestore, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1018 opts.get(b'keep'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1019 activebookmark, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1020 interactive, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1021 ) |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
1022 raise error.InterventionRequired( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1023 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1024 b"unresolved conflicts (see 'hg resolve', then " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1025 b"'hg unshelve --continue')" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1026 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1027 ) |
30464
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30463
diff
changeset
|
1028 |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
1029 with repo.dirstate.parentchange(): |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
1030 repo.setparents(tmpwctx.node(), nodemod.nullid) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1031 newnode, ispartialunshelve = _createunshelvectx( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1032 ui, repo, shelvectx, basename, interactive, opts |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1033 ) |
30464
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30463
diff
changeset
|
1034 |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
1035 if newnode is None: |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
1036 # 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
|
1037 # 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
|
1038 # here. Fix issue5494 |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
1039 merge.mergestate.clean(repo) |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
1040 shelvectx = tmpwctx |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1041 msg = _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1042 b'note: unshelved changes already existed ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1043 b'in the working copy\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1044 ) |
38618
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
1045 ui.status(msg) |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
1046 else: |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
1047 shelvectx = repo[newnode] |
c829749e7639
shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents:
38512
diff
changeset
|
1048 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
|
1049 |
42616
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
1050 return shelvectx, ispartialunshelve |
30464
10684a298973
shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30463
diff
changeset
|
1051 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1052 |
30465
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30464
diff
changeset
|
1053 def _forgetunknownfiles(repo, shelvectx, addedbefore): |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30464
diff
changeset
|
1054 # 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
|
1055 # unshelve started, but are now added. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1056 shelveunknown = shelvectx.extra().get(b'shelve_unknown') |
30465
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30464
diff
changeset
|
1057 if not shelveunknown: |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30464
diff
changeset
|
1058 return |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1059 shelveunknown = frozenset(shelveunknown.split(b'\0')) |
30465
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30464
diff
changeset
|
1060 addedafter = frozenset(repo.status().added) |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30464
diff
changeset
|
1061 toforget = (addedafter & shelveunknown) - addedbefore |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30464
diff
changeset
|
1062 repo[None].forget(toforget) |
b924375cce3a
shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30464
diff
changeset
|
1063 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1064 |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
1065 def _finishunshelve(repo, oldtiprev, tr, activebookmark): |
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
1066 _restoreactivebookmark(repo, activebookmark) |
30466
893be22cdb38
shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30465
diff
changeset
|
1067 # 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
|
1068 # 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
|
1069 # 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
|
1070 # 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
|
1071 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
|
1072 _aborttransaction(repo, tr) |
30466
893be22cdb38
shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents:
30465
diff
changeset
|
1073 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1074 |
30846
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
1075 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
|
1076 """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
|
1077 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
|
1078 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
|
1079 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
|
1080 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
|
1081 if intersection: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1082 m = _(b"shelved change touches missing files") |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1083 hint = _(b"run hg status to see which files are missing") |
30846
dfc6663f97ca
shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents:
30823
diff
changeset
|
1084 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
|
1085 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1086 |
42563
70f1a84d0794
unshelve: rename _dounshelve() to dounshelve()
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42548
diff
changeset
|
1087 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
|
1088 opts = pycompat.byteskwargs(opts) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1089 abortf = opts.get(b'abort') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1090 continuef = opts.get(b'continue') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1091 interactive = opts.get(b'interactive') |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1092 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
|
1093 cmdutil.checkunfinished(repo) |
31041
4189d790e8a4
shelve: add -n/--name option to unshelve (issue5475)
liscju <piotr.listkiewicz@gmail.com>
parents:
30846
diff
changeset
|
1094 shelved = list(shelved) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1095 if opts.get(b"name"): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1096 shelved.append(opts[b"name"]) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1097 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1098 if interactive and opts.get(b'keep'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1099 raise error.Abort(_(b'--keep on --interactive is not yet supported')) |
42691
ee86ad6f50fe
unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42690
diff
changeset
|
1100 if abortf or continuef: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1101 if abortf and continuef: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1102 raise error.Abort(_(b'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
|
1103 if shelved: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1104 raise error.Abort( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1105 _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1106 b'cannot combine abort/continue with ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1107 b'naming a shelved change' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1108 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1109 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1110 if abortf and opts.get(b'tool', False): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1111 ui.warn(_(b'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
|
1112 |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
1113 state = _loadshelvedstate(ui, repo, opts) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1114 if abortf: |
42599
3fb0493812c0
abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents:
42598
diff
changeset
|
1115 return unshelveabort(ui, repo, state) |
42695
52a383451739
unshelve: add abort on using continue and interactive together
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42691
diff
changeset
|
1116 elif continuef and interactive: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1117 raise error.Abort(_(b'cannot use both continue and interactive')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1118 elif continuef: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1119 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
|
1120 elif len(shelved) > 1: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1121 raise error.Abort(_(b'can only unshelve one change at a time')) |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1122 elif not shelved: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1123 shelved = listshelves(repo) |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1124 if not shelved: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1125 raise error.Abort(_(b'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
|
1126 basename = util.split(shelved[0][1])[1] |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1127 ui.status(_(b"unshelving change '%s'\n") % basename) |
42691
ee86ad6f50fe
unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42690
diff
changeset
|
1128 else: |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1129 basename = shelved[0] |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1130 |
30560
1775975dd439
shelve: move patch extension to a string constant
Kostia Balytskyi <ikostia@fb.com>
parents:
30551
diff
changeset
|
1131 if not shelvedfile(repo, basename, patchextension).exists(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1132 raise error.Abort(_(b"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
|
1133 |
39400
6a71324cb68b
shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents:
39399
diff
changeset
|
1134 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
|
1135 lock = tr = None |
19854
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1136 try: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1137 lock = repo.lock() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1138 tr = repo.transaction(b'unshelve', 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
|
1139 oldtiprev = len(repo) |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
1140 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1141 pctx = repo[b'.'] |
20958
df33c9014430
shelve: repo['.'] is not a wctx but a pctx
Mads Kiilerich <madski@unity3d.com>
parents:
20942
diff
changeset
|
1142 tmpwctx = pctx |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
1143 # 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
|
1144 # ...-> pctx -> tmpwctx -> shelvectx |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
1145 # 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
|
1146 # 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
|
1147 # to the original pctx. |
19961
1d7a36ff2615
shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents:
19951
diff
changeset
|
1148 |
31669
1cbeefa59343
shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents:
31561
diff
changeset
|
1149 activebookmark = _backupactivebookmark(repo) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1150 tmpwctx, addedbefore = _commitworkingcopychanges( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1151 ui, repo, opts, tmpwctx |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1152 ) |
41017
a06dc62f1c82
shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents:
40872
diff
changeset
|
1153 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
|
1154 _checkunshelveuntrackedproblems(ui, repo, shelvectx) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1155 branchtorestore = b'' |
38011
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1156 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
|
1157 branchtorestore = shelvectx.branch() |
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1158 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1159 shelvectx, ispartialunshelve = _rebaserestoredcommit( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1160 ui, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1161 repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1162 opts, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1163 tr, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1164 oldtiprev, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1165 basename, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1166 pctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1167 tmpwctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1168 shelvectx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1169 branchtorestore, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1170 activebookmark, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42777
diff
changeset
|
1171 ) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1172 overrides = {(b'ui', b'forcemerge'): opts.get(b'tool', b'')} |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1173 with ui.configoverride(overrides, b'unshelve'): |
38011
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1174 mergefiles(ui, repo, pctx, shelvectx) |
7932be8b0559
shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents:
37603
diff
changeset
|
1175 restorebranch(ui, repo, branchtorestore) |
42726
6957f7b93e03
unshelve: clear shelvedstate and _finishunshelve() on partial unshelve
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42725
diff
changeset
|
1176 shelvedstate.clear(repo) |
6957f7b93e03
unshelve: clear shelvedstate and _finishunshelve() on partial unshelve
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42725
diff
changeset
|
1177 _finishunshelve(repo, oldtiprev, tr, activebookmark) |
42750
d684449eef67
unshelve: forget unknown files after a partial unshelve
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42726
diff
changeset
|
1178 _forgetunknownfiles(repo, shelvectx, addedbefore) |
42616
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
1179 if not ispartialunshelve: |
5162753c4c14
unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
42614
diff
changeset
|
1180 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
|
1181 finally: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1182 if tr: |
49d4919d21c2
shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff
changeset
|
1183 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
|
1184 lockmod.release(lock) |