annotate mercurial/shelve.py @ 51817:adbfbbf9963f

shelve: consistently convert exception to bytes via `stringutil.forcebytestr` The other two places in this module use this, and past experience shows that this method does a nicer job. I'm not sure why we're converting to bytes here- `KeyError` is built-in and will have str attrs, and `RepoLookupError` is a subclass of the built-in `Exception` class (not `errors.Error`, which is allegedly the baseclass for all Mercurial exceptions).
author Matt Harbison <matt_harbison@yahoo.com>
date Tue, 20 Aug 2024 22:47:11 -0400
parents a1a94d488e14
children 607e94e01851
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
1 # shelve.py - save/restore working directory state
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
2 #
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
3 # Copyright 2013 Facebook, Inc.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
4 #
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
5 # This software may be used and distributed according to the terms of the
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
6 # GNU General Public License version 2 or any later version.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
7
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
8 """save and restore changes to the working directory
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
9
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
10 The "hg shelve" command saves changes made to the working directory
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
11 and reverts those changes, resetting the working directory to a clean
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
12 state.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
13
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
14 Later on, the "hg unshelve" command restores the changes saved by "hg
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
15 shelve". Changes can be restored even after updating to a different
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
16 parent, in which case Mercurial's merge machinery will resolve any
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
17 conflicts if necessary.
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
18
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
19 You can have more than one shelved change outstanding at a time; each
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
20 shelved change has a distinct name. For details, see the help for "hg
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
21 shelve".
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
22 """
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
23
25113
0ca8410ea345 util: drop alias for collections.deque
Martin von Zweigbergk <martinvonz@google.com>
parents: 25104
diff changeset
24 import collections
49426
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
25 import io
25712
8a6264a2ee60 shelve: always backup shelves instead of deleting them
Colin Chan <colinchan@fb.com>
parents: 25660
diff changeset
26 import itertools
36781
ffa3026d4196 cleanup: use stat_result[stat.ST_MTIME] instead of stat_result.st_mtime
Augie Fackler <augie@google.com>
parents: 36607
diff changeset
27 import stat
29205
a0939666b836 py3: move up symbol imports to enforce import-checker rules
Yuya Nishihara <yuya@tcha.org>
parents: 28862
diff changeset
28
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
29 from typing import (
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
30 Any,
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
31 Dict,
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
32 Iterable,
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
33 Iterator,
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
34 List,
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
35 Sequence,
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
36 Tuple,
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
37 )
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
38
42541
3de4f17f4824 shelve: move shelve extension to core
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42540
diff changeset
39 from .i18n import _
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
40 from .node import (
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
41 bin,
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
42 hex,
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
43 nullrev,
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
44 )
42541
3de4f17f4824 shelve: move shelve extension to core
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42540
diff changeset
45 from . import (
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
46 bookmarks,
28378
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
47 bundle2,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
48 changegroup,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
49 cmdutil,
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
50 context as contextmod,
34097
f7d41b85bbf6 changegroup: replace changegroupsubset with makechangegroup
Durham Goode <durham@fb.com>
parents: 33440
diff changeset
51 discovery,
28378
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
52 error,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
53 exchange,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
54 hg,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
55 lock as lockmod,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
56 mdiff,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
57 merge,
44856
b7808443ed6a mergestate: split out merge state handling code from main merge module
Augie Fackler <augie@google.com>
parents: 44595
diff changeset
58 mergestate as mergestatemod,
28378
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
59 patch,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
60 phases,
35005
aad6b9fdfc75 py3: handle keyword arguments in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34496
diff changeset
61 pycompat,
28378
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
62 repair,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
63 scmutil,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
64 templatefilters,
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
65 util,
31244
636f55b9ba23 vfs: use 'vfs' module directly in 'hgext.shelve'
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 31096
diff changeset
66 vfs as vfsmod,
28378
96a7368a79b6 shelve: use absolute_import
timeless <timeless@mozdev.org>
parents: 28124
diff changeset
67 )
42541
3de4f17f4824 shelve: move shelve extension to core
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42540
diff changeset
68 from .utils import (
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36781
diff changeset
69 dateutil,
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36781
diff changeset
70 stringutil,
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36781
diff changeset
71 )
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
72
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
73 backupdir = b'shelve-backup'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
74 shelvedir = b'shelved'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
75 shelvefileextensions = [b'hg', b'patch', b'shelve']
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
76
30381
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
77 # we never need the user, so we use a
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
78 # 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
79 shelveuser = b'shelve@localhost'
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
80
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
81
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
82 class ShelfDir:
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
83 def __init__(self, repo, for_backups: bool = False) -> None:
46296
eec8899407f4 shelve: also create class representing whole directory of shelves
Martin von Zweigbergk <martinvonz@google.com>
parents: 46295
diff changeset
84 if for_backups:
eec8899407f4 shelve: also create class representing whole directory of shelves
Martin von Zweigbergk <martinvonz@google.com>
parents: 46295
diff changeset
85 self.vfs = vfsmod.vfs(repo.vfs.join(backupdir))
eec8899407f4 shelve: also create class representing whole directory of shelves
Martin von Zweigbergk <martinvonz@google.com>
parents: 46295
diff changeset
86 else:
eec8899407f4 shelve: also create class representing whole directory of shelves
Martin von Zweigbergk <martinvonz@google.com>
parents: 46295
diff changeset
87 self.vfs = vfsmod.vfs(repo.vfs.join(shelvedir))
eec8899407f4 shelve: also create class representing whole directory of shelves
Martin von Zweigbergk <martinvonz@google.com>
parents: 46295
diff changeset
88
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
89 def get(self, name: bytes) -> "Shelf":
46296
eec8899407f4 shelve: also create class representing whole directory of shelves
Martin von Zweigbergk <martinvonz@google.com>
parents: 46295
diff changeset
90 return Shelf(self.vfs, name)
eec8899407f4 shelve: also create class representing whole directory of shelves
Martin von Zweigbergk <martinvonz@google.com>
parents: 46295
diff changeset
91
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
92 def listshelves(self) -> List[Tuple[float, bytes]]:
46297
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
93 """return all shelves in repo as list of (time, name)"""
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
94 try:
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
95 names = self.vfs.listdir()
49306
2e726c934fcd py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents: 49284
diff changeset
96 except FileNotFoundError:
46297
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
97 return []
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
98 info = []
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
99 seen = set()
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
100 for filename in names:
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
101 name = filename.rsplit(b'.', 1)[0]
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
102 if name in seen:
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
103 continue
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
104 seen.add(name)
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
105 shelf = self.get(name)
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
106 if not shelf.exists():
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
107 continue
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
108 mtime = shelf.mtime()
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
109 info.append((mtime, name))
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
110 return sorted(info, reverse=True)
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
111
46296
eec8899407f4 shelve: also create class representing whole directory of shelves
Martin von Zweigbergk <martinvonz@google.com>
parents: 46295
diff changeset
112
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
113 def _use_internal_phase(repo) -> bool:
49430
2064bbf7a1d5 phase-shelve: Implement a 'shelve.store' experimental config
Jason R. Coombs <jaraco@jaraco.com>
parents: 49429
diff changeset
114 return (
2064bbf7a1d5 phase-shelve: Implement a 'shelve.store' experimental config
Jason R. Coombs <jaraco@jaraco.com>
parents: 49429
diff changeset
115 phases.supportinternal(repo)
49457
53229e170496 phase-shelve: correct unicode string to honor 'shelve.store=internal'
Jason R. Coombs <jaraco@jaraco.com>
parents: 49430
diff changeset
116 and repo.ui.config(b'shelve', b'store') == b'internal'
49430
2064bbf7a1d5 phase-shelve: Implement a 'shelve.store' experimental config
Jason R. Coombs <jaraco@jaraco.com>
parents: 49429
diff changeset
117 )
2064bbf7a1d5 phase-shelve: Implement a 'shelve.store' experimental config
Jason R. Coombs <jaraco@jaraco.com>
parents: 49429
diff changeset
118
2064bbf7a1d5 phase-shelve: Implement a 'shelve.store' experimental config
Jason R. Coombs <jaraco@jaraco.com>
parents: 49429
diff changeset
119
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
120 def _target_phase(repo) -> int:
49430
2064bbf7a1d5 phase-shelve: Implement a 'shelve.store' experimental config
Jason R. Coombs <jaraco@jaraco.com>
parents: 49429
diff changeset
121 return phases.internal if _use_internal_phase(repo) else phases.secret
49429
fa00c407d61c phase-shelve: Extract function for _target_phase
Jason R. Coombs <jaraco@jaraco.com>
parents: 49427
diff changeset
122
fa00c407d61c phase-shelve: Extract function for _target_phase
Jason R. Coombs <jaraco@jaraco.com>
parents: 49427
diff changeset
123
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
124 class Shelf:
46273
efc71bb71682 shelve: introduce class representing a shelf
Martin von Zweigbergk <martinvonz@google.com>
parents: 46272
diff changeset
125 """Represents a shelf, including possibly multiple files storing it.
efc71bb71682 shelve: introduce class representing a shelf
Martin von Zweigbergk <martinvonz@google.com>
parents: 46272
diff changeset
126
efc71bb71682 shelve: introduce class representing a shelf
Martin von Zweigbergk <martinvonz@google.com>
parents: 46272
diff changeset
127 Old shelves will have a .patch and a .hg file. Newer shelves will
efc71bb71682 shelve: introduce class representing a shelf
Martin von Zweigbergk <martinvonz@google.com>
parents: 46272
diff changeset
128 also have a .shelve file. This class abstracts away some of the
efc71bb71682 shelve: introduce class representing a shelf
Martin von Zweigbergk <martinvonz@google.com>
parents: 46272
diff changeset
129 differences and lets you work with the shelf as a whole.
efc71bb71682 shelve: introduce class representing a shelf
Martin von Zweigbergk <martinvonz@google.com>
parents: 46272
diff changeset
130 """
efc71bb71682 shelve: introduce class representing a shelf
Martin von Zweigbergk <martinvonz@google.com>
parents: 46272
diff changeset
131
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
132 def __init__(self, vfs: vfsmod.vfs, name: bytes) -> None:
46291
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
133 self.vfs = vfs
46273
efc71bb71682 shelve: introduce class representing a shelf
Martin von Zweigbergk <martinvonz@google.com>
parents: 46272
diff changeset
134 self.name = name
46291
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
135
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
136 def exists(self) -> bool:
49427
c4417029e6c2 phase-shelve: honor and prefer obs shelves for existence and modified time
Jason R. Coombs <jaraco@jaraco.com>
parents: 49426
diff changeset
137 return self._exists(b'.shelve') or self._exists(b'.patch', b'.hg')
c4417029e6c2 phase-shelve: honor and prefer obs shelves for existence and modified time
Jason R. Coombs <jaraco@jaraco.com>
parents: 49426
diff changeset
138
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
139 def _exists(self, *exts: bytes) -> bool:
49427
c4417029e6c2 phase-shelve: honor and prefer obs shelves for existence and modified time
Jason R. Coombs <jaraco@jaraco.com>
parents: 49426
diff changeset
140 return all(self.vfs.exists(self.name + ext) for ext in exts)
46273
efc71bb71682 shelve: introduce class representing a shelf
Martin von Zweigbergk <martinvonz@google.com>
parents: 46272
diff changeset
141
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
142 def mtime(self) -> float:
49427
c4417029e6c2 phase-shelve: honor and prefer obs shelves for existence and modified time
Jason R. Coombs <jaraco@jaraco.com>
parents: 49426
diff changeset
143 try:
c4417029e6c2 phase-shelve: honor and prefer obs shelves for existence and modified time
Jason R. Coombs <jaraco@jaraco.com>
parents: 49426
diff changeset
144 return self._stat(b'.shelve')[stat.ST_MTIME]
c4417029e6c2 phase-shelve: honor and prefer obs shelves for existence and modified time
Jason R. Coombs <jaraco@jaraco.com>
parents: 49426
diff changeset
145 except FileNotFoundError:
c4417029e6c2 phase-shelve: honor and prefer obs shelves for existence and modified time
Jason R. Coombs <jaraco@jaraco.com>
parents: 49426
diff changeset
146 return self._stat(b'.patch')[stat.ST_MTIME]
c4417029e6c2 phase-shelve: honor and prefer obs shelves for existence and modified time
Jason R. Coombs <jaraco@jaraco.com>
parents: 49426
diff changeset
147
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
148 def _stat(self, ext: bytes):
49427
c4417029e6c2 phase-shelve: honor and prefer obs shelves for existence and modified time
Jason R. Coombs <jaraco@jaraco.com>
parents: 49426
diff changeset
149 return self.vfs.stat(self.name + ext)
46280
7e300d297547 shelve: move method for getting stat (mtime) to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46279
diff changeset
150
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
151 def writeinfo(self, info) -> None:
46274
a344ec05b99c shelve: move method for writing .shelve to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46273
diff changeset
152 scmutil.simplekeyvaluefile(self.vfs, self.name + b'.shelve').write(info)
a344ec05b99c shelve: move method for writing .shelve to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46273
diff changeset
153
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
154 def hasinfo(self) -> bool:
46286
3b08f56c8a11 shelve: teach new shelf class to check if .shelve file exists
Martin von Zweigbergk <martinvonz@google.com>
parents: 46285
diff changeset
155 return self.vfs.exists(self.name + b'.shelve')
3b08f56c8a11 shelve: teach new shelf class to check if .shelve file exists
Martin von Zweigbergk <martinvonz@google.com>
parents: 46285
diff changeset
156
46275
157305bf859f shelve: move method for reading .shelve file to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46274
diff changeset
157 def readinfo(self):
157305bf859f shelve: move method for reading .shelve file to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46274
diff changeset
158 return scmutil.simplekeyvaluefile(
157305bf859f shelve: move method for reading .shelve file to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46274
diff changeset
159 self.vfs, self.name + b'.shelve'
157305bf859f shelve: move method for reading .shelve file to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46274
diff changeset
160 ).read()
157305bf859f shelve: move method for reading .shelve file to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46274
diff changeset
161
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
162 def writebundle(self, repo, bases, node) -> None:
46291
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
163 cgversion = changegroup.safeversion(repo)
46276
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
164 if cgversion == b'01':
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
165 btype = b'HG10BZ'
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
166 compression = None
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
167 else:
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
168 btype = b'HG20'
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
169 compression = b'BZ'
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
170
46291
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
171 repo = repo.unfiltered()
46276
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
172
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
173 outgoing = discovery.outgoing(
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
174 repo, missingroots=bases, ancestorsof=[node]
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
175 )
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
176 cg = changegroup.makechangegroup(repo, outgoing, cgversion, b'shelve')
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
177
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
178 bundle_filename = self.vfs.join(self.name + b'.hg')
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
179 bundle2.writebundle(
46291
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
180 repo.ui,
46276
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
181 cg,
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
182 bundle_filename,
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
183 btype,
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
184 self.vfs,
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
185 compression=compression,
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
186 )
eb7b2929ae49 shelve: move method for writing bundle to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46275
diff changeset
187
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
188 def applybundle(self, repo, tr) -> contextmod.changectx:
46277
ed2f2150d57c shelve: move method for reading .hg to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46276
diff changeset
189 filename = self.name + b'.hg'
ed2f2150d57c shelve: move method for reading .hg to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46276
diff changeset
190 fp = self.vfs(filename)
ed2f2150d57c shelve: move method for reading .hg to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46276
diff changeset
191 try:
49429
fa00c407d61c phase-shelve: Extract function for _target_phase
Jason R. Coombs <jaraco@jaraco.com>
parents: 49427
diff changeset
192 targetphase = _target_phase(repo)
46291
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
193 gen = exchange.readbundle(repo.ui, fp, filename, self.vfs)
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
194 pretip = repo[b'tip']
46277
ed2f2150d57c shelve: move method for reading .hg to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46276
diff changeset
195 bundle2.applybundle(
46291
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
196 repo,
46277
ed2f2150d57c shelve: move method for reading .hg to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46276
diff changeset
197 gen,
ed2f2150d57c shelve: move method for reading .hg to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46276
diff changeset
198 tr,
ed2f2150d57c shelve: move method for reading .hg to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46276
diff changeset
199 source=b'unshelve',
ed2f2150d57c shelve: move method for reading .hg to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46276
diff changeset
200 url=b'bundle:' + self.vfs.join(filename),
ed2f2150d57c shelve: move method for reading .hg to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46276
diff changeset
201 targetphase=targetphase,
ed2f2150d57c shelve: move method for reading .hg to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46276
diff changeset
202 )
46291
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
203 shelvectx = repo[b'tip']
46277
ed2f2150d57c shelve: move method for reading .hg to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46276
diff changeset
204 if pretip == shelvectx:
ed2f2150d57c shelve: move method for reading .hg to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46276
diff changeset
205 shelverev = tr.changes[b'revduplicates'][-1]
46291
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
206 shelvectx = repo[shelverev]
46277
ed2f2150d57c shelve: move method for reading .hg to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46276
diff changeset
207 return shelvectx
ed2f2150d57c shelve: move method for reading .hg to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46276
diff changeset
208 finally:
ed2f2150d57c shelve: move method for reading .hg to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46276
diff changeset
209 fp.close()
ed2f2150d57c shelve: move method for reading .hg to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46276
diff changeset
210
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
211 def open_patch(self, mode: bytes = b'rb'):
46278
58ca94869287 shelve: move function for opening .patch file to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46277
diff changeset
212 return self.vfs(self.name + b'.patch', mode)
58ca94869287 shelve: move function for opening .patch file to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46277
diff changeset
213
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
214 def patch_from_node(self, repo, node) -> io.BytesIO:
49426
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
215 repo = repo.unfiltered()
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
216 match = _optimized_match(repo, node)
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
217 fp = io.BytesIO()
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
218 cmdutil.exportfile(
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
219 repo,
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
220 [node],
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
221 fp,
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
222 opts=mdiff.diffopts(git=True),
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
223 match=match,
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
224 )
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
225 fp.seek(0)
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
226 return fp
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
227
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
228 def load_patch(self, repo):
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
229 try:
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
230 # prefer node-based shelf
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
231 return self.patch_from_node(repo, self.readinfo()[b'node'])
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
232 except (FileNotFoundError, error.RepoLookupError):
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
233 return self.open_patch()
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
234
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
235 def _backupfilename(self, backupvfs: vfsmod.vfs, filename: bytes) -> bytes:
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
236 def gennames(base: bytes):
46285
e79f8ae0901b shelve: move method for creating backup to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46284
diff changeset
237 yield base
e79f8ae0901b shelve: move method for creating backup to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46284
diff changeset
238 base, ext = base.rsplit(b'.', 1)
e79f8ae0901b shelve: move method for creating backup to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46284
diff changeset
239 for i in itertools.count(1):
e79f8ae0901b shelve: move method for creating backup to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46284
diff changeset
240 yield b'%s-%d.%s' % (base, i, ext)
e79f8ae0901b shelve: move method for creating backup to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46284
diff changeset
241
e79f8ae0901b shelve: move method for creating backup to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46284
diff changeset
242 for n in gennames(filename):
46291
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
243 if not backupvfs.exists(n):
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
244 return backupvfs.join(n)
46285
e79f8ae0901b shelve: move method for creating backup to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46284
diff changeset
245
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
246 # Help pytype- gennames() yields infinitely
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
247 raise error.ProgrammingError("unreachable")
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
248
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
249 def movetobackup(self, backupvfs: vfsmod.vfs) -> None:
46291
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
250 if not backupvfs.isdir():
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
251 backupvfs.makedir()
46285
e79f8ae0901b shelve: move method for creating backup to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46284
diff changeset
252 for suffix in shelvefileextensions:
e79f8ae0901b shelve: move method for creating backup to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46284
diff changeset
253 filename = self.name + b'.' + suffix
e79f8ae0901b shelve: move method for creating backup to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46284
diff changeset
254 if self.vfs.exists(filename):
e79f8ae0901b shelve: move method for creating backup to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46284
diff changeset
255 util.rename(
46291
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
256 self.vfs.join(filename),
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
257 self._backupfilename(backupvfs, filename),
46285
e79f8ae0901b shelve: move method for creating backup to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46284
diff changeset
258 )
e79f8ae0901b shelve: move method for creating backup to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46284
diff changeset
259
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
260 def delete(self) -> None:
46295
f8c5e6ecd008 shelve: add a method for deleting shelf to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46294
diff changeset
261 for ext in shelvefileextensions:
f8c5e6ecd008 shelve: add a method for deleting shelf to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46294
diff changeset
262 self.vfs.tryunlink(self.name + b'.' + ext)
f8c5e6ecd008 shelve: add a method for deleting shelf to new shelf class
Martin von Zweigbergk <martinvonz@google.com>
parents: 46294
diff changeset
263
49586
636cd96806a7 shelve: add Shelf.changed_files for resolving changed files in a plugin
Jason R. Coombs <jaraco@jaraco.com>
parents: 49560
diff changeset
264 def changed_files(self, ui, repo):
636cd96806a7 shelve: add Shelf.changed_files for resolving changed files in a plugin
Jason R. Coombs <jaraco@jaraco.com>
parents: 49560
diff changeset
265 try:
636cd96806a7 shelve: add Shelf.changed_files for resolving changed files in a plugin
Jason R. Coombs <jaraco@jaraco.com>
parents: 49560
diff changeset
266 ctx = repo.unfiltered()[self.readinfo()[b'node']]
636cd96806a7 shelve: add Shelf.changed_files for resolving changed files in a plugin
Jason R. Coombs <jaraco@jaraco.com>
parents: 49560
diff changeset
267 return ctx.files()
636cd96806a7 shelve: add Shelf.changed_files for resolving changed files in a plugin
Jason R. Coombs <jaraco@jaraco.com>
parents: 49560
diff changeset
268 except (FileNotFoundError, error.RepoLookupError):
636cd96806a7 shelve: add Shelf.changed_files for resolving changed files in a plugin
Jason R. Coombs <jaraco@jaraco.com>
parents: 49560
diff changeset
269 filename = self.vfs.join(self.name + b'.patch')
636cd96806a7 shelve: add Shelf.changed_files for resolving changed files in a plugin
Jason R. Coombs <jaraco@jaraco.com>
parents: 49560
diff changeset
270 return patch.changedfiles(ui, repo, filename)
636cd96806a7 shelve: add Shelf.changed_files for resolving changed files in a plugin
Jason R. Coombs <jaraco@jaraco.com>
parents: 49560
diff changeset
271
46273
efc71bb71682 shelve: introduce class representing a shelf
Martin von Zweigbergk <martinvonz@google.com>
parents: 46272
diff changeset
272
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
273 def _optimized_match(repo, node: bytes):
49425
35c9f0bc2648 phase-shelve: Extract function for _optimized_match for re-use
Jason R. Coombs <jaraco@jaraco.com>
parents: 49306
diff changeset
274 """
35c9f0bc2648 phase-shelve: Extract function for _optimized_match for re-use
Jason R. Coombs <jaraco@jaraco.com>
parents: 49306
diff changeset
275 Create a matcher so that prefetch doesn't attempt to fetch
35c9f0bc2648 phase-shelve: Extract function for _optimized_match for re-use
Jason R. Coombs <jaraco@jaraco.com>
parents: 49306
diff changeset
276 the entire repository pointlessly, and as an optimisation
35c9f0bc2648 phase-shelve: Extract function for _optimized_match for re-use
Jason R. Coombs <jaraco@jaraco.com>
parents: 49306
diff changeset
277 for movedirstate, if needed.
35c9f0bc2648 phase-shelve: Extract function for _optimized_match for re-use
Jason R. Coombs <jaraco@jaraco.com>
parents: 49306
diff changeset
278 """
35c9f0bc2648 phase-shelve: Extract function for _optimized_match for re-use
Jason R. Coombs <jaraco@jaraco.com>
parents: 49306
diff changeset
279 return scmutil.matchfiles(repo, repo[node].files())
35c9f0bc2648 phase-shelve: Extract function for _optimized_match for re-use
Jason R. Coombs <jaraco@jaraco.com>
parents: 49306
diff changeset
280
35c9f0bc2648 phase-shelve: Extract function for _optimized_match for re-use
Jason R. Coombs <jaraco@jaraco.com>
parents: 49306
diff changeset
281
48946
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48875
diff changeset
282 class shelvedstate:
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
283 """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
284
df54786a3203 shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19908
diff changeset
285 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
286 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
287 """
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
288
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
289 # Class-wide constants
32285
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
290 _version = 2
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
291 _filename = b'shelvedstate'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
292 _keep = b'keep'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
293 _nokeep = b'nokeep'
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
294 # 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
295 _noactivebook = b':no-active-bookmark'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
296 _interactive = b'interactive'
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
297
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
298 # Per instance attrs
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
299 name: bytes
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
300 wctx: contextmod.workingctx
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
301 pendingctx: contextmod.changectx
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
302 parents: List[bytes]
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
303 nodestoremove: List[bytes]
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
304 branchtorestore: bytes
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
305 keep: bool
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
306 activebookmark: bytes
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
307 interactive: bool
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
308
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
309 @classmethod
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
310 def _verifyandtransform(cls, d: Dict[bytes, Any]) -> None:
32285
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
311 """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
312 try:
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
313 d[b'originalwctx'] = bin(d[b'originalwctx'])
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
314 d[b'pendingctx'] = bin(d[b'pendingctx'])
49560
5f778b3a94ca shelve: handle empty parents and nodestoremove in shelvedstate (issue6748)
Jason R. Coombs <jaraco@jaraco.com>
parents: 49527
diff changeset
315 d[b'parents'] = [bin(h) for h in d[b'parents'].split(b' ') if h]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
316 d[b'nodestoremove'] = [
49560
5f778b3a94ca shelve: handle empty parents and nodestoremove in shelvedstate (issue6748)
Jason R. Coombs <jaraco@jaraco.com>
parents: 49527
diff changeset
317 bin(h) for h in d[b'nodestoremove'].split(b' ') if h
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
318 ]
49248
63fd0282ad40 node: stop converting binascii.Error to TypeError in bin()
Manuel Jacob <me@manueljacob.de>
parents: 48946
diff changeset
319 except (ValueError, KeyError) as err:
46640
e571fec5b606 shelve: fix conversion of exceptions to strings flagged by pytype
Matt Harbison <matt_harbison@yahoo.com>
parents: 46361
diff changeset
320 raise error.CorruptedState(stringutil.forcebytestr(err))
32284
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
321
32285
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
322 @classmethod
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
323 def _getversion(cls, repo) -> int:
32285
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
324 """Read version information from shelvestate file"""
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
325 fp = repo.vfs(cls._filename)
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
326 try:
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
327 version = int(fp.readline().strip())
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
328 except ValueError as err:
46640
e571fec5b606 shelve: fix conversion of exceptions to strings flagged by pytype
Matt Harbison <matt_harbison@yahoo.com>
parents: 46361
diff changeset
329 raise error.CorruptedState(stringutil.forcebytestr(err))
32285
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
330 finally:
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
331 fp.close()
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
332 return version
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
333
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
334 @classmethod
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
335 def _readold(cls, repo) -> Dict[bytes, Any]:
32285
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
336 """Read the old position-based version of a shelvestate file"""
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
337 # Order is important, because old shelvestate file uses it
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
338 # 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: 32284
diff changeset
339 # originalwctx is on the third and so forth). Please do not change.
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
340 keys = [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
341 b'version',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
342 b'name',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
343 b'originalwctx',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
344 b'pendingctx',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
345 b'parents',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
346 b'nodestoremove',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
347 b'branchtorestore',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
348 b'keep',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
349 b'activebook',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
350 ]
32285
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
351 # this is executed only seldomly, so it is not a big deal
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
352 # that we open this file twice
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
353 fp = repo.vfs(cls._filename)
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
354 d = {}
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
355 try:
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
356 for key in keys:
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
357 d[key] = fp.readline().strip()
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
358 finally:
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
359 fp.close()
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
360 return d
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
361
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
362 @classmethod
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
363 def load(cls, repo):
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
364 version = cls._getversion(repo)
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
365 if version < cls._version:
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
366 d = cls._readold(repo)
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
367 elif version == cls._version:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
368 d = scmutil.simplekeyvaluefile(repo.vfs, cls._filename).read(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
369 firstlinenonkeyval=True
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
370 )
32285
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
371 else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
372 raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
373 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
374 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
375 b'with the version used in this repo'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
376 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
377 )
32285
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
378
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
379 cls._verifyandtransform(d)
29536
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
380 try:
b17a6e3cd2ac shelve: make unshelve be able to abort in any case
Kostia Balytskyi <ikostia@fb.com>
parents: 29270
diff changeset
381 obj = cls()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
382 obj.name = d[b'name']
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
383 obj.wctx = repo[d[b'originalwctx']]
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
384 obj.pendingctx = repo[d[b'pendingctx']]
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
385 obj.parents = d[b'parents']
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
386 obj.nodestoremove = d[b'nodestoremove']
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
387 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
388 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
389 obj.activebookmark = b''
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
390 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
391 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
392 obj.interactive = d.get(b'interactive') == cls._interactive
32284
16d424b97125 shelve: refactor shelvestate loading
Kostia Balytskyi <ikostia@fb.com>
parents: 31888
diff changeset
393 except (error.RepoLookupError, KeyError) as err:
51817
adbfbbf9963f shelve: consistently convert exception to bytes via `stringutil.forcebytestr`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51816
diff changeset
394 raise error.CorruptedState(stringutil.forcebytestr(err))
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
395
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
396 return obj
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
397
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
398 @classmethod
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
399 def save(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
400 cls,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
401 repo,
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
402 name: bytes,
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
403 originalwctx: contextmod.workingctx,
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
404 pendingctx: contextmod.changectx,
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
405 nodestoremove: List[bytes],
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
406 branchtorestore: bytes,
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
407 keep: bool = False,
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
408 activebook: bytes = b'',
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
409 interactive: bool = False,
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
410 ) -> None:
32285
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
411 info = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
412 b"name": name,
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
413 b"originalwctx": hex(originalwctx.node()),
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
414 b"pendingctx": hex(pendingctx.node()),
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
415 b"parents": b' '.join([hex(p) for p in repo.dirstate.parents()]),
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
416 b"nodestoremove": b' '.join([hex(n) for n in nodestoremove]),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
417 b"branchtorestore": branchtorestore,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
418 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
419 b"activebook": activebook or cls._noactivebook,
32285
fe3105e6e051 shelve: make shelvestate use simplekeyvaluefile
Kostia Balytskyi <ikostia@fb.com>
parents: 32284
diff changeset
420 }
42662
ee86ad6f50fe unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42658
diff changeset
421 if interactive:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
422 info[b'interactive'] = cls._interactive
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
423 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
424 info, firstline=(b"%d" % cls._version)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
425 )
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
426
19908
07ee5c8867ca shelve: use the class constant in the clear method
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19904
diff changeset
427 @classmethod
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
428 def clear(cls, repo) -> None:
31311
f59b6cf663a9 vfs: use repo.vfs.unlinkpath
Mads Kiilerich <mads@kiilerich.com>
parents: 31244
diff changeset
429 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
430
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
431
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
432 def cleanupoldbackups(repo) -> None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
433 maxbackups = repo.ui.configint(b'shelve', b'maxbackups')
46297
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
434 backup_dir = ShelfDir(repo, for_backups=True)
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
435 hgfiles = backup_dir.listshelves()
40029
e2697acd9381 cleanup: some Yoda conditions, this patch removes
Martin von Zweigbergk <martinvonz@google.com>
parents: 39889
diff changeset
436 if maxbackups > 0 and maxbackups < len(hgfiles):
46293
9cdef4c41c94 shelve: use listshelves() in cleanupoldbackups()
Martin von Zweigbergk <martinvonz@google.com>
parents: 46292
diff changeset
437 bordermtime = hgfiles[maxbackups - 1][0]
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
438 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
439 bordermtime = None
46293
9cdef4c41c94 shelve: use listshelves() in cleanupoldbackups()
Martin von Zweigbergk <martinvonz@google.com>
parents: 46292
diff changeset
440 for mtime, name in 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
441 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
442 # 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
443 continue
46297
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
444 backup_dir.get(name).delete()
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
445
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
446
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
447 def _backupactivebookmark(repo) -> bytes:
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
448 activebookmark = repo._activebookmark
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
449 if activebookmark:
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
450 bookmarks.deactivate(repo)
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
451 return activebookmark
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
452
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
453
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
454 def _restoreactivebookmark(repo, mark) -> None:
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
455 if mark:
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
456 bookmarks.activate(repo, mark)
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
457
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
458
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
459 def _aborttransaction(repo, tr) -> None:
45942
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45860
diff changeset
460 """Abort current transaction for shelve/unshelve, but keep dirstate"""
50079
acd2a0267660 dirstate: simplify the shelve hack to not go through the disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50054
diff changeset
461 # disable the transaction invalidation of the dirstate, to preserve the
acd2a0267660 dirstate: simplify the shelve hack to not go through the disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50054
diff changeset
462 # current change in memory.
acd2a0267660 dirstate: simplify the shelve hack to not go through the disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50054
diff changeset
463 ds = repo.dirstate
acd2a0267660 dirstate: simplify the shelve hack to not go through the disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50054
diff changeset
464 # The assert below check that nobody else did such wrapping.
acd2a0267660 dirstate: simplify the shelve hack to not go through the disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50054
diff changeset
465 #
acd2a0267660 dirstate: simplify the shelve hack to not go through the disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50054
diff changeset
466 # These is not such other wrapping currently, but if someone try to
acd2a0267660 dirstate: simplify the shelve hack to not go through the disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50054
diff changeset
467 # implement one in the future, this will explicitly break here instead of
acd2a0267660 dirstate: simplify the shelve hack to not go through the disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50054
diff changeset
468 # misbehaving in subtle ways.
50195
11e6eee4b063 transaction: use the standard transaction mechanism to backup branch
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50079
diff changeset
469 current_branch = ds.branch()
50079
acd2a0267660 dirstate: simplify the shelve hack to not go through the disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50054
diff changeset
470 assert 'invalidate' not in vars(ds)
acd2a0267660 dirstate: simplify the shelve hack to not go through the disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50054
diff changeset
471 try:
acd2a0267660 dirstate: simplify the shelve hack to not go through the disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50054
diff changeset
472 # note : we could simply disable the transaction abort callback, but
acd2a0267660 dirstate: simplify the shelve hack to not go through the disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50054
diff changeset
473 # other code also tries to rollback and invalidate this.
acd2a0267660 dirstate: simplify the shelve hack to not go through the disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50054
diff changeset
474 ds.invalidate = lambda: None
acd2a0267660 dirstate: simplify the shelve hack to not go through the disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50054
diff changeset
475 tr.abort()
acd2a0267660 dirstate: simplify the shelve hack to not go through the disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50054
diff changeset
476 finally:
acd2a0267660 dirstate: simplify the shelve hack to not go through the disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50054
diff changeset
477 del ds.invalidate
acd2a0267660 dirstate: simplify the shelve hack to not go through the disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50054
diff changeset
478 # manually write the change in memory since we can no longer rely on the
acd2a0267660 dirstate: simplify the shelve hack to not go through the disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50054
diff changeset
479 # transaction to do so.
acd2a0267660 dirstate: simplify the shelve hack to not go through the disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50054
diff changeset
480 assert repo.currenttransaction() is None
acd2a0267660 dirstate: simplify the shelve hack to not go through the disk
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50054
diff changeset
481 repo.dirstate.write(None)
50264
921f4834b7b5 branch: pass current transaction when writing branch in shelve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50195
diff changeset
482 ds.setbranch(current_branch, None)
26522
10f14bb22950 shelve: add utility to abort current transaction but keep dirstate
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26520
diff changeset
483
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
484
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
485 def getshelvename(repo, parent, opts) -> bytes:
30379
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
486 """Decide on the name this shelve is going to have"""
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
487
30379
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
488 def gennames():
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
489 yield label
32968
4107eb8a5648 shelve: allow unlimited shelved changes per name
Jun Wu <quark@fb.com>
parents: 32930
diff changeset
490 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
491 yield b'%s-%02d' % (label, i)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
492
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
493 name = opts.get(b'name')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
494 label = repo._activebookmark or parent.branch() or b'default'
30379
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
495 # 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
496 label = label.replace(b'/', b'_')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
497 label = label.replace(b'\\', b'_')
30671
64a75655b988 shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30554
diff changeset
498 # 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
499 if label.startswith(b'.'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
500 label = label.replace(b'.', b'_', 1)
30379
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
501
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
502 if name:
46296
eec8899407f4 shelve: also create class representing whole directory of shelves
Martin von Zweigbergk <martinvonz@google.com>
parents: 46295
diff changeset
503 if ShelfDir(repo).get(name).exists():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
504 e = _(b"a shelved change named '%s' already exists") % name
30379
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
505 raise error.Abort(e)
30671
64a75655b988 shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30554
diff changeset
506
64a75655b988 shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30554
diff changeset
507 # 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
508 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
509 raise error.Abort(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
510 _(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
511 )
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
512 if name.startswith(b'.'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
513 raise error.Abort(_(b"shelved change names can not start with '.'"))
30671
64a75655b988 shelve: choose a legal shelve name when no name is passed (issue5112)
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30554
diff changeset
514
30379
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
515 else:
46296
eec8899407f4 shelve: also create class representing whole directory of shelves
Martin von Zweigbergk <martinvonz@google.com>
parents: 46295
diff changeset
516 shelf_dir = ShelfDir(repo)
30379
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
517 for n in gennames():
46296
eec8899407f4 shelve: also create class representing whole directory of shelves
Martin von Zweigbergk <martinvonz@google.com>
parents: 46295
diff changeset
518 if not shelf_dir.get(n).exists():
30379
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
519 name = n
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
520 break
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
521
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
522 return name
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
523
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
524
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
525 def mutableancestors(ctx) -> Iterator[bytes]:
30380
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
526 """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
527
30380
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
528 Much faster than the revset ancestors(ctx) & draft()"""
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
529 seen = {nullrev}
30380
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
530 visit = collections.deque()
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
531 visit.append(ctx)
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
532 while visit:
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
533 ctx = visit.popleft()
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
534 yield ctx.node()
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
535 for parent in ctx.parents():
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
536 rev = parent.rev()
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
537 if rev not in seen:
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
538 seen.add(rev)
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
539 if parent.mutable():
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
540 visit.append(parent)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
541
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
542
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
543 def getcommitfunc(extra, interactive: bool, editor: bool = False):
30381
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
544 def commitfunc(ui, repo, message, match, opts):
50928
d718eddf01d9 safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50596
diff changeset
545 hasmq = hasattr(repo, 'mq')
30381
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
546 if hasmq:
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
547 saved, repo.mq.checkapplied = repo.mq.checkapplied, False
39519
5d69e2412ec8 shelve: use the internal phase when possible
Boris Feld <boris.feld@octobus.net>
parents: 39387
diff changeset
548
49429
fa00c407d61c phase-shelve: Extract function for _target_phase
Jason R. Coombs <jaraco@jaraco.com>
parents: 49427
diff changeset
549 targetphase = _target_phase(repo)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
550 overrides = {(b'phases', b'new-commit'): targetphase}
30381
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
551 try:
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
552 editor_ = False
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
553 if editor:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
554 editor_ = cmdutil.getcommiteditor(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
555 editform=b'shelve.shelve', **pycompat.strkwargs(opts)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
556 )
31462
d1ce2124ec83 shelve: get rid of ui.backupconfig
Jun Wu <quark@fb.com>
parents: 31335
diff changeset
557 with repo.ui.configoverride(overrides):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
558 return repo.commit(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
559 message,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
560 shelveuser,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
561 opts.get(b'date'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
562 match,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
563 editor=editor_,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
564 extra=extra,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
565 )
30381
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
566 finally:
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
567 if hasmq:
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
568 repo.mq.checkapplied = saved
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
569
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
570 def interactivecommitfunc(ui, repo, *pats, **opts):
35005
aad6b9fdfc75 py3: handle keyword arguments in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34496
diff changeset
571 opts = pycompat.byteskwargs(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
572 match = scmutil.match(repo[b'.'], pats, {})
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
573 message = opts[b'message']
30381
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
574 return commitfunc(ui, repo, message, match, opts)
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
575
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
576 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
577
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
578
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
579 def _nothingtoshelvemessaging(ui, repo, pats, opts) -> None:
30382
dedf0915ca5b shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30381
diff changeset
580 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: 30381
diff changeset
581 if stat.deleted:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
582 ui.status(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43085
diff changeset
583 _(b"nothing changed (%d missing files, see 'hg status')\n")
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
584 % len(stat.deleted)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
585 )
30382
dedf0915ca5b shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30381
diff changeset
586 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
587 ui.status(_(b"nothing changed\n"))
30382
dedf0915ca5b shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30381
diff changeset
588
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
589
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
590 def _shelvecreatedcommit(repo, node: bytes, name: bytes, match) -> None:
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
591 info = {b'node': hex(node)}
46296
eec8899407f4 shelve: also create class representing whole directory of shelves
Martin von Zweigbergk <martinvonz@google.com>
parents: 46295
diff changeset
592 shelf = ShelfDir(repo).get(name)
46287
ae7a77a7ebc0 shelve: extract some repeated creation of shelf instances to variables
Martin von Zweigbergk <martinvonz@google.com>
parents: 46286
diff changeset
593 shelf.writeinfo(info)
30383
455f7856db20 shelve: move actual created commit shelving to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30382
diff changeset
594 bases = list(mutableancestors(repo[node]))
46291
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
595 shelf.writebundle(repo, bases, node)
46287
ae7a77a7ebc0 shelve: extract some repeated creation of shelf instances to variables
Martin von Zweigbergk <martinvonz@google.com>
parents: 46286
diff changeset
596 with shelf.open_patch(b'wb') as fp:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
597 cmdutil.exportfile(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
598 repo, [node], fp, opts=mdiff.diffopts(git=True), match=match
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
599 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
600
30383
455f7856db20 shelve: move actual created commit shelving to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30382
diff changeset
601
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
602 def _includeunknownfiles(repo, pats, opts, extra) -> None:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
603 s = repo.status(match=scmutil.match(repo[None], pats, opts), unknown=True)
30384
21a75b63c10e shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30383
diff changeset
604 if s.unknown:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
605 extra[b'shelve_unknown'] = b'\0'.join(s.unknown)
30384
21a75b63c10e shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30383
diff changeset
606 repo[None].add(s.unknown)
21a75b63c10e shelve: move unknown files handling to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30383
diff changeset
607
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
608
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
609 def _finishshelve(repo, tr) -> None:
49430
2064bbf7a1d5 phase-shelve: Implement a 'shelve.store' experimental config
Jason R. Coombs <jaraco@jaraco.com>
parents: 49429
diff changeset
610 if _use_internal_phase(repo):
39744
52dfa1eb0ad4 shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents: 39601
diff changeset
611 tr.close()
52dfa1eb0ad4 shelve: no longer strip internal commit when using internal phase
Boris Feld <boris.feld@octobus.net>
parents: 39601
diff changeset
612 else:
41007
a06dc62f1c82 shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents: 40854
diff changeset
613 _aborttransaction(repo, tr)
30385
b573d7ca31c4 shelve: move shelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30384
diff changeset
614
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
615
39342
d52fa7ddd1ac shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents: 38869
diff changeset
616 def createcmd(ui, repo, pats, opts):
d52fa7ddd1ac shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents: 38869
diff changeset
617 """subcommand that creates a new shelve"""
d52fa7ddd1ac shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents: 38869
diff changeset
618 with repo.wlock():
d52fa7ddd1ac shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents: 38869
diff changeset
619 cmdutil.checkunfinished(repo)
d52fa7ddd1ac shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents: 38869
diff changeset
620 return _docreatecmd(ui, repo, pats, opts)
d52fa7ddd1ac shelve: move createcmd next to _docreatecmd
Boris Feld <boris.feld@octobus.net>
parents: 38869
diff changeset
621
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
622
30380
84e8cbdbdee4 shelve: move mutableancestors to not be a closure
Kostia Balytskyi <ikostia@fb.com>
parents: 30379
diff changeset
623 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
624 wctx = repo[None]
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
625 parents = wctx.parents()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
626 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
627 origbranch = wctx.branch()
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
628
46843
728d89f6f9b1 refactor: prefer checks against nullrev over nullid
Joerg Sonnenberger <joerg@bec.de>
parents: 46640
diff changeset
629 if parent.rev() != nullrev:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
630 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
631 else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
632 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
633
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
634 if not opts.get(b'message'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
635 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
636
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
637 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
638 try:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
639 lock = repo.lock()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
640
19951
d51c4d85ec23 spelling: random spell checker fixes
Mads Kiilerich <madski@unity3d.com>
parents: 19943
diff changeset
641 # 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
642 # 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
643 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
644
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
645 interactive = opts.get(b'interactive', False)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
646 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
647 b'addremove', False
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
648 )
27908
d73a5ab18015 shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents: 27888
diff changeset
649
30379
684068d24658 shelve: move shelve name generation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30378
diff changeset
650 name = getshelvename(repo, parent, opts)
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
651 activebookmark = _backupactivebookmark(repo)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
652 extra = {b'internal': b'shelve'}
27908
d73a5ab18015 shelve: permit shelves to contain unknown files
Simon Farnsworth <simonfar@fb.com>
parents: 27888
diff changeset
653 if includeunknown:
50054
e2b89b6d4cdd dirstate: use `dirstate.change_files` to scope the change in `shelve`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50053
diff changeset
654 with repo.dirstate.changing_files(repo):
e2b89b6d4cdd dirstate: use `dirstate.change_files` to scope the change in `shelve`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50053
diff changeset
655 _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
656
28572
43c204ddf333 shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents: 28571
diff changeset
657 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
658 # 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
659 # at bundled commit
50264
921f4834b7b5 branch: pass current transaction when writing branch in shelve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50195
diff changeset
660 repo.dirstate.setbranch(
921f4834b7b5 branch: pass current transaction when writing branch in shelve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50195
diff changeset
661 repo[b'.'].branch(), repo.currenttransaction()
921f4834b7b5 branch: pass current transaction when writing branch in shelve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50195
diff changeset
662 )
28572
43c204ddf333 shelve: make non bare shelve not saving branch information in bundle
liscju <piotr.listkiewicz@gmail.com>
parents: 28571
diff changeset
663
30381
caba61934721 shelve: move commitfunc creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30380
diff changeset
664 commitfunc = getcommitfunc(extra, interactive, editor=True)
24478
95cbc77c0cad shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents: 24477
diff changeset
665 if not interactive:
95cbc77c0cad shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents: 24477
diff changeset
666 node = cmdutil.commit(ui, repo, commitfunc, pats, opts)
95cbc77c0cad shelve: add interactive mode
Laurent Charignon <lcharignon@fb.com>
parents: 24477
diff changeset
667 else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
668 node = cmdutil.dorecord(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
669 ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
670 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
671 commitfunc,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
672 None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
673 False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
674 cmdutil.recordfilter,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
675 *pats,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
676 **pycompat.strkwargs(opts)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
677 )
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
678 if not node:
30382
dedf0915ca5b shelve: move 'nothing changed' messaging to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30381
diff changeset
679 _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
680 return 1
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
681
49425
35c9f0bc2648 phase-shelve: Extract function for _optimized_match for re-use
Jason R. Coombs <jaraco@jaraco.com>
parents: 49306
diff changeset
682 match = _optimized_match(repo, node)
42012
9b78bbb76111 shelve: refactor _shelvecreatedcommit's match object into calling site
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 42011
diff changeset
683 _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
684
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
685 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
686 if opts[b'keep']:
49961
7a8bfc05b691 dirstate: rename parentchange to changing_parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49960
diff changeset
687 with repo.dirstate.changing_parents(repo):
42013
50d5e64ec561 shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 42012
diff changeset
688 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
689 else:
50d5e64ec561 shelve: do not update when keeping changes, just move the dirstate
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 42012
diff changeset
690 hg.update(repo, parent.node())
45860
073bb7563931 shelve: clear merge state after partial shelve
Martin von Zweigbergk <martinvonz@google.com>
parents: 45577
diff changeset
691 ms = mergestatemod.mergestate.read(repo)
073bb7563931 shelve: clear merge state after partial shelve
Martin von Zweigbergk <martinvonz@google.com>
parents: 45577
diff changeset
692 if not ms.unresolvedcount():
073bb7563931 shelve: clear merge state after partial shelve
Martin von Zweigbergk <martinvonz@google.com>
parents: 45577
diff changeset
693 ms.reset()
073bb7563931 shelve: clear merge state after partial shelve
Martin von Zweigbergk <martinvonz@google.com>
parents: 45577
diff changeset
694
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
695 if origbranch != repo[b'.'].branch() and not _isbareshelve(pats, opts):
50264
921f4834b7b5 branch: pass current transaction when writing branch in shelve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50195
diff changeset
696 repo.dirstate.setbranch(origbranch, repo.currenttransaction())
26523
1d23bf6cd90a shelve: restore shelved dirstate explicitly after aborting transaction
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 26522
diff changeset
697
41007
a06dc62f1c82 shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents: 40854
diff changeset
698 _finishshelve(repo, tr)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
699 finally:
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
700 _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
701 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
702
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
703
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
704 def _isbareshelve(pats, opts) -> bool:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
705 return (
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
706 not pats
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
707 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
708 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
709 and not opts.get(b'exclude', False)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
710 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
711
28571
3f0e25e89e28 shelve: preserve newly created branch on non-bare shelve in wctx (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28401
diff changeset
712
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
713 def _iswctxonnewbranch(repo) -> bool:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
714 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
715
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
716
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
717 def cleanupcmd(ui, repo) -> None:
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
718 """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
719
27835
c448d7e00bf9 with: use context manager for wlock in shelve cleanupcmd
Bryan O'Sullivan <bryano@fb.com>
parents: 27834
diff changeset
720 with repo.wlock():
46297
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
721 shelf_dir = ShelfDir(repo)
46291
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
722 backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
46297
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
723 for _mtime, name in shelf_dir.listshelves():
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
724 shelf_dir.get(name).movetobackup(backupvfs)
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
725 cleanupoldbackups(repo)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
726
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
727
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
728 def deletecmd(ui, repo, pats) -> None:
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
729 """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
730 if not pats:
46272
a68d3386138c shelve: raise more specific errors
Martin von Zweigbergk <martinvonz@google.com>
parents: 46271
diff changeset
731 raise error.InputError(_(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
732 with repo.wlock():
46291
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
733 backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
43719
cb23d9e3e21f shelve: fix a missing variable in the exception handler for delete
Matt Harbison <matt_harbison@yahoo.com>
parents: 43117
diff changeset
734 for name in pats:
46296
eec8899407f4 shelve: also create class representing whole directory of shelves
Martin von Zweigbergk <martinvonz@google.com>
parents: 46295
diff changeset
735 shelf = ShelfDir(repo).get(name)
46287
ae7a77a7ebc0 shelve: extract some repeated creation of shelf instances to variables
Martin von Zweigbergk <martinvonz@google.com>
parents: 46286
diff changeset
736 if not shelf.exists():
46272
a68d3386138c shelve: raise more specific errors
Martin von Zweigbergk <martinvonz@google.com>
parents: 46271
diff changeset
737 raise error.InputError(
a68d3386138c shelve: raise more specific errors
Martin von Zweigbergk <martinvonz@google.com>
parents: 46271
diff changeset
738 _(b"shelved change '%s' not found") % name
a68d3386138c shelve: raise more specific errors
Martin von Zweigbergk <martinvonz@google.com>
parents: 46271
diff changeset
739 )
46291
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
740 shelf.movetobackup(backupvfs)
27836
1c2408c28aff with: use context manager for wlock in shelve deletecmd
Bryan O'Sullivan <bryano@fb.com>
parents: 27835
diff changeset
741 cleanupoldbackups(repo)
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
742
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
743
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
744 def listcmd(ui, repo, pats: Iterable[bytes], opts) -> None:
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
745 """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
746 pats = set(pats)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
747 width = 80
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
748 if not ui.plain():
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
749 width = ui.termwidth()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
750 namelabel = b'shelve.newest'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
751 ui.pager(b'shelve')
46296
eec8899407f4 shelve: also create class representing whole directory of shelves
Martin von Zweigbergk <martinvonz@google.com>
parents: 46295
diff changeset
752 shelf_dir = ShelfDir(repo)
46297
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
753 for mtime, name in shelf_dir.listshelves():
46281
a34607b6d320 shelve: make listshelves() return shelf names instead of filenames
Martin von Zweigbergk <martinvonz@google.com>
parents: 46280
diff changeset
754 if pats and name not in pats:
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
755 continue
46281
a34607b6d320 shelve: make listshelves() return shelf names instead of filenames
Martin von Zweigbergk <martinvonz@google.com>
parents: 46280
diff changeset
756 ui.write(name, label=namelabel)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
757 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
758 if ui.quiet:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
759 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
760 continue
46281
a34607b6d320 shelve: make listshelves() return shelf names instead of filenames
Martin von Zweigbergk <martinvonz@google.com>
parents: 46280
diff changeset
761 ui.write(b' ' * (16 - len(name)))
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
762 used = 16
36607
c6061cadb400 util: extract all date-related utils in utils/dateutil module
Boris Feld <boris.feld@octobus.net>
parents: 36496
diff changeset
763 date = dateutil.makedate(mtime)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
764 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
765 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
766 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
767 used += 12
49426
24ffd13893cc phase-shelve: read patch details from a (possibly internal) node in the repo
Jason R. Coombs <jaraco@jaraco.com>
parents: 49425
diff changeset
768 with shelf_dir.get(name).load_patch(repo) as fp:
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
769 while True:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
770 line = fp.readline()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
771 if not line:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
772 break
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
773 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
774 desc = line.rstrip()
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
775 if ui.formatted():
37084
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 36781
diff changeset
776 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
777 ui.write(desc)
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
778 break
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
779 ui.write(b'\n')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
780 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
781 continue
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
782 difflines = fp.readlines()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
783 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
784 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
785 ui.write(chunk, label=label)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
786 if opts[b'stat']:
30407
e1677cc29da6 patch: remove unused git parameter from patch.diffstat()
Henning Schild <henning@hennsch.de>
parents: 30385
diff changeset
787 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
788 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
789
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
790
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
791 def patchcmds(ui, repo, pats: Sequence[bytes], opts) -> None:
30823
806a830e6612 shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30671
diff changeset
792 """subcommand that displays shelves"""
46297
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
793 shelf_dir = ShelfDir(repo)
30823
806a830e6612 shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30671
diff changeset
794 if len(pats) == 0:
46297
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
795 shelves = shelf_dir.listshelves()
38715
905b66681004 shelve: pick the most recent shelve if none specified for --patch/--stat
Danny Hooper <hooper@google.com>
parents: 38714
diff changeset
796 if not shelves:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
797 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
798 mtime, name = shelves[0]
46281
a34607b6d320 shelve: make listshelves() return shelf names instead of filenames
Martin von Zweigbergk <martinvonz@google.com>
parents: 46280
diff changeset
799 pats = [name]
25104
d6453f6fbdba shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents: 25103
diff changeset
800
30823
806a830e6612 shelve: allow multiple shelves with --patch and --stat
Pulkit Goyal <7895pulkit@gmail.com>
parents: 30671
diff changeset
801 for shelfname in pats:
46296
eec8899407f4 shelve: also create class representing whole directory of shelves
Martin von Zweigbergk <martinvonz@google.com>
parents: 46295
diff changeset
802 if not shelf_dir.get(shelfname).exists():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
803 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
804
d6453f6fbdba shelve: allow --patch and --stat without --list for a single shelf
Tony Tung <tonytung@fb.com>
parents: 25103
diff changeset
805 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
806
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
807
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
808 def checkparents(repo, state: shelvedstate) -> None:
19909
df54786a3203 shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19908
diff changeset
809 """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
810 if state.parents != repo.dirstate.parents():
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
811 raise error.Abort(
43117
8ff1ecfadcd1 cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents: 43085
diff changeset
812 _(b'working directory parents do not match unshelve state')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
813 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
814
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
815
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
816 def _loadshelvedstate(ui, repo, opts) -> shelvedstate:
42599
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
817 try:
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
818 state = shelvedstate.load(repo)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
819 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
820 opts[b'keep'] = state.keep
51813
54b1a3738530 shelve: raise an error when loading a corrupt state file in an impossible case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51100
diff changeset
821 return state
49306
2e726c934fcd py3: catch FileNotFoundError instead of checking errno == ENOENT
Manuel Jacob <me@manueljacob.de>
parents: 49284
diff changeset
822 except FileNotFoundError:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
823 cmdutil.wrongtooltocontinue(repo, _(b'unshelve'))
42599
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
824 except error.CorruptedState as err:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
825 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
826 if opts.get(b'continue'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
827 msg = _(b'corrupted shelved state file')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
828 hint = _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
829 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
830 b'operation'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
831 )
42599
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
832 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
833 elif opts.get(b'abort'):
42599
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
834 shelvedstate.clear(repo)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
835 raise error.Abort(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
836 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
837 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
838 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
839 b'please update to some commit\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
840 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
841 )
51813
54b1a3738530 shelve: raise an error when loading a corrupt state file in an impossible case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51100
diff changeset
842 else:
54b1a3738530 shelve: raise an error when loading a corrupt state file in an impossible case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51100
diff changeset
843 raise error.ProgrammingError(
54b1a3738530 shelve: raise an error when loading a corrupt state file in an impossible case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51100
diff changeset
844 "a corrupted shelvedstate exists without --abort or --continue"
54b1a3738530 shelve: raise an error when loading a corrupt state file in an impossible case
Matt Harbison <matt_harbison@yahoo.com>
parents: 51100
diff changeset
845 )
42599
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
846
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
847
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
848 def unshelveabort(ui, repo, state: shelvedstate) -> None:
19909
df54786a3203 shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19908
diff changeset
849 """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
850 with repo.lock():
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
851 try:
27841
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
852 checkparents(repo, state)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
853
44270
f546d2170b0f merge: introduce a clean_update() for that use-case
Martin von Zweigbergk <martinvonz@google.com>
parents: 44212
diff changeset
854 merge.clean_update(state.pendingctx)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
855 if state.activebookmark and state.activebookmark in repo._bookmarks:
38462
61e4cf1be5b2 shelve: directly handle the abort process
Boris Feld <boris.feld@octobus.net>
parents: 37967
diff changeset
856 bookmarks.activate(repo, state.activebookmark)
27841
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
857 mergefiles(ui, repo, state.wctx, state.pendingctx)
49430
2064bbf7a1d5 phase-shelve: Implement a 'shelve.store' experimental config
Jason R. Coombs <jaraco@jaraco.com>
parents: 49429
diff changeset
858 if not _use_internal_phase(repo):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
859 repair.strip(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
860 ui, repo, state.nodestoremove, backup=False, topic=b'shelve'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
861 )
27841
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
862 finally:
83995fdde225 with: use context manager in unshelveabort
Bryan O'Sullivan <bryano@fb.com>
parents: 27838
diff changeset
863 shelvedstate.clear(repo)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
864 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
865
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
866
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
867 def hgabortunshelve(ui, repo) -> None:
42599
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
868 """logic to abort unshelve using 'hg abort"""
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
869 with repo.wlock():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
870 state = _loadshelvedstate(ui, repo, {b'abort': True})
42599
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
871 return unshelveabort(ui, repo, state)
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
872
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
873
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
874 def mergefiles(ui, repo, wctx, shelvectx) -> None:
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
875 """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
876 dirstate."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
877 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
878 hg.update(repo, wctx.node())
45375
8c466bcb0879 revert: remove dangerous `parents` argument from `cmdutil.revert()`
Martin von Zweigbergk <martinvonz@google.com>
parents: 45151
diff changeset
879 cmdutil.revert(ui, repo, shelvectx)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
880
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
881
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
882 def restorebranch(ui, repo, branchtorestore: bytes) -> None:
28573
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
883 if branchtorestore and branchtorestore != repo.dirstate.branch():
50264
921f4834b7b5 branch: pass current transaction when writing branch in shelve
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50195
diff changeset
884 repo.dirstate.setbranch(branchtorestore, repo.currenttransaction())
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
885 ui.status(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
886 _(b'marked working directory as branch %s\n') % branchtorestore
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
887 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
888
28573
6a42564081cb shelve: adds restoring newly created branch (issue5048) (BC)
liscju <piotr.listkiewicz@gmail.com>
parents: 28572
diff changeset
889
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
890 def unshelvecleanup(ui, repo, name: bytes, opts) -> None:
19911
1c58e368fbfd shelve: some docstring cleanups
Augie Fackler <raf@durin42.com>
parents: 19909
diff changeset
891 """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
892 if not opts.get(b'keep'):
46291
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
893 backupvfs = vfsmod.vfs(repo.vfs.join(backupdir))
46296
eec8899407f4 shelve: also create class representing whole directory of shelves
Martin von Zweigbergk <martinvonz@google.com>
parents: 46295
diff changeset
894 ShelfDir(repo).get(name).movetobackup(backupvfs)
25713
2ca116614cfc shelve: only keep the latest N shelve backups
Colin Chan <colinchan@fb.com>
parents: 25712
diff changeset
895 cleanupoldbackups(repo)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
896
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
897
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
898 def unshelvecontinue(ui, repo, state: shelvedstate, opts) -> None:
19909
df54786a3203 shelve: add minimal documentation to all functions
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 19908
diff changeset
899 """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
900 # 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
901 # parent, second is the temporary "fake" commit we're unshelving.
42662
ee86ad6f50fe unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42658
diff changeset
902 interactive = state.interactive
ee86ad6f50fe unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42658
diff changeset
903 basename = state.name
27838
60b850b7e4ef with: use context manager for lock in continue
Bryan O'Sullivan <bryano@fb.com>
parents: 27837
diff changeset
904 with repo.lock():
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
905 checkparents(repo, state)
44856
b7808443ed6a mergestate: split out merge state handling code from main merge module
Augie Fackler <augie@google.com>
parents: 44595
diff changeset
906 ms = mergestatemod.mergestate.read(repo)
46361
dfca84970da8 cleanup: use mergestate.unresolvedcount() instead of bool(list(unresolved()))
Augie Fackler <augie@google.com>
parents: 46297
diff changeset
907 if ms.unresolvedcount():
26587
56b2bcea2529 error: get Abort from 'error' instead of 'util'
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 26577
diff changeset
908 raise error.Abort(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
909 _(b"unresolved conflicts, can't continue"),
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
910 hint=_(b"see 'hg resolve', then 'hg unshelve --continue'"),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
911 )
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
912
38463
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
913 shelvectx = repo[state.parents[1]]
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
914 pendingctx = state.pendingctx
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
915
49961
7a8bfc05b691 dirstate: rename parentchange to changing_parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49960
diff changeset
916 with repo.dirstate.changing_parents(repo):
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46843
diff changeset
917 repo.setparents(state.pendingctx.node(), repo.nullid)
38618
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
918 repo.dirstate.write(repo.currenttransaction())
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
919
49429
fa00c407d61c phase-shelve: Extract function for _target_phase
Jason R. Coombs <jaraco@jaraco.com>
parents: 49427
diff changeset
920 targetphase = _target_phase(repo)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
921 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
922 with repo.ui.configoverride(overrides, b'unshelve'):
49961
7a8bfc05b691 dirstate: rename parentchange to changing_parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49960
diff changeset
923 with repo.dirstate.changing_parents(repo):
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46843
diff changeset
924 repo.setparents(state.parents[0], repo.nullid)
50052
1b044a63a98a shelve: adjust what happens in some `changing_parents` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49961
diff changeset
925 newnode, ispartialunshelve = _createunshelvectx(
1b044a63a98a shelve: adjust what happens in some `changing_parents` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49961
diff changeset
926 ui, repo, shelvectx, basename, interactive, opts
1b044a63a98a shelve: adjust what happens in some `changing_parents` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49961
diff changeset
927 )
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
928
38463
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
929 if newnode is None:
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
930 shelvectx = state.pendingctx
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
931 msg = _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
932 b'note: unshelved changes already existed '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
933 b'in the working copy\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
934 )
38463
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
935 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
936 else:
38463
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
937 # only strip the shelvectx if we produced one
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
938 state.nodestoremove.append(newnode)
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
939 shelvectx = repo[newnode]
f4776f8b98e0 shelve: directly handle `--continue`
Boris Feld <boris.feld@octobus.net>
parents: 38462
diff changeset
940
45577
5c8230ca37f2 merge: replace calls to hg.updaterepo() by merge.update()
Martin von Zweigbergk <martinvonz@google.com>
parents: 45375
diff changeset
941 merge.update(pendingctx)
20149
578b888c820e unshelve: don't commit unknown files during unshelve (issue4113)
Durham Goode <durham@fb.com>
parents: 20103
diff changeset
942 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
943 restorebranch(ui, repo, state.branchtorestore)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
944
49430
2064bbf7a1d5 phase-shelve: Implement a 'shelve.store' experimental config
Jason R. Coombs <jaraco@jaraco.com>
parents: 49429
diff changeset
945 if not _use_internal_phase(repo):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
946 repair.strip(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
947 ui, repo, state.nodestoremove, backup=False, topic=b'shelve'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
948 )
42703
073cfff9aaef unshelve: delete shelvedstate after a successful unshelve --continue
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42702
diff changeset
949 shelvedstate.clear(repo)
42616
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
950 if not ispartialunshelve:
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
951 unshelvecleanup(ui, repo, state.name, opts)
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
952 _restoreactivebookmark(repo, state.activebookmark)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
953 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
954
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
955
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
956 def hgcontinueunshelve(ui, repo) -> None:
42614
117437f3f541 continue: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42599
diff changeset
957 """logic to resume unshelve using 'hg continue'"""
117437f3f541 continue: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42599
diff changeset
958 with repo.wlock():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
959 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
960 return unshelvecontinue(ui, repo, state, {b'keep': state.keep})
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
961
42614
117437f3f541 continue: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42599
diff changeset
962
30453
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
963 def _commitworkingcopychanges(ui, repo, opts, tmpwctx):
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
964 """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: 30407
diff changeset
965 # 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: 30407
diff changeset
966 # 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: 30407
diff changeset
967 s = repo.status()
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
968 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
969 if not (s.modified or s.added or s.removed):
30453
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
970 return tmpwctx, addedbefore
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
971 ui.status(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
972 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
973 b"temporarily committing pending changes "
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
974 b"(restore with 'hg unshelve --abort')\n"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
975 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
976 )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
977 extra = {b'internal': b'shelve'}
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
978 commitfunc = getcommitfunc(extra=extra, interactive=False, editor=False)
30453
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
979 tempopts = {}
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
980 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
981 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
982 with ui.configoverride({(b'ui', b'quiet'): True}):
31757
473f2fcc7629 shelve: move ui.quiet manipulations to configoverride
Kostia Balytskyi <ikostia@fb.com>
parents: 31664
diff changeset
983 node = cmdutil.commit(ui, repo, commitfunc, [], tempopts)
30453
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
984 tmpwctx = repo[node]
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
985 return tmpwctx, addedbefore
2e736f01a710 shelve: move temporary commit creation to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30407
diff changeset
986
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
987
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
988 def _unshelverestorecommit(ui, repo, tr, basename: bytes):
30454
672026aece64 shelve: move commit restoration logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30453
diff changeset
989 """Recreate commit in the repository during the unshelve"""
39373
6a71324cb68b shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents: 39372
diff changeset
990 repo = repo.unfiltered()
39387
da84cca65036 shelve: fix crash on unshelve without .shelve metadata file
Yuya Nishihara <yuya@tcha.org>
parents: 39376
diff changeset
991 node = None
46296
eec8899407f4 shelve: also create class representing whole directory of shelves
Martin von Zweigbergk <martinvonz@google.com>
parents: 46295
diff changeset
992 shelf = ShelfDir(repo).get(basename)
46287
ae7a77a7ebc0 shelve: extract some repeated creation of shelf instances to variables
Martin von Zweigbergk <martinvonz@google.com>
parents: 46286
diff changeset
993 if shelf.hasinfo():
ae7a77a7ebc0 shelve: extract some repeated creation of shelf instances to variables
Martin von Zweigbergk <martinvonz@google.com>
parents: 46286
diff changeset
994 node = shelf.readinfo()[b'node']
39374
c67c94c0e7ae shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents: 39373
diff changeset
995 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
996 with ui.configoverride({(b'ui', b'quiet'): True}):
46291
e2713c68b477 shelve: replace repo instance in Shelf class by vfs instance
Martin von Zweigbergk <martinvonz@google.com>
parents: 46290
diff changeset
997 shelvectx = shelf.applybundle(repo, tr)
39375
38373da1af02 shelve: write metadata file on the fly if they are missing
Boris Feld <boris.feld@octobus.net>
parents: 39374
diff changeset
998 # 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: 39374
diff changeset
999 # 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: 39374
diff changeset
1000 if node is None:
46113
59fa3890d40a node: import symbols explicitly
Joerg Sonnenberger <joerg@bec.de>
parents: 45942
diff changeset
1001 info = {b'node': hex(shelvectx.node())}
46287
ae7a77a7ebc0 shelve: extract some repeated creation of shelf instances to variables
Martin von Zweigbergk <martinvonz@google.com>
parents: 46286
diff changeset
1002 shelf.writeinfo(info)
39374
c67c94c0e7ae shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents: 39373
diff changeset
1003 else:
c67c94c0e7ae shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents: 39373
diff changeset
1004 shelvectx = repo[node]
c67c94c0e7ae shelve: look for shelved node in the repository before unbundling
Boris Feld <boris.feld@octobus.net>
parents: 39373
diff changeset
1005
30454
672026aece64 shelve: move commit restoration logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30453
diff changeset
1006 return repo, shelvectx
672026aece64 shelve: move commit restoration logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30453
diff changeset
1007
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1008
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
1009 def _createunshelvectx(
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
1010 ui, repo, shelvectx, basename: bytes, interactive: bool, opts
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
1011 ) -> Tuple[bytes, bool]:
42656
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
1012 """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
1013 was partially unshelved.
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
1014
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
1015 If interactive is:
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
1016
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
1017 * 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
1018 * 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
1019 Update the shelve with remaining changes.
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
1020
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
1021 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
1022 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
1023 interactively or non-interactively.
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
1024
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
1025 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
1026 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
1027 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
1028
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
1029 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
1030 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
1031 """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1032 opts[b'message'] = shelvectx.description()
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1033 opts[b'interactive-unshelve'] = True
42616
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
1034 pats = []
42656
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
1035 if not interactive:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1036 newnode = repo.commit(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1037 text=shelvectx.description(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1038 extra=shelvectx.extra(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1039 user=shelvectx.user(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1040 date=shelvectx.date(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1041 )
42656
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
1042 return newnode, False
c9114885c14b unshelve: unify logic around creating an unshelve changeset
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42616
diff changeset
1043
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1044 commitfunc = getcommitfunc(shelvectx.extra(), interactive=True, editor=True)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1045 newnode = cmdutil.dorecord(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1046 ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1047 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1048 commitfunc,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1049 None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1050 False,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1051 cmdutil.recordfilter,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1052 *pats,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1053 **pycompat.strkwargs(opts)
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1054 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1055 snode = repo.commit(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1056 text=shelvectx.description(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1057 extra=shelvectx.extra(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1058 user=shelvectx.user(),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1059 )
42616
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
1060 if snode:
49425
35c9f0bc2648 phase-shelve: Extract function for _optimized_match for re-use
Jason R. Coombs <jaraco@jaraco.com>
parents: 49306
diff changeset
1061 m = _optimized_match(repo, snode)
42616
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
1062 _shelvecreatedcommit(repo, snode, basename, m)
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
1063
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
1064 return newnode, bool(snode)
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
1065
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1066
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1067 def _rebaserestoredcommit(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1068 ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1069 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1070 opts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1071 tr,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1072 oldtiprev,
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
1073 basename: bytes,
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1074 pctx,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1075 tmpwctx,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1076 shelvectx,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1077 branchtorestore,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1078 activebookmark,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1079 ):
30455
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
1080 """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: 30454
diff changeset
1081 # 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: 30454
diff changeset
1082 # 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
1083 interactive = opts.get(b'interactive')
42616
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
1084 if tmpwctx.node() == shelvectx.p1().node() and not interactive:
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
1085 # 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
1086 # unshelve certain changes only.
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
1087 return shelvectx, False
30455
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
1088
38618
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
1089 overrides = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1090 (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
1091 (b'phases', b'new-commit'): phases.secret,
38618
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
1092 }
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1093 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
1094 ui.status(_(b'rebasing shelved changes\n'))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1095 stats = merge.graft(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1096 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1097 shelvectx,
48592
bcc4820242cf shelve: attempt to make merge labels more helpful
Martin von Zweigbergk <martinvonz@google.com>
parents: 47436
diff changeset
1098 labels=[
bcc4820242cf shelve: attempt to make merge labels more helpful
Martin von Zweigbergk <martinvonz@google.com>
parents: 47436
diff changeset
1099 b'working-copy',
bcc4820242cf shelve: attempt to make merge labels more helpful
Martin von Zweigbergk <martinvonz@google.com>
parents: 47436
diff changeset
1100 b'shelved change',
bcc4820242cf shelve: attempt to make merge labels more helpful
Martin von Zweigbergk <martinvonz@google.com>
parents: 47436
diff changeset
1101 b'parent of shelved change',
bcc4820242cf shelve: attempt to make merge labels more helpful
Martin von Zweigbergk <martinvonz@google.com>
parents: 47436
diff changeset
1102 ],
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1103 keepconflictparent=True,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1104 )
38618
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
1105 if stats.unresolvedcount:
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
1106 tr.close()
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
1107
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1108 nodestoremove = [
49284
d44e3c45f0e4 py3: replace `pycompat.xrange` by `range`
Manuel Jacob <me@manueljacob.de>
parents: 49248
diff changeset
1109 repo.changelog.node(rev) for rev in range(oldtiprev, len(repo))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1110 ]
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1111 shelvedstate.save(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1112 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1113 basename,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1114 pctx,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1115 tmpwctx,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1116 nodestoremove,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1117 branchtorestore,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1118 opts.get(b'keep'),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1119 activebookmark,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1120 interactive,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1121 )
45151
e429e7c801b2 error: normalize "unresolved conflicts" error messages with a custom class
Daniel Ploch <dploch@google.com>
parents: 45144
diff changeset
1122 raise error.ConflictResolutionRequired(b'unshelve')
30455
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
1123
49961
7a8bfc05b691 dirstate: rename parentchange to changing_parents
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49960
diff changeset
1124 with repo.dirstate.changing_parents(repo):
47012
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46843
diff changeset
1125 repo.setparents(tmpwctx.node(), repo.nullid)
50052
1b044a63a98a shelve: adjust what happens in some `changing_parents` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49961
diff changeset
1126 newnode, ispartialunshelve = _createunshelvectx(
1b044a63a98a shelve: adjust what happens in some `changing_parents` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49961
diff changeset
1127 ui, repo, shelvectx, basename, interactive, opts
1b044a63a98a shelve: adjust what happens in some `changing_parents` context
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 49961
diff changeset
1128 )
30455
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
1129
38618
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
1130 if newnode is None:
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
1131 shelvectx = tmpwctx
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1132 msg = _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1133 b'note: unshelved changes already existed '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1134 b'in the working copy\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1135 )
38618
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
1136 ui.status(msg)
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
1137 else:
c829749e7639 shelve: directly handle the initial parent alignment
Boris Feld <boris.feld@octobus.net>
parents: 38508
diff changeset
1138 shelvectx = repo[newnode]
45577
5c8230ca37f2 merge: replace calls to hg.updaterepo() by merge.update()
Martin von Zweigbergk <martinvonz@google.com>
parents: 45375
diff changeset
1139 merge.update(tmpwctx)
30455
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
1140
42616
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
1141 return shelvectx, ispartialunshelve
30455
10684a298973 shelve: move rebasing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30454
diff changeset
1142
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1143
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
1144 def _forgetunknownfiles(repo, shelvectx, addedbefore) -> None:
30456
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
1145 # 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: 30455
diff changeset
1146 # 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
1147 shelveunknown = shelvectx.extra().get(b'shelve_unknown')
30456
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
1148 if not shelveunknown:
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
1149 return
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1150 shelveunknown = frozenset(shelveunknown.split(b'\0'))
30456
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
1151 addedafter = frozenset(repo.status().added)
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
1152 toforget = (addedafter & shelveunknown) - addedbefore
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
1153 repo[None].forget(toforget)
b924375cce3a shelve: move file-forgetting logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30455
diff changeset
1154
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1155
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
1156 def _finishunshelve(repo, oldtiprev, tr, activebookmark) -> None:
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
1157 _restoreactivebookmark(repo, activebookmark)
51100
ae6722dbb575 shelve: drop some weird manually stripping before transaction abort
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
1158 # We used to manually strip the commit to update inmemory structure and
ae6722dbb575 shelve: drop some weird manually stripping before transaction abort
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
1159 # prevent some issue around hooks. This no longer seems to be the case, so
ae6722dbb575 shelve: drop some weird manually stripping before transaction abort
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50928
diff changeset
1160 # we simply abort the transaction.
41007
a06dc62f1c82 shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents: 40854
diff changeset
1161 _aborttransaction(repo, tr)
30457
893be22cdb38 shelve: move unshelve-finishing logic to a separate function
Kostia Balytskyi <ikostia@fb.com>
parents: 30456
diff changeset
1162
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1163
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
1164 def _checkunshelveuntrackedproblems(ui, repo, shelvectx) -> None:
30846
dfc6663f97ca shelve: make unshelve not crash when there are missing files (issue4176)
Kostia Balytskyi <ikostia@fb.com>
parents: 30823
diff changeset
1165 """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
1166 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
1167 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
1168 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
1169 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
1170 if intersection:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1171 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
1172 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
1173 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
1174
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1175
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
1176 def unshelvecmd(ui, repo, *shelved, **opts) -> None:
35005
aad6b9fdfc75 py3: handle keyword arguments in hgext/shelve.py
Pulkit Goyal <7895pulkit@gmail.com>
parents: 34496
diff changeset
1177 opts = pycompat.byteskwargs(opts)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1178 abortf = opts.get(b'abort')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1179 continuef = opts.get(b'continue')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1180 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
1181 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
1182 cmdutil.checkunfinished(repo)
31021
4189d790e8a4 shelve: add -n/--name option to unshelve (issue5475)
liscju <piotr.listkiewicz@gmail.com>
parents: 30846
diff changeset
1183 shelved = list(shelved)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1184 if opts.get(b"name"):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1185 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
1186
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1187 if interactive and opts.get(b'keep'):
46272
a68d3386138c shelve: raise more specific errors
Martin von Zweigbergk <martinvonz@google.com>
parents: 46271
diff changeset
1188 raise error.InputError(
a68d3386138c shelve: raise more specific errors
Martin von Zweigbergk <martinvonz@google.com>
parents: 46271
diff changeset
1189 _(b'--keep on --interactive is not yet supported')
a68d3386138c shelve: raise more specific errors
Martin von Zweigbergk <martinvonz@google.com>
parents: 46271
diff changeset
1190 )
42662
ee86ad6f50fe unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42658
diff changeset
1191 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
1192 if abortf and continuef:
46272
a68d3386138c shelve: raise more specific errors
Martin von Zweigbergk <martinvonz@google.com>
parents: 46271
diff changeset
1193 raise error.InputError(_(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
1194 if shelved:
46272
a68d3386138c shelve: raise more specific errors
Martin von Zweigbergk <martinvonz@google.com>
parents: 46271
diff changeset
1195 raise error.InputError(
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1196 _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1197 b'cannot combine abort/continue with '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1198 b'naming a shelved change'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1199 )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1200 )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1201 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
1202 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
1203
42599
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
1204 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
1205 if abortf:
42599
3fb0493812c0 abort: added support for unshelve
Taapas Agrawal <taapas2897@gmail.com>
parents: 42598
diff changeset
1206 return unshelveabort(ui, repo, state)
42668
52a383451739 unshelve: add abort on using continue and interactive together
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42662
diff changeset
1207 elif continuef and interactive:
46272
a68d3386138c shelve: raise more specific errors
Martin von Zweigbergk <martinvonz@google.com>
parents: 46271
diff changeset
1208 raise error.InputError(
a68d3386138c shelve: raise more specific errors
Martin von Zweigbergk <martinvonz@google.com>
parents: 46271
diff changeset
1209 _(b'cannot use both continue and interactive')
a68d3386138c shelve: raise more specific errors
Martin von Zweigbergk <martinvonz@google.com>
parents: 46271
diff changeset
1210 )
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
1211 elif continuef:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
1212 return unshelvecontinue(ui, repo, state, opts)
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
1213 else:
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
1214 # Unreachable code, but help type checkers not think that
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
1215 # 'basename' may be used before initialization when checking
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
1216 # ShelfDir below.
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
1217 raise error.ProgrammingError("neither abort nor continue specified")
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
1218 elif len(shelved) > 1:
46272
a68d3386138c shelve: raise more specific errors
Martin von Zweigbergk <martinvonz@google.com>
parents: 46271
diff changeset
1219 raise error.InputError(_(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
1220 elif not shelved:
46297
82edad33fd81 shelve: move listshelves() to new ShelfDir class, so caller need not pass vfs
Martin von Zweigbergk <martinvonz@google.com>
parents: 46296
diff changeset
1221 shelved = ShelfDir(repo).listshelves()
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
1222 if not shelved:
46272
a68d3386138c shelve: raise more specific errors
Martin von Zweigbergk <martinvonz@google.com>
parents: 46271
diff changeset
1223 raise error.StateError(_(b'no shelved changes to apply!'))
46281
a34607b6d320 shelve: make listshelves() return shelf names instead of filenames
Martin von Zweigbergk <martinvonz@google.com>
parents: 46280
diff changeset
1224 basename = shelved[0][1]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1225 ui.status(_(b"unshelving change '%s'\n") % basename)
42662
ee86ad6f50fe unshelve: store information about interactive mode in shelvedstate
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42658
diff changeset
1226 else:
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
1227 basename = shelved[0]
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
1228
46296
eec8899407f4 shelve: also create class representing whole directory of shelves
Martin von Zweigbergk <martinvonz@google.com>
parents: 46295
diff changeset
1229 if not ShelfDir(repo).get(basename).exists():
46272
a68d3386138c shelve: raise more specific errors
Martin von Zweigbergk <martinvonz@google.com>
parents: 46271
diff changeset
1230 raise error.InputError(_(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
1231
44595
47c1226463a1 shelve: split up dounshelve() in unshelvecmd() and _dounshelve()
Martin von Zweigbergk <martinvonz@google.com>
parents: 44438
diff changeset
1232 return _dounshelve(ui, repo, basename, opts)
47c1226463a1 shelve: split up dounshelve() in unshelvecmd() and _dounshelve()
Martin von Zweigbergk <martinvonz@google.com>
parents: 44438
diff changeset
1233
47c1226463a1 shelve: split up dounshelve() in unshelvecmd() and _dounshelve()
Martin von Zweigbergk <martinvonz@google.com>
parents: 44438
diff changeset
1234
51816
a1a94d488e14 typing: add type hints to `mercurial.shelve`
Matt Harbison <matt_harbison@yahoo.com>
parents: 51813
diff changeset
1235 def _dounshelve(ui, repo, basename: bytes, opts) -> None:
39373
6a71324cb68b shelve: handle shelved node on unfiltered repository
Boris Feld <boris.feld@octobus.net>
parents: 39372
diff changeset
1236 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
1237 lock = tr = None
19854
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
1238 try:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
1239 lock = repo.lock()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1240 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
1241 oldtiprev = len(repo)
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
1242
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1243 pctx = repo[b'.']
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
1244 # 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
1245 # ...-> pctx -> tmpwctx -> shelvectx
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
1246 # 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
1247 # 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
1248 # to the original pctx.
19961
1d7a36ff2615 shelve: use rebase instead of merge (issue4068)
Durham Goode <durham@fb.com>
parents: 19951
diff changeset
1249
31664
1cbeefa59343 shelve: add logic to preserve active bookmarks
Kostia Balytskyi <ikostia@fb.com>
parents: 31555
diff changeset
1250 activebookmark = _backupactivebookmark(repo)
49523
52dd7a43ad5c shelve: re-wrap now that the line fits
Jason R. Coombs <jaraco@jaraco.com>
parents: 49522
diff changeset
1251 tmpwctx, addedbefore = _commitworkingcopychanges(ui, repo, opts, pctx)
41007
a06dc62f1c82 shelve: pass transaction around to clarify where it's used
Martin von Zweigbergk <martinvonz@google.com>
parents: 40854
diff changeset
1252 repo, shelvectx = _unshelverestorecommit(ui, repo, tr, basename)
37967
7932be8b0559 shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents: 37603
diff changeset
1253 _checkunshelveuntrackedproblems(ui, repo, shelvectx)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1254 branchtorestore = b''
37967
7932be8b0559 shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents: 37603
diff changeset
1255 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
1256 branchtorestore = shelvectx.branch()
7932be8b0559 shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents: 37603
diff changeset
1257
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1258 shelvectx, ispartialunshelve = _rebaserestoredcommit(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1259 ui,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1260 repo,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1261 opts,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1262 tr,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1263 oldtiprev,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1264 basename,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1265 pctx,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1266 tmpwctx,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1267 shelvectx,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1268 branchtorestore,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1269 activebookmark,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42761
diff changeset
1270 )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
1271 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
1272 with ui.configoverride(overrides, b'unshelve'):
37967
7932be8b0559 shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents: 37603
diff changeset
1273 mergefiles(ui, repo, pctx, shelvectx)
7932be8b0559 shelve: reduce scope of merge tool config override
Martin von Zweigbergk <martinvonz@google.com>
parents: 37603
diff changeset
1274 restorebranch(ui, repo, branchtorestore)
42704
6957f7b93e03 unshelve: clear shelvedstate and _finishunshelve() on partial unshelve
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42703
diff changeset
1275 shelvedstate.clear(repo)
6957f7b93e03 unshelve: clear shelvedstate and _finishunshelve() on partial unshelve
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42703
diff changeset
1276 _finishunshelve(repo, oldtiprev, tr, activebookmark)
50053
5327ae76b740 dirstate: use `dirstate.change_files` to scope the change in `unshelve`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50052
diff changeset
1277 with repo.dirstate.changing_files(repo):
5327ae76b740 dirstate: use `dirstate.change_files` to scope the change in `unshelve`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 50052
diff changeset
1278 _forgetunknownfiles(repo, shelvectx, addedbefore)
42616
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
1279 if not ispartialunshelve:
5162753c4c14 unshelve: add interactive mode
Navaneeth Suresh <navaneeths1998@gmail.com>
parents: 42614
diff changeset
1280 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
1281 finally:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
1282 if tr:
49d4919d21c2 shelve: add a shelve extension to save/restore working changes
David Soria Parra <dsp@experimentalworks.net>
parents:
diff changeset
1283 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
1284 lockmod.release(lock)