Mercurial > hg
annotate mercurial/state.py @ 50424:ed052780ad5e
peer: rename makepeer() → _make_peer()
In httppeer and sshpeer, there previously were makepeer() and make_peer(),
which was confusing. Therefore, this changeset renames one of the functions.
makepeer() was the internal function called by make_peer() and some debug
command. This function is renamed to _make_peer().
author | Manuel Jacob <me@manueljacob.de> |
---|---|
date | Fri, 07 Apr 2023 15:42:49 +0200 |
parents | 8ced4ca30ea1 |
children | 9d3721552b6c |
rev | line source |
---|---|
38103
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
1 # state.py - writing and reading state files in Mercurial |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
2 # |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
3 # Copyright 2018 Pulkit Goyal <pulkitmgoyal@gmail.com> |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
4 # |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
7 |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
8 """ |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
9 This file contains class to wrap the state for commands and other |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
10 related logic. |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
11 |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
12 All the data related to the command state is stored as dictionary in the object. |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
13 The class has methods using which the data can be stored to disk in a file under |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
14 .hg/ directory. |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
15 |
41135
050ea8eb42a5
state: update comment about use of CBOR
Augie Fackler <augie@google.com>
parents:
39451
diff
changeset
|
16 We store the data on disk in cbor, for which we use the CBOR format to encode |
050ea8eb42a5
state: update comment about use of CBOR
Augie Fackler <augie@google.com>
parents:
39451
diff
changeset
|
17 the data. |
38103
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
18 """ |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
19 |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
20 |
45171
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
21 import contextlib |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
22 |
42529
5f2f6912c9e6
states: moved cmdutil.unfinishedstates to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents:
41135
diff
changeset
|
23 from .i18n import _ |
5f2f6912c9e6
states: moved cmdutil.unfinishedstates to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents:
41135
diff
changeset
|
24 |
38103
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
25 from . import ( |
38106
a0e4d654bceb
state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38105
diff
changeset
|
26 error, |
43773
7b14d649af1b
typing: consolidate "if not globals():" trick
Yuya Nishihara <yuya@tcha.org>
parents:
43702
diff
changeset
|
27 pycompat, |
38103
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
28 util, |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
29 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
30 from .utils import cborutil |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
31 |
43773
7b14d649af1b
typing: consolidate "if not globals():" trick
Yuya Nishihara <yuya@tcha.org>
parents:
43702
diff
changeset
|
32 if pycompat.TYPE_CHECKING: |
43702
127d46468a45
state: add a pytype annotation
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
33 from typing import ( |
127d46468a45
state: add a pytype annotation
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
34 Any, |
127d46468a45
state: add a pytype annotation
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
35 Dict, |
127d46468a45
state: add a pytype annotation
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
36 ) |
127d46468a45
state: add a pytype annotation
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
37 |
127d46468a45
state: add a pytype annotation
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
38 for t in (Any, Dict): |
127d46468a45
state: add a pytype annotation
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
39 assert t |
127d46468a45
state: add a pytype annotation
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
40 |
38103
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
41 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
42 class cmdstate: |
38103
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
43 """a wrapper class to store the state of commands like `rebase`, `graft`, |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
44 `histedit`, `shelve` etc. Extensions can also use this to write state files. |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
45 |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
46 All the data for the state is stored in the form of key-value pairs in a |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
47 dictionary. |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
48 |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
49 The class object can write all the data to a file in .hg/ directory and |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
50 can populate the object data reading that file. |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
51 |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
52 Uses cbor to serialize and deserialize data while writing and reading from |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
53 disk. |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
54 """ |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
55 |
38145
6f67bfe4b82f
state: removing remaining instances of opts class variable
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38133
diff
changeset
|
56 def __init__(self, repo, fname): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45244
diff
changeset
|
57 """repo is the repo object |
38103
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
58 fname is the file name in which data should be stored in .hg directory |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
59 """ |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
60 self._repo = repo |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
61 self.fname = fname |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
62 |
38104
36a5a1239a15
state: don't have a dict like interface for cmdstate class
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38103
diff
changeset
|
63 def read(self): |
43702
127d46468a45
state: add a pytype annotation
Augie Fackler <augie@google.com>
parents:
43117
diff
changeset
|
64 # type: () -> Dict[bytes, Any] |
38104
36a5a1239a15
state: don't have a dict like interface for cmdstate class
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38103
diff
changeset
|
65 """read the existing state file and return a dict of data stored""" |
36a5a1239a15
state: don't have a dict like interface for cmdstate class
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38103
diff
changeset
|
66 return self._read() |
38103
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
67 |
38106
a0e4d654bceb
state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38105
diff
changeset
|
68 def save(self, version, data): |
38103
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
69 """write all the state data stored to .hg/<filename> file |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
70 |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
71 we use third-party library cbor to serialize data to write in the file. |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
72 """ |
38106
a0e4d654bceb
state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38105
diff
changeset
|
73 if not isinstance(version, int): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
74 raise error.ProgrammingError( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43077
diff
changeset
|
75 b"version of state file should be an integer" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
76 ) |
38106
a0e4d654bceb
state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38105
diff
changeset
|
77 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
78 with self._repo.vfs(self.fname, b'wb', atomictemp=True) as fp: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
79 fp.write(b'%d\n' % version) |
39451
5bfab9400daf
state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38145
diff
changeset
|
80 for chunk in cborutil.streamencode(data): |
5bfab9400daf
state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38145
diff
changeset
|
81 fp.write(chunk) |
38103
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
82 |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
83 def _read(self): |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
84 """reads the state file and returns a dictionary which contain |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
85 data in the same format as it was before storing""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
86 with self._repo.vfs(self.fname, b'rb') as fp: |
38106
a0e4d654bceb
state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38105
diff
changeset
|
87 try: |
38127
b7e5c53a779e
state: temporary silence pyflakes warning by removing variable assignment
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38126
diff
changeset
|
88 int(fp.readline()) |
38106
a0e4d654bceb
state: write the version number in plain text on top of state files
Pulkit Goyal <7895pulkit@gmail.com>
parents:
38105
diff
changeset
|
89 except ValueError: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
90 raise error.CorruptedState( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43077
diff
changeset
|
91 b"unknown version of state file found" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
92 ) |
39451
5bfab9400daf
state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38145
diff
changeset
|
93 |
5bfab9400daf
state: use our CBOR module
Gregory Szorc <gregory.szorc@gmail.com>
parents:
38145
diff
changeset
|
94 return cborutil.decodeall(fp.read())[0] |
38103
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
95 |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
96 def delete(self): |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
97 """drop the state file if exists""" |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
98 util.unlinkpath(self._repo.vfs.join(self.fname), ignoremissing=True) |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
99 |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
100 def exists(self): |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
101 """check whether the state file exists or not""" |
a2f83661f721
state: import the file to write state files from evolve extension
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
102 return self._repo.vfs.exists(self.fname) |
42529
5f2f6912c9e6
states: moved cmdutil.unfinishedstates to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents:
41135
diff
changeset
|
103 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
104 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
105 class _statecheck: |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
106 """a utility class that deals with multistep operations like graft, |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45244
diff
changeset
|
107 histedit, bisect, update etc and check whether such commands |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45244
diff
changeset
|
108 are in an unfinished conditition or not and return appropriate message |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45244
diff
changeset
|
109 and hint. |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45244
diff
changeset
|
110 It also has the ability to register and determine the states of any new |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45244
diff
changeset
|
111 multistep operation or multistep command extension. |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
112 """ |
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
113 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
114 def __init__( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
115 self, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
116 opname, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
117 fname, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
118 clearable, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
119 allowcommit, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
120 reportonly, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
121 continueflag, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
122 stopflag, |
45171
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
123 childopnames, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
124 cmdmsg, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
125 cmdhint, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
126 statushint, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
127 abortfunc, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
128 continuefunc, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
129 ): |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
130 self._opname = opname |
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
131 self._fname = fname |
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
132 self._clearable = clearable |
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
133 self._allowcommit = allowcommit |
42534
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
134 self._reportonly = reportonly |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
135 self._continueflag = continueflag |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
136 self._stopflag = stopflag |
45171
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
137 self._childopnames = childopnames |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
138 self._delegating = False |
42534
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
139 self._cmdmsg = cmdmsg |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
140 self._cmdhint = cmdhint |
42532
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
141 self._statushint = statushint |
42581
bb135a784b70
abort: added logic for of hg abort
Taapas Agrawal <taapas2897@gmail.com>
parents:
42541
diff
changeset
|
142 self.abortfunc = abortfunc |
42612
3c16b9c0b099
continue: added logic for hg continue
Taapas Agrawal <taapas2897@gmail.com>
parents:
42600
diff
changeset
|
143 self.continuefunc = continuefunc |
42532
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
144 |
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
145 def statusmsg(self): |
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
146 """returns the hint message corresponding to the command for |
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
147 hg status --verbose |
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
148 """ |
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
149 if not self._statushint: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
150 hint = _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
151 b'To continue: hg %s --continue\n' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
152 b'To abort: hg %s --abort' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
153 ) % (self._opname, self._opname) |
42532
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
154 if self._stopflag: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
155 hint = hint + ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
156 _(b'\nTo stop: hg %s --stop') % (self._opname) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
157 ) |
42532
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
158 return hint |
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
159 return self._statushint |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
160 |
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
161 def hint(self): |
42532
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
162 """returns the hint message corresponding to an interrupted |
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
163 operation |
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
164 """ |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
165 if not self._cmdhint: |
45215
a253ded5b03d
morestatus: mention --stop even if not using --verbose
Kyle Lippincott <spectral@google.com>
parents:
45171
diff
changeset
|
166 if not self._stopflag: |
a253ded5b03d
morestatus: mention --stop even if not using --verbose
Kyle Lippincott <spectral@google.com>
parents:
45171
diff
changeset
|
167 return _(b"use 'hg %s --continue' or 'hg %s --abort'") % ( |
a253ded5b03d
morestatus: mention --stop even if not using --verbose
Kyle Lippincott <spectral@google.com>
parents:
45171
diff
changeset
|
168 self._opname, |
a253ded5b03d
morestatus: mention --stop even if not using --verbose
Kyle Lippincott <spectral@google.com>
parents:
45171
diff
changeset
|
169 self._opname, |
a253ded5b03d
morestatus: mention --stop even if not using --verbose
Kyle Lippincott <spectral@google.com>
parents:
45171
diff
changeset
|
170 ) |
a253ded5b03d
morestatus: mention --stop even if not using --verbose
Kyle Lippincott <spectral@google.com>
parents:
45171
diff
changeset
|
171 else: |
45244
d4a28b76fa54
cleanup: fix bad formatting of state.py from D8811
Martin von Zweigbergk <martinvonz@google.com>
parents:
45215
diff
changeset
|
172 return _( |
d4a28b76fa54
cleanup: fix bad formatting of state.py from D8811
Martin von Zweigbergk <martinvonz@google.com>
parents:
45215
diff
changeset
|
173 b"use 'hg %s --continue', 'hg %s --abort', " |
d4a28b76fa54
cleanup: fix bad formatting of state.py from D8811
Martin von Zweigbergk <martinvonz@google.com>
parents:
45215
diff
changeset
|
174 b"or 'hg %s --stop'" |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45244
diff
changeset
|
175 ) % ( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45244
diff
changeset
|
176 self._opname, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45244
diff
changeset
|
177 self._opname, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45244
diff
changeset
|
178 self._opname, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45244
diff
changeset
|
179 ) |
45215
a253ded5b03d
morestatus: mention --stop even if not using --verbose
Kyle Lippincott <spectral@google.com>
parents:
45171
diff
changeset
|
180 |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
181 return self._cmdhint |
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
182 |
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
183 def msg(self): |
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
184 """returns the status message corresponding to the command""" |
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
185 if not self._cmdmsg: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
186 return _(b'%s in progress') % (self._opname) |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
187 return self._cmdmsg |
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
188 |
42533
0231032729c4
statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42532
diff
changeset
|
189 def continuemsg(self): |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
45942
diff
changeset
|
190 """returns appropriate continue message corresponding to command""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
191 return _(b'hg %s --continue') % (self._opname) |
42533
0231032729c4
statecheck: added support for cmdutil.afterresolvedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42532
diff
changeset
|
192 |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
193 def isunfinished(self, repo): |
42532
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
194 """determines whether a multi-step operation is in progress |
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
195 or not |
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
196 """ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
197 if self._opname == b'merge': |
42532
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
198 return len(repo[None].parents()) > 1 |
45171
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
199 elif self._delegating: |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
200 return False |
42532
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
201 else: |
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
202 return repo.vfs.exists(self._fname) |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
203 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
204 |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
205 # A list of statecheck objects for multistep operations like graft. |
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
206 _unfinishedstates = [] |
45171
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
207 _unfinishedstatesbyname = {} |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
208 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
209 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
210 def addunfinished( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
211 opname, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
212 fname, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
213 clearable=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
214 allowcommit=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
215 reportonly=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
216 continueflag=False, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
217 stopflag=False, |
45171
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
218 childopnames=None, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
219 cmdmsg=b"", |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
220 cmdhint=b"", |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
221 statushint=b"", |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
222 abortfunc=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
223 continuefunc=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
224 ): |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
225 """this registers a new command or operation to unfinishedstates |
42534
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
226 opname is the name the command or operation |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
227 fname is the file name in which data should be stored in .hg directory. |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
228 It is None for merge command. |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
229 clearable boolean determines whether or not interrupted states can be |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
230 cleared by running `hg update -C .` which in turn deletes the |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
231 state file. |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
232 allowcommit boolean decides whether commit is allowed during interrupted |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
233 state or not. |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
234 reportonly flag is used for operations like bisect where we just |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
235 need to detect the operation using 'hg status --verbose' |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
236 continueflag is a boolean determines whether or not a command supports |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
237 `--continue` option or not. |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
238 stopflag is a boolean that determines whether or not a command supports |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
239 --stop flag |
45171
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
240 childopnames is a list of other opnames this op uses as sub-steps of its |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
241 own execution. They must already be added. |
42534
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
242 cmdmsg is used to pass a different status message in case standard |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
243 message of the format "abort: cmdname in progress" is not desired. |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
244 cmdhint is used to pass a different hint message in case standard |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
245 message of the format "To continue: hg cmdname --continue |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
246 To abort: hg cmdname --abort" is not desired. |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
247 statushint is used to pass a different status message in case standard |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
248 message of the format ('To continue: hg cmdname --continue' |
faec09d89435
statecheck: shifted defaults to addunfinished()
Taapas Agrawal <taapas2897@gmail.com>
parents:
42533
diff
changeset
|
249 'To abort: hg cmdname --abort') is not desired |
42581
bb135a784b70
abort: added logic for of hg abort
Taapas Agrawal <taapas2897@gmail.com>
parents:
42541
diff
changeset
|
250 abortfunc stores the function required to abort an unfinished state. |
42612
3c16b9c0b099
continue: added logic for hg continue
Taapas Agrawal <taapas2897@gmail.com>
parents:
42600
diff
changeset
|
251 continuefunc stores the function required to finish an interrupted |
3c16b9c0b099
continue: added logic for hg continue
Taapas Agrawal <taapas2897@gmail.com>
parents:
42600
diff
changeset
|
252 operation. |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
253 """ |
45171
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
254 childopnames = childopnames or [] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
255 statecheckobj = _statecheck( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
256 opname, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
257 fname, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
258 clearable, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
259 allowcommit, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
260 reportonly, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
261 continueflag, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
262 stopflag, |
45171
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
263 childopnames, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
264 cmdmsg, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
265 cmdhint, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
266 statushint, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
267 abortfunc, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
268 continuefunc, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
269 ) |
45171
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
270 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
271 if opname == b'merge': |
42532
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
272 _unfinishedstates.append(statecheckobj) |
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
273 else: |
45171
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
274 # This check enforces that for any op 'foo' which depends on op 'bar', |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
275 # 'foo' comes before 'bar' in _unfinishedstates. This ensures that |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
276 # getrepostate() always returns the most specific applicable answer. |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
277 for childopname in childopnames: |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
278 if childopname not in _unfinishedstatesbyname: |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
279 raise error.ProgrammingError( |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
280 _(b'op %s depends on unknown op %s') % (opname, childopname) |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
281 ) |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
282 |
42532
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
283 _unfinishedstates.insert(0, statecheckobj) |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
284 |
45171
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
285 if opname in _unfinishedstatesbyname: |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
286 raise error.ProgrammingError(_(b'op %s registered twice') % opname) |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
287 _unfinishedstatesbyname[opname] = statecheckobj |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
288 |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
289 |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
290 def _getparentandchild(opname, childopname): |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
291 p = _unfinishedstatesbyname.get(opname, None) |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
292 if not p: |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
293 raise error.ProgrammingError(_(b'unknown op %s') % opname) |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
294 if childopname not in p._childopnames: |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
295 raise error.ProgrammingError( |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
296 _(b'op %s does not delegate to %s') % (opname, childopname) |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
297 ) |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
298 c = _unfinishedstatesbyname[childopname] |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
299 return p, c |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
300 |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
301 |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
302 @contextlib.contextmanager |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
303 def delegating(repo, opname, childopname): |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
304 """context wrapper for delegations from opname to childopname. |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
305 |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
306 requires that childopname was specified when opname was registered. |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
307 |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
308 Usage: |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
309 def my_command_foo_that_uses_rebase(...): |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
310 ... |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
311 with state.delegating(repo, 'foo', 'rebase'): |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
312 _run_rebase(...) |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
313 ... |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
314 """ |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
315 |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
316 p, c = _getparentandchild(opname, childopname) |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
317 if p._delegating: |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
318 raise error.ProgrammingError( |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
319 _(b'cannot delegate from op %s recursively') % opname |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
320 ) |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
321 p._delegating = True |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
322 try: |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
323 yield |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
324 except error.ConflictResolutionRequired as e: |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
325 # Rewrite conflict resolution advice for the parent opname. |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
326 if e.opname == childopname: |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
327 raise error.ConflictResolutionRequired(opname) |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
328 raise e |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
329 finally: |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
330 p._delegating = False |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
331 |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
332 |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
333 def ischildunfinished(repo, opname, childopname): |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
334 """Returns true if both opname and childopname are unfinished.""" |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
335 |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
336 p, c = _getparentandchild(opname, childopname) |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
337 return (p._delegating or p.isunfinished(repo)) and c.isunfinished(repo) |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
338 |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
339 |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
340 def continuechild(ui, repo, opname, childopname): |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
341 """Checks that childopname is in progress, and continues it.""" |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
342 |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
343 p, c = _getparentandchild(opname, childopname) |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
344 if not ischildunfinished(repo, opname, childopname): |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
345 raise error.ProgrammingError( |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
346 _(b'child op %s of parent %s is not unfinished') |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
347 % (childopname, opname) |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
348 ) |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
349 if not c.continuefunc: |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
350 raise error.ProgrammingError( |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
351 _(b'op %s has no continue function') % childopname |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
352 ) |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
353 return c.continuefunc(ui, repo) |
5322e738be0f
state: support validated declaration of nested unfinished ops
Daniel Ploch <dploch@google.com>
parents:
43773
diff
changeset
|
354 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
355 |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
356 addunfinished( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
357 b'update', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
358 fname=b'updatestate', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
359 clearable=True, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
360 cmdmsg=_(b'last update was interrupted'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
361 cmdhint=_(b"use 'hg update' to get a consistent checkout"), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
362 statushint=_(b"To continue: hg update ."), |
42530
dc3fdd1b5af4
state: created new class statecheck to handle unfinishedstates
Taapas Agrawal <taapas2897@gmail.com>
parents:
42529
diff
changeset
|
363 ) |
42532
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
364 addunfinished( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
365 b'bisect', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
366 fname=b'bisect.state', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
367 allowcommit=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
368 reportonly=True, |
49829
8ced4ca30ea1
bisect: correct message about aborting an in-progress bisect (issue6527)
Anton Shestakov <av6@dwimlabs.net>
parents:
48946
diff
changeset
|
369 cmdhint=_(b"use 'hg bisect --reset'"), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
370 statushint=_( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
371 b'To mark the changeset good: hg bisect --good\n' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
372 b'To mark the changeset bad: hg bisect --bad\n' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
373 b'To abort: hg bisect --reset\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
374 ), |
42532
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
375 ) |
42531
5bddd2244814
state: moved cmdutil.STATES and utilities to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents:
42530
diff
changeset
|
376 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
43045
diff
changeset
|
377 |
42531
5bddd2244814
state: moved cmdutil.STATES and utilities to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents:
42530
diff
changeset
|
378 def getrepostate(repo): |
5bddd2244814
state: moved cmdutil.STATES and utilities to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents:
42530
diff
changeset
|
379 # experimental config: commands.status.skipstates |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
380 skip = set(repo.ui.configlist(b'commands', b'status.skipstates')) |
42532
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
381 for state in _unfinishedstates: |
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
382 if state._opname in skip: |
42531
5bddd2244814
state: moved cmdutil.STATES and utilities to state.py
Taapas Agrawal <taapas2897@gmail.com>
parents:
42530
diff
changeset
|
383 continue |
42532
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
384 if state.isunfinished(repo): |
12243f15d53e
statecheck: added support for STATES
Taapas Agrawal <taapas2897@gmail.com>
parents:
42531
diff
changeset
|
385 return (state._opname, state.statusmsg()) |