author | Martin von Zweigbergk <martinvonz@google.com> |
Thu, 22 Oct 2020 14:14:59 -0700 | |
changeset 45877 | ac362d5a7893 |
parent 45712 | 0a330055340c |
child 45878 | f4a218331ff4 |
permissions | -rw-r--r-- |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1 |
# absorb.py |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
2 |
# |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
3 |
# Copyright 2016 Facebook, Inc. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
4 |
# |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
5 |
# This software may be used and distributed according to the terms of the |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
6 |
# GNU General Public License version 2 or any later version. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
7 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
8 |
"""apply working directory changes to changesets (EXPERIMENTAL) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
9 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
10 |
The absorb extension provides a command to use annotate information to |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
11 |
amend modified chunks into the corresponding non-public changesets. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
12 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
13 |
:: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
14 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
15 |
[absorb] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
16 |
# only check 50 recent non-public changesets at most |
38961
19344143b3e1
absorb: following UI conventions
David Demelier <markand@malikania.fr>
parents:
38932
diff
changeset
|
17 |
max-stack-size = 50 |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
18 |
# whether to add noise to new commits to avoid obsolescence cycle |
38961
19344143b3e1
absorb: following UI conventions
David Demelier <markand@malikania.fr>
parents:
38932
diff
changeset
|
19 |
add-noise = 1 |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
20 |
# make `amend --correlated` a shortcut to the main command |
38961
19344143b3e1
absorb: following UI conventions
David Demelier <markand@malikania.fr>
parents:
38932
diff
changeset
|
21 |
amend-flag = correlated |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
22 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
23 |
[color] |
40188
2c5316796f45
absorb: print summary of changesets affected
Mark Thomas <mbthomas@fb.com>
parents:
40187
diff
changeset
|
24 |
absorb.description = yellow |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
25 |
absorb.node = blue bold |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
26 |
absorb.path = bold |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
27 |
""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
28 |
|
38922
ec0697f4f9c9
absorb: note some TODOs from the code review
Augie Fackler <augie@google.com>
parents:
38921
diff
changeset
|
29 |
# TODO: |
ec0697f4f9c9
absorb: note some TODOs from the code review
Augie Fackler <augie@google.com>
parents:
38921
diff
changeset
|
30 |
# * Rename config items to [commands] namespace |
ec0697f4f9c9
absorb: note some TODOs from the code review
Augie Fackler <augie@google.com>
parents:
38921
diff
changeset
|
31 |
# * Converge getdraftstack() with other code in core |
ec0697f4f9c9
absorb: note some TODOs from the code review
Augie Fackler <augie@google.com>
parents:
38921
diff
changeset
|
32 |
# * move many attributes on fixupstate to be private |
ec0697f4f9c9
absorb: note some TODOs from the code review
Augie Fackler <augie@google.com>
parents:
38921
diff
changeset
|
33 |
|
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
34 |
from __future__ import absolute_import |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
35 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
36 |
import collections |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
37 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
38 |
from mercurial.i18n import _ |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
39 |
from mercurial import ( |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
40 |
cmdutil, |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
41 |
commands, |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
42 |
context, |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
43 |
crecord, |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
44 |
error, |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
45 |
linelog, |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
46 |
mdiff, |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
47 |
node, |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
48 |
obsolete, |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
49 |
patch, |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
50 |
phases, |
38920
a5c8c5476339
absorb: use pycompat to get xrange
Augie Fackler <augie@google.com>
parents:
38919
diff
changeset
|
51 |
pycompat, |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
52 |
registrar, |
45124
3ee8e2d5c0d8
absorb: consider rewrite.empty-successor configuration
Manuel Jacob <me@manueljacob.de>
parents:
44991
diff
changeset
|
53 |
rewriteutil, |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
54 |
scmutil, |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
55 |
util, |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
56 |
) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
57 |
from mercurial.utils import stringutil |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
58 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
59 |
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
60 |
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
61 |
# be specifying the version(s) of Mercurial they are tested with, or |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
62 |
# leave the attribute unspecified. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
63 |
testedwith = b'ships-with-hg-core' |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
64 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
65 |
cmdtable = {} |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
66 |
command = registrar.command(cmdtable) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
67 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
68 |
configtable = {} |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
69 |
configitem = registrar.configitem(configtable) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
70 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
71 |
configitem(b'absorb', b'add-noise', default=True) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
72 |
configitem(b'absorb', b'amend-flag', default=None) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
73 |
configitem(b'absorb', b'max-stack-size', default=50) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
74 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
75 |
colortable = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
76 |
b'absorb.description': b'yellow', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
77 |
b'absorb.node': b'blue bold', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
78 |
b'absorb.path': b'bold', |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
79 |
} |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
80 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
81 |
defaultdict = collections.defaultdict |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
82 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
83 |
|
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
84 |
class nullui(object): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
85 |
"""blank ui object doing nothing""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
86 |
|
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
87 |
debugflag = False |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
88 |
verbose = False |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
89 |
quiet = True |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
90 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
91 |
def __getitem__(name): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
92 |
def nullfunc(*args, **kwds): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
93 |
return |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
94 |
|
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
95 |
return nullfunc |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
96 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
97 |
|
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
98 |
class emptyfilecontext(object): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
99 |
"""minimal filecontext representing an empty file""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
100 |
|
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
101 |
def data(self): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
102 |
return b'' |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
103 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
104 |
def node(self): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
105 |
return node.nullid |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
106 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
107 |
|
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
108 |
def uniq(lst): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
109 |
"""list -> list. remove duplicated items without changing the order""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
110 |
seen = set() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
111 |
result = [] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
112 |
for x in lst: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
113 |
if x not in seen: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
114 |
seen.add(x) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
115 |
result.append(x) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
116 |
return result |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
117 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
118 |
|
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
119 |
def getdraftstack(headctx, limit=None): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
120 |
"""(ctx, int?) -> [ctx]. get a linear stack of non-public changesets. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
121 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
122 |
changesets are sorted in topo order, oldest first. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
123 |
return at most limit items, if limit is a positive number. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
124 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
125 |
merges are considered as non-draft as well. i.e. every commit |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
126 |
returned has and only has 1 parent. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
127 |
""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
128 |
ctx = headctx |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
129 |
result = [] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
130 |
while ctx.phase() != phases.public: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
131 |
if limit and len(result) >= limit: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
132 |
break |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
133 |
parents = ctx.parents() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
134 |
if len(parents) != 1: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
135 |
break |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
136 |
result.append(ctx) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
137 |
ctx = parents[0] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
138 |
result.reverse() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
139 |
return result |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
140 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
141 |
|
38918
2ac40e86f604
absorb: avoid mutable default arg
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
142 |
def getfilestack(stack, path, seenfctxs=None): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
143 |
"""([ctx], str, set) -> [fctx], {ctx: fctx} |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
144 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
145 |
stack is a list of contexts, from old to new. usually they are what |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
146 |
"getdraftstack" returns. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
147 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
148 |
follows renames, but not copies. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
149 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
150 |
seenfctxs is a set of filecontexts that will be considered "immutable". |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
151 |
they are usually what this function returned in earlier calls, useful |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
152 |
to avoid issues that a file was "moved" to multiple places and was then |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
153 |
modified differently, like: "a" was copied to "b", "a" was also copied to |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
154 |
"c" and then "a" was deleted, then both "b" and "c" were "moved" from "a" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
155 |
and we enforce only one of them to be able to affect "a"'s content. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
156 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
157 |
return an empty list and an empty dict, if the specified path does not |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
158 |
exist in stack[-1] (the top of the stack). |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
159 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
160 |
otherwise, return a list of de-duplicated filecontexts, and the map to |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
161 |
convert ctx in the stack to fctx, for possible mutable fctxs. the first item |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
162 |
of the list would be outside the stack and should be considered immutable. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
163 |
the remaining items are within the stack. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
164 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
165 |
for example, given the following changelog and corresponding filelog |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
166 |
revisions: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
167 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
168 |
changelog: 3----4----5----6----7 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
169 |
filelog: x 0----1----1----2 (x: no such file yet) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
170 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
171 |
- if stack = [5, 6, 7], returns ([0, 1, 2], {5: 1, 6: 1, 7: 2}) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
172 |
- if stack = [3, 4, 5], returns ([e, 0, 1], {4: 0, 5: 1}), where "e" is a |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
173 |
dummy empty filecontext. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
174 |
- if stack = [2], returns ([], {}) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
175 |
- if stack = [7], returns ([1, 2], {7: 2}) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
176 |
- if stack = [6, 7], returns ([1, 2], {6: 1, 7: 2}), although {6: 1} can be |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
177 |
removed, since 1 is immutable. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
178 |
""" |
38918
2ac40e86f604
absorb: avoid mutable default arg
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
179 |
if seenfctxs is None: |
2ac40e86f604
absorb: avoid mutable default arg
Augie Fackler <augie@google.com>
parents:
38917
diff
changeset
|
180 |
seenfctxs = set() |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
181 |
assert stack |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
182 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
183 |
if path not in stack[-1]: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
184 |
return [], {} |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
185 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
186 |
fctxs = [] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
187 |
fctxmap = {} |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
188 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
189 |
pctx = stack[0].p1() # the public (immutable) ctx we stop at |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
190 |
for ctx in reversed(stack): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
191 |
if path not in ctx: # the file is added in the next commit |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
192 |
pctx = ctx |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
193 |
break |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
194 |
fctx = ctx[path] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
195 |
fctxs.append(fctx) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
196 |
if fctx in seenfctxs: # treat fctx as the immutable one |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
197 |
pctx = None # do not add another immutable fctx |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
198 |
break |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
199 |
fctxmap[ctx] = fctx # only for mutable fctxs |
41778
8843bc1fc14d
absorb: migrate to new method for getting copy info
Martin von Zweigbergk <martinvonz@google.com>
parents:
41365
diff
changeset
|
200 |
copy = fctx.copysource() |
8843bc1fc14d
absorb: migrate to new method for getting copy info
Martin von Zweigbergk <martinvonz@google.com>
parents:
41365
diff
changeset
|
201 |
if copy: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
202 |
path = copy # follow rename |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
203 |
if path in ctx: # but do not follow copy |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
204 |
pctx = ctx.p1() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
205 |
break |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
206 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
207 |
if pctx is not None: # need an extra immutable fctx |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
208 |
if path in pctx: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
209 |
fctxs.append(pctx[path]) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
210 |
else: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
211 |
fctxs.append(emptyfilecontext()) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
212 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
213 |
fctxs.reverse() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
214 |
# note: we rely on a property of hg: filerev is not reused for linear |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
215 |
# history. i.e. it's impossible to have: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
216 |
# changelog: 4----5----6 (linear, no merges) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
217 |
# filelog: 1----2----1 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
218 |
# ^ reuse filerev (impossible) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
219 |
# because parents are part of the hash. if that's not true, we need to |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
220 |
# remove uniq and find a different way to identify fctxs. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
221 |
return uniq(fctxs), fctxmap |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
222 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
223 |
|
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
224 |
class overlaystore(patch.filestore): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
225 |
"""read-only, hybrid store based on a dict and ctx. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
226 |
memworkingcopy: {path: content}, overrides file contents. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
227 |
""" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
228 |
|
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
229 |
def __init__(self, basectx, memworkingcopy): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
230 |
self.basectx = basectx |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
231 |
self.memworkingcopy = memworkingcopy |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
232 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
233 |
def getfile(self, path): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
234 |
"""comply with mercurial.patch.filestore.getfile""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
235 |
if path not in self.basectx: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
236 |
return None, None, None |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
237 |
fctx = self.basectx[path] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
238 |
if path in self.memworkingcopy: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
239 |
content = self.memworkingcopy[path] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
240 |
else: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
241 |
content = fctx.data() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
242 |
mode = (fctx.islink(), fctx.isexec()) |
41778
8843bc1fc14d
absorb: migrate to new method for getting copy info
Martin von Zweigbergk <martinvonz@google.com>
parents:
41365
diff
changeset
|
243 |
copy = fctx.copysource() |
8843bc1fc14d
absorb: migrate to new method for getting copy info
Martin von Zweigbergk <martinvonz@google.com>
parents:
41365
diff
changeset
|
244 |
return content, mode, copy |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
245 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
246 |
|
45712
0a330055340c
absorb: update commit hash references in the new commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
45170
diff
changeset
|
247 |
def overlaycontext(memworkingcopy, ctx, parents=None, extra=None, desc=None): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
248 |
"""({path: content}, ctx, (p1node, p2node)?, {}?) -> memctx |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
249 |
memworkingcopy overrides file contents. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
250 |
""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
251 |
# parents must contain 2 items: (node1, node2) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
252 |
if parents is None: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
253 |
parents = ctx.repo().changelog.parents(ctx.node()) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
254 |
if extra is None: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
255 |
extra = ctx.extra() |
45712
0a330055340c
absorb: update commit hash references in the new commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
45170
diff
changeset
|
256 |
if desc is None: |
0a330055340c
absorb: update commit hash references in the new commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
45170
diff
changeset
|
257 |
desc = ctx.description() |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
258 |
date = ctx.date() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
259 |
user = ctx.user() |
38987
9204445ad54c
absorb: port partway to Python 3
Augie Fackler <augie@google.com>
parents:
38961
diff
changeset
|
260 |
files = set(ctx.files()).union(memworkingcopy) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
261 |
store = overlaystore(ctx, memworkingcopy) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
262 |
return context.memctx( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
263 |
repo=ctx.repo(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
264 |
parents=parents, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
265 |
text=desc, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
266 |
files=files, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
267 |
filectxfn=store, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
268 |
user=user, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
269 |
date=date, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
270 |
branch=None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
271 |
extra=extra, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
272 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
273 |
|
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
274 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
275 |
class filefixupstate(object): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
276 |
"""state needed to apply fixups to a single file |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
277 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
278 |
internally, it keeps file contents of several revisions and a linelog. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
279 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
280 |
the linelog uses odd revision numbers for original contents (fctxs passed |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
281 |
to __init__), and even revision numbers for fixups, like: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
282 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
283 |
linelog rev 1: self.fctxs[0] (from an immutable "public" changeset) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
284 |
linelog rev 2: fixups made to self.fctxs[0] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
285 |
linelog rev 3: self.fctxs[1] (a child of fctxs[0]) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
286 |
linelog rev 4: fixups made to self.fctxs[1] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
287 |
... |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
288 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
289 |
a typical use is like: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
290 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
291 |
1. call diffwith, to calculate self.fixups |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
292 |
2. (optionally), present self.fixups to the user, or change it |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
293 |
3. call apply, to apply changes |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
294 |
4. read results from "finalcontents", or call getfinalcontent |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
295 |
""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
296 |
|
40187
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
297 |
def __init__(self, fctxs, path, ui=None, opts=None): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
298 |
"""([fctx], ui or None) -> None |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
299 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
300 |
fctxs should be linear, and sorted by topo order - oldest first. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
301 |
fctxs[0] will be considered as "immutable" and will not be changed. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
302 |
""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
303 |
self.fctxs = fctxs |
40187
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
304 |
self.path = path |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
305 |
self.ui = ui or nullui() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
306 |
self.opts = opts or {} |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
307 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
308 |
# following fields are built from fctxs. they exist for perf reason |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
309 |
self.contents = [f.data() for f in fctxs] |
38987
9204445ad54c
absorb: port partway to Python 3
Augie Fackler <augie@google.com>
parents:
38961
diff
changeset
|
310 |
self.contentlines = pycompat.maplist(mdiff.splitnewlines, self.contents) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
311 |
self.linelog = self._buildlinelog() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
312 |
if self.ui.debugflag: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
313 |
assert self._checkoutlinelog() == self.contents |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
314 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
315 |
# following fields will be filled later |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
316 |
self.chunkstats = [0, 0] # [adopted, total : int] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
317 |
self.targetlines = [] # [str] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
318 |
self.fixups = [] # [(linelog rev, a1, a2, b1, b2)] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
319 |
self.finalcontents = [] # [str] |
40188
2c5316796f45
absorb: print summary of changesets affected
Mark Thomas <mbthomas@fb.com>
parents:
40187
diff
changeset
|
320 |
self.ctxaffected = set() |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
321 |
|
40187
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
322 |
def diffwith(self, targetfctx, fm=None): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
323 |
"""calculate fixups needed by examining the differences between |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
324 |
self.fctxs[-1] and targetfctx, chunk by chunk. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
325 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
326 |
targetfctx is the target state we move towards. we may or may not be |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
327 |
able to get there because not all modified chunks can be amended into |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
328 |
a non-public fctx unambiguously. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
329 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
330 |
call this only once, before apply(). |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
331 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
332 |
update self.fixups, self.chunkstats, and self.targetlines. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
333 |
""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
334 |
a = self.contents[-1] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
335 |
alines = self.contentlines[-1] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
336 |
b = targetfctx.data() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
337 |
blines = mdiff.splitnewlines(b) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
338 |
self.targetlines = blines |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
339 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
340 |
self.linelog.annotate(self.linelog.maxrev) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
341 |
annotated = self.linelog.annotateresult # [(linelog rev, linenum)] |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
342 |
assert len(annotated) == len(alines) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
343 |
# add a dummy end line to make insertion at the end easier |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
344 |
if annotated: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
345 |
dummyendline = (annotated[-1][0], annotated[-1][1] + 1) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
346 |
annotated.append(dummyendline) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
347 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
348 |
# analyse diff blocks |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
349 |
for chunk in self._alldiffchunks(a, b, alines, blines): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
350 |
newfixups = self._analysediffchunk(chunk, annotated) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
351 |
self.chunkstats[0] += bool(newfixups) # 1 or 0 |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
352 |
self.chunkstats[1] += 1 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
353 |
self.fixups += newfixups |
40187
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
354 |
if fm is not None: |
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
355 |
self._showchanges(fm, alines, blines, chunk, newfixups) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
356 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
357 |
def apply(self): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
358 |
"""apply self.fixups. update self.linelog, self.finalcontents. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
359 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
360 |
call this only once, before getfinalcontent(), after diffwith(). |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
361 |
""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
362 |
# the following is unnecessary, as it's done by "diffwith": |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
363 |
# self.linelog.annotate(self.linelog.maxrev) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
364 |
for rev, a1, a2, b1, b2 in reversed(self.fixups): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
365 |
blines = self.targetlines[b1:b2] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
366 |
if self.ui.debugflag: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
367 |
idx = (max(rev - 1, 0)) // 2 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
368 |
self.ui.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
369 |
_(b'%s: chunk %d:%d -> %d lines\n') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
370 |
% (node.short(self.fctxs[idx].node()), a1, a2, len(blines)) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
371 |
) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
372 |
self.linelog.replacelines(rev, a1, a2, b1, b2) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
373 |
if self.opts.get(b'edit_lines', False): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
374 |
self.finalcontents = self._checkoutlinelogwithedits() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
375 |
else: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
376 |
self.finalcontents = self._checkoutlinelog() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
377 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
378 |
def getfinalcontent(self, fctx): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
379 |
"""(fctx) -> str. get modified file content for a given filecontext""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
380 |
idx = self.fctxs.index(fctx) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
381 |
return self.finalcontents[idx] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
382 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
383 |
def _analysediffchunk(self, chunk, annotated): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
384 |
"""analyse a different chunk and return new fixups found |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
385 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
386 |
return [] if no lines from the chunk can be safely applied. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
387 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
388 |
the chunk (or lines) cannot be safely applied, if, for example: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
389 |
- the modified (deleted) lines belong to a public changeset |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
390 |
(self.fctxs[0]) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
391 |
- the chunk is a pure insertion and the adjacent lines (at most 2 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
392 |
lines) belong to different non-public changesets, or do not belong |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
393 |
to any non-public changesets. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
394 |
- the chunk is modifying lines from different changesets. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
395 |
in this case, if the number of lines deleted equals to the number |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
396 |
of lines added, assume it's a simple 1:1 map (could be wrong). |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
397 |
otherwise, give up. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
398 |
- the chunk is modifying lines from a single non-public changeset, |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
399 |
but other revisions touch the area as well. i.e. the lines are |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
400 |
not continuous as seen from the linelog. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
401 |
""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
402 |
a1, a2, b1, b2 = chunk |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
403 |
# find involved indexes from annotate result |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
404 |
involved = annotated[a1:a2] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
405 |
if not involved and annotated: # a1 == a2 and a is not empty |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
406 |
# pure insertion, check nearby lines. ignore lines belong |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
407 |
# to the public (first) changeset (i.e. annotated[i][0] == 1) |
38919
dc4750b2a04e
absorb: use set literal to avoid intermediate list
Augie Fackler <augie@google.com>
parents:
38918
diff
changeset
|
408 |
nearbylinenums = {a2, max(0, a1 - 1)} |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
409 |
involved = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
410 |
annotated[i] for i in nearbylinenums if annotated[i][0] != 1 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
411 |
] |
44452
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44236
diff
changeset
|
412 |
involvedrevs = list({r for r, l in involved}) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
413 |
newfixups = [] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
414 |
if len(involvedrevs) == 1 and self._iscontinuous(a1, a2 - 1, True): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
415 |
# chunk belongs to a single revision |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
416 |
rev = involvedrevs[0] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
417 |
if rev > 1: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
418 |
fixuprev = rev + 1 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
419 |
newfixups.append((fixuprev, a1, a2, b1, b2)) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
420 |
elif a2 - a1 == b2 - b1 or b1 == b2: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
421 |
# 1:1 line mapping, or chunk was deleted |
38920
a5c8c5476339
absorb: use pycompat to get xrange
Augie Fackler <augie@google.com>
parents:
38919
diff
changeset
|
422 |
for i in pycompat.xrange(a1, a2): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
423 |
rev, linenum = annotated[i] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
424 |
if rev > 1: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
425 |
if b1 == b2: # deletion, simply remove that single line |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
426 |
nb1 = nb2 = 0 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
427 |
else: # 1:1 line mapping, change the corresponding rev |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
428 |
nb1 = b1 + i - a1 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
429 |
nb2 = nb1 + 1 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
430 |
fixuprev = rev + 1 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
431 |
newfixups.append((fixuprev, i, i + 1, nb1, nb2)) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
432 |
return self._optimizefixups(newfixups) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
433 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
434 |
@staticmethod |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
435 |
def _alldiffchunks(a, b, alines, blines): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
436 |
"""like mdiff.allblocks, but only care about differences""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
437 |
blocks = mdiff.allblocks(a, b, lines1=alines, lines2=blines) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
438 |
for chunk, btype in blocks: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
439 |
if btype != b'!': |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
440 |
continue |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
441 |
yield chunk |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
442 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
443 |
def _buildlinelog(self): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
444 |
"""calculate the initial linelog based on self.content{,line}s. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
445 |
this is similar to running a partial "annotate". |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
446 |
""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
447 |
llog = linelog.linelog() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
448 |
a, alines = b'', [] |
38920
a5c8c5476339
absorb: use pycompat to get xrange
Augie Fackler <augie@google.com>
parents:
38919
diff
changeset
|
449 |
for i in pycompat.xrange(len(self.contents)): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
450 |
b, blines = self.contents[i], self.contentlines[i] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
451 |
llrev = i * 2 + 1 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
452 |
chunks = self._alldiffchunks(a, b, alines, blines) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
453 |
for a1, a2, b1, b2 in reversed(list(chunks)): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
454 |
llog.replacelines(llrev, a1, a2, b1, b2) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
455 |
a, alines = b, blines |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
456 |
return llog |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
457 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
458 |
def _checkoutlinelog(self): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
459 |
"""() -> [str]. check out file contents from linelog""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
460 |
contents = [] |
38920
a5c8c5476339
absorb: use pycompat to get xrange
Augie Fackler <augie@google.com>
parents:
38919
diff
changeset
|
461 |
for i in pycompat.xrange(len(self.contents)): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
462 |
rev = (i + 1) * 2 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
463 |
self.linelog.annotate(rev) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
464 |
content = b''.join(map(self._getline, self.linelog.annotateresult)) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
465 |
contents.append(content) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
466 |
return contents |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
467 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
468 |
def _checkoutlinelogwithedits(self): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
469 |
"""() -> [str]. prompt all lines for edit""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
470 |
alllines = self.linelog.getalllines() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
471 |
# header |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
472 |
editortext = ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
473 |
_( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
474 |
b'HG: editing %s\nHG: "y" means the line to the right ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
475 |
b'exists in the changeset to the top\nHG:\n' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
476 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
477 |
% self.fctxs[-1].path() |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
478 |
) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
479 |
# [(idx, fctx)]. hide the dummy emptyfilecontext |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
480 |
visiblefctxs = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
481 |
(i, f) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
482 |
for i, f in enumerate(self.fctxs) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
483 |
if not isinstance(f, emptyfilecontext) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
484 |
] |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
485 |
for i, (j, f) in enumerate(visiblefctxs): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
486 |
editortext += _(b'HG: %s/%s %s %s\n') % ( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
487 |
b'|' * i, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
488 |
b'-' * (len(visiblefctxs) - i + 1), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
489 |
node.short(f.node()), |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
490 |
f.description().split(b'\n', 1)[0], |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
491 |
) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
492 |
editortext += _(b'HG: %s\n') % (b'|' * len(visiblefctxs)) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
493 |
# figure out the lifetime of a line, this is relatively inefficient, |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
494 |
# but probably fine |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
495 |
lineset = defaultdict(lambda: set()) # {(llrev, linenum): {llrev}} |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
496 |
for i, f in visiblefctxs: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
497 |
self.linelog.annotate((i + 1) * 2) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
498 |
for l in self.linelog.annotateresult: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
499 |
lineset[l].add(i) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
500 |
# append lines |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
501 |
for l in alllines: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
502 |
editortext += b' %s : %s' % ( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
503 |
b''.join( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
504 |
[ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
505 |
(b'y' if i in lineset[l] else b' ') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
506 |
for i, _f in visiblefctxs |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
507 |
] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
508 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
509 |
self._getline(l), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
510 |
) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
511 |
# run editor |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
512 |
editedtext = self.ui.edit(editortext, b'', action=b'absorb') |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
513 |
if not editedtext: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
514 |
raise error.Abort(_(b'empty editor text')) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
515 |
# parse edited result |
43983
236cec445be2
absorb: avoid using a list comprehension to fill a list with fixed values
Matt Harbison <matt_harbison@yahoo.com>
parents:
43115
diff
changeset
|
516 |
contents = [b''] * len(self.fctxs) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
517 |
leftpadpos = 4 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
518 |
colonpos = leftpadpos + len(visiblefctxs) + 1 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
519 |
for l in mdiff.splitnewlines(editedtext): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
520 |
if l.startswith(b'HG:'): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
521 |
continue |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
522 |
if l[colonpos - 1 : colonpos + 2] != b' : ': |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
523 |
raise error.Abort(_(b'malformed line: %s') % l) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
524 |
linecontent = l[colonpos + 2 :] |
41260
c146651a78e1
absorb: add a pycompat.bytestr() to fix --edit-lines functionality on Python 3
Augie Fackler <augie@google.com>
parents:
40951
diff
changeset
|
525 |
for i, ch in enumerate( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
526 |
pycompat.bytestr(l[leftpadpos : colonpos - 1]) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
527 |
): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
528 |
if ch == b'y': |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
529 |
contents[visiblefctxs[i][0]] += linecontent |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
530 |
# chunkstats is hard to calculate if anything changes, therefore |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
531 |
# set them to just a simple value (1, 1). |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
532 |
if editedtext != editortext: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
533 |
self.chunkstats = [1, 1] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
534 |
return contents |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
535 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
536 |
def _getline(self, lineinfo): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
537 |
"""((rev, linenum)) -> str. convert rev+line number to line content""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
538 |
rev, linenum = lineinfo |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
539 |
if rev & 1: # odd: original line taken from fctxs |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
540 |
return self.contentlines[rev // 2][linenum] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
541 |
else: # even: fixup line from targetfctx |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
542 |
return self.targetlines[linenum] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
543 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
544 |
def _iscontinuous(self, a1, a2, closedinterval=False): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
545 |
"""(a1, a2 : int) -> bool |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
546 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
547 |
check if these lines are continuous. i.e. no other insertions or |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
548 |
deletions (from other revisions) among these lines. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
549 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
550 |
closedinterval decides whether a2 should be included or not. i.e. is |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
551 |
it [a1, a2), or [a1, a2] ? |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
552 |
""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
553 |
if a1 >= a2: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
554 |
return True |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
555 |
llog = self.linelog |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
556 |
offset1 = llog.getoffset(a1) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
557 |
offset2 = llog.getoffset(a2) + int(closedinterval) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
558 |
linesinbetween = llog.getalllines(offset1, offset2) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
559 |
return len(linesinbetween) == a2 - a1 + int(closedinterval) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
560 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
561 |
def _optimizefixups(self, fixups): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
562 |
"""[(rev, a1, a2, b1, b2)] -> [(rev, a1, a2, b1, b2)]. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
563 |
merge adjacent fixups to make them less fragmented. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
564 |
""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
565 |
result = [] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
566 |
pcurrentchunk = [[-1, -1, -1, -1, -1]] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
567 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
568 |
def pushchunk(): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
569 |
if pcurrentchunk[0][0] != -1: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
570 |
result.append(tuple(pcurrentchunk[0])) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
571 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
572 |
for i, chunk in enumerate(fixups): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
573 |
rev, a1, a2, b1, b2 = chunk |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
574 |
lastrev = pcurrentchunk[0][0] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
575 |
lasta2 = pcurrentchunk[0][2] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
576 |
lastb2 = pcurrentchunk[0][4] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
577 |
if ( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
578 |
a1 == lasta2 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
579 |
and b1 == lastb2 |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
580 |
and rev == lastrev |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
581 |
and self._iscontinuous(max(a1 - 1, 0), a1) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
582 |
): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
583 |
# merge into currentchunk |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
584 |
pcurrentchunk[0][2] = a2 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
585 |
pcurrentchunk[0][4] = b2 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
586 |
else: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
587 |
pushchunk() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
588 |
pcurrentchunk[0] = list(chunk) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
589 |
pushchunk() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
590 |
return result |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
591 |
|
40187
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
592 |
def _showchanges(self, fm, alines, blines, chunk, fixups): |
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
593 |
def trim(line): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
594 |
if line.endswith(b'\n'): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
595 |
line = line[:-1] |
40187
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
596 |
return line |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
597 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
598 |
# this is not optimized for perf but _showchanges only gets executed |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
599 |
# with an extra command-line flag. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
600 |
a1, a2, b1, b2 = chunk |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
601 |
aidxs, bidxs = [0] * (a2 - a1), [0] * (b2 - b1) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
602 |
for idx, fa1, fa2, fb1, fb2 in fixups: |
38920
a5c8c5476339
absorb: use pycompat to get xrange
Augie Fackler <augie@google.com>
parents:
38919
diff
changeset
|
603 |
for i in pycompat.xrange(fa1, fa2): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
604 |
aidxs[i - a1] = (max(idx, 1) - 1) // 2 |
38920
a5c8c5476339
absorb: use pycompat to get xrange
Augie Fackler <augie@google.com>
parents:
38919
diff
changeset
|
605 |
for i in pycompat.xrange(fb1, fb2): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
606 |
bidxs[i - b1] = (max(idx, 1) - 1) // 2 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
607 |
|
40187
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
608 |
fm.startitem() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
609 |
fm.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
610 |
b'hunk', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
611 |
b' %s\n', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
612 |
b'@@ -%d,%d +%d,%d @@' % (a1, a2 - a1, b1, b2 - b1), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
613 |
label=b'diff.hunk', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
614 |
) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
615 |
fm.data(path=self.path, linetype=b'hunk') |
40187
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
616 |
|
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
617 |
def writeline(idx, diffchar, line, linetype, linelabel): |
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
618 |
fm.startitem() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
619 |
node = b'' |
40187
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
620 |
if idx: |
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
621 |
ctx = self.fctxs[idx] |
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
622 |
fm.context(fctx=ctx) |
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
623 |
node = ctx.hex() |
40188
2c5316796f45
absorb: print summary of changesets affected
Mark Thomas <mbthomas@fb.com>
parents:
40187
diff
changeset
|
624 |
self.ctxaffected.add(ctx.changectx()) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
625 |
fm.write(b'node', b'%-7.7s ', node, label=b'absorb.node') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
626 |
fm.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
627 |
b'diffchar ' + linetype, |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
628 |
b'%s%s\n', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
629 |
diffchar, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
630 |
line, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
631 |
label=linelabel, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
632 |
) |
40187
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
633 |
fm.data(path=self.path, linetype=linetype) |
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
634 |
|
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
635 |
for i in pycompat.xrange(a1, a2): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
636 |
writeline( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
637 |
aidxs[i - a1], |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
638 |
b'-', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
639 |
trim(alines[i]), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
640 |
b'deleted', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
641 |
b'diff.deleted', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
642 |
) |
40187
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
643 |
for i in pycompat.xrange(b1, b2): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
644 |
writeline( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
645 |
bidxs[i - b1], |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
646 |
b'+', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
647 |
trim(blines[i]), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
648 |
b'inserted', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
649 |
b'diff.inserted', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
650 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
651 |
|
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
652 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
653 |
class fixupstate(object): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
654 |
"""state needed to run absorb |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
655 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
656 |
internally, it keeps paths and filefixupstates. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
657 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
658 |
a typical use is like filefixupstates: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
659 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
660 |
1. call diffwith, to calculate fixups |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
661 |
2. (optionally), present fixups to the user, or edit fixups |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
662 |
3. call apply, to apply changes to memory |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
663 |
4. call commit, to commit changes to hg database |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
664 |
""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
665 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
666 |
def __init__(self, stack, ui=None, opts=None): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
667 |
"""([ctx], ui or None) -> None |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
668 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
669 |
stack: should be linear, and sorted by topo order - oldest first. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
670 |
all commits in stack are considered mutable. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
671 |
""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
672 |
assert stack |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
673 |
self.ui = ui or nullui() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
674 |
self.opts = opts or {} |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
675 |
self.stack = stack |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
676 |
self.repo = stack[-1].repo().unfiltered() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
677 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
678 |
# following fields will be filled later |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
679 |
self.paths = [] # [str] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
680 |
self.status = None # ctx.status output |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
681 |
self.fctxmap = {} # {path: {ctx: fctx}} |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
682 |
self.fixupmap = {} # {path: filefixupstate} |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
683 |
self.replacemap = {} # {oldnode: newnode or None} |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
684 |
self.finalnode = None # head after all fixups |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
685 |
self.ctxaffected = set() # ctx that will be absorbed into |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
686 |
|
40187
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
687 |
def diffwith(self, targetctx, match=None, fm=None): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
688 |
"""diff and prepare fixups. update self.fixupmap, self.paths""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
689 |
# only care about modified files |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
690 |
self.status = self.stack[-1].status(targetctx, match) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
691 |
self.paths = [] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
692 |
# but if --edit-lines is used, the user may want to edit files |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
693 |
# even if they are not modified |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
694 |
editopt = self.opts.get(b'edit_lines') |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
695 |
if not self.status.modified and editopt and match: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
696 |
interestingpaths = match.files() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
697 |
else: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
698 |
interestingpaths = self.status.modified |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
699 |
# prepare the filefixupstate |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
700 |
seenfctxs = set() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
701 |
# sorting is necessary to eliminate ambiguity for the "double move" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
702 |
# case: "hg cp A B; hg cp A C; hg rm A", then only "B" can affect "A". |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
703 |
for path in sorted(interestingpaths): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
704 |
self.ui.debug(b'calculating fixups for %s\n' % path) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
705 |
targetfctx = targetctx[path] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
706 |
fctxs, ctx2fctx = getfilestack(self.stack, path, seenfctxs) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
707 |
# ignore symbolic links or binary, or unchanged files |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
708 |
if any( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
709 |
f.islink() or stringutil.binary(f.data()) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
710 |
for f in [targetfctx] + fctxs |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
711 |
if not isinstance(f, emptyfilecontext) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
712 |
): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
713 |
continue |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
714 |
if targetfctx.data() == fctxs[-1].data() and not editopt: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
715 |
continue |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
716 |
seenfctxs.update(fctxs[1:]) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
717 |
self.fctxmap[path] = ctx2fctx |
40187
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
718 |
fstate = filefixupstate(fctxs, path, ui=self.ui, opts=self.opts) |
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
719 |
if fm is not None: |
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
720 |
fm.startitem() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
721 |
fm.plain(b'showing changes for ') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
722 |
fm.write(b'path', b'%s\n', path, label=b'absorb.path') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
723 |
fm.data(linetype=b'path') |
40187
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
724 |
fstate.diffwith(targetfctx, fm) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
725 |
self.fixupmap[path] = fstate |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
726 |
self.paths.append(path) |
40188
2c5316796f45
absorb: print summary of changesets affected
Mark Thomas <mbthomas@fb.com>
parents:
40187
diff
changeset
|
727 |
self.ctxaffected.update(fstate.ctxaffected) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
728 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
729 |
def apply(self): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
730 |
"""apply fixups to individual filefixupstates""" |
43105
649d3ac37a12
py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
731 |
for path, state in pycompat.iteritems(self.fixupmap): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
732 |
if self.ui.debugflag: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
733 |
self.ui.write(_(b'applying fixups to %s\n') % path) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
734 |
state.apply() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
735 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
736 |
@property |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
737 |
def chunkstats(self): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
738 |
"""-> {path: chunkstats}. collect chunkstats from filefixupstates""" |
44452
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44236
diff
changeset
|
739 |
return { |
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44236
diff
changeset
|
740 |
path: state.chunkstats |
43105
649d3ac37a12
py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
741 |
for path, state in pycompat.iteritems(self.fixupmap) |
44452
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
44236
diff
changeset
|
742 |
} |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
743 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
744 |
def commit(self): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
745 |
"""commit changes. update self.finalnode, self.replacemap""" |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
746 |
with self.repo.transaction(b'absorb') as tr: |
42128
537a8aeb9977
absorb: aborting if another operation is in progress
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
41830
diff
changeset
|
747 |
self._commitstack() |
537a8aeb9977
absorb: aborting if another operation is in progress
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
41830
diff
changeset
|
748 |
self._movebookmarks(tr) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
749 |
if self.repo[b'.'].node() in self.replacemap: |
42128
537a8aeb9977
absorb: aborting if another operation is in progress
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
41830
diff
changeset
|
750 |
self._moveworkingdirectoryparent() |
537a8aeb9977
absorb: aborting if another operation is in progress
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
41830
diff
changeset
|
751 |
self._cleanupoldcommits() |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
752 |
return self.finalnode |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
753 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
754 |
def printchunkstats(self): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
755 |
"""print things like '1 of 2 chunk(s) applied'""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
756 |
ui = self.ui |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
757 |
chunkstats = self.chunkstats |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
758 |
if ui.verbose: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
759 |
# chunkstats for each file |
43105
649d3ac37a12
py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
760 |
for path, stat in pycompat.iteritems(chunkstats): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
761 |
if stat[0]: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
762 |
ui.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
763 |
_(b'%s: %d of %d chunk(s) applied\n') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
764 |
% (path, stat[0], stat[1]) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
765 |
) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
766 |
elif not ui.quiet: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
767 |
# a summary for all files |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
768 |
stats = chunkstats.values() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
769 |
applied, total = (sum(s[i] for s in stats) for i in (0, 1)) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
770 |
ui.write(_(b'%d of %d chunk(s) applied\n') % (applied, total)) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
771 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
772 |
def _commitstack(self): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
773 |
"""make new commits. update self.finalnode, self.replacemap. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
774 |
it is splitted from "commit" to avoid too much indentation. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
775 |
""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
776 |
# last node (20-char) committed by us |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
777 |
lastcommitted = None |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
778 |
# p1 which overrides the parent of the next commit, "None" means use |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
779 |
# the original parent unchanged |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
780 |
nextp1 = None |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
781 |
for ctx in self.stack: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
782 |
memworkingcopy = self._getnewfilecontents(ctx) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
783 |
if not memworkingcopy and not lastcommitted: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
784 |
# nothing changed, nothing commited |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
785 |
nextp1 = ctx |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
786 |
continue |
45125
f55099982bc5
absorb: make it explicit if empty changeset was created
Manuel Jacob <me@manueljacob.de>
parents:
45124
diff
changeset
|
787 |
willbecomenoop = ctx.files() and self._willbecomenoop( |
f55099982bc5
absorb: make it explicit if empty changeset was created
Manuel Jacob <me@manueljacob.de>
parents:
45124
diff
changeset
|
788 |
memworkingcopy, ctx, nextp1 |
f55099982bc5
absorb: make it explicit if empty changeset was created
Manuel Jacob <me@manueljacob.de>
parents:
45124
diff
changeset
|
789 |
) |
f55099982bc5
absorb: make it explicit if empty changeset was created
Manuel Jacob <me@manueljacob.de>
parents:
45124
diff
changeset
|
790 |
if self.skip_empty_successor and willbecomenoop: |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
791 |
# changeset is no longer necessary |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
792 |
self.replacemap[ctx.node()] = None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
793 |
msg = _(b'became empty and was dropped') |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
794 |
else: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
795 |
# changeset needs re-commit |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
796 |
nodestr = self._commitsingle(memworkingcopy, ctx, p1=nextp1) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
797 |
lastcommitted = self.repo[nodestr] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
798 |
nextp1 = lastcommitted |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
799 |
self.replacemap[ctx.node()] = lastcommitted.node() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
800 |
if memworkingcopy: |
45125
f55099982bc5
absorb: make it explicit if empty changeset was created
Manuel Jacob <me@manueljacob.de>
parents:
45124
diff
changeset
|
801 |
if willbecomenoop: |
45170
c87bd1fe3da2
absorb: improve message for the case when changeset became empty
Manuel Jacob <me@manueljacob.de>
parents:
45125
diff
changeset
|
802 |
msg = _(b'%d file(s) changed, became empty as %s') |
45125
f55099982bc5
absorb: make it explicit if empty changeset was created
Manuel Jacob <me@manueljacob.de>
parents:
45124
diff
changeset
|
803 |
else: |
f55099982bc5
absorb: make it explicit if empty changeset was created
Manuel Jacob <me@manueljacob.de>
parents:
45124
diff
changeset
|
804 |
msg = _(b'%d file(s) changed, became %s') |
f55099982bc5
absorb: make it explicit if empty changeset was created
Manuel Jacob <me@manueljacob.de>
parents:
45124
diff
changeset
|
805 |
msg = msg % ( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
806 |
len(memworkingcopy), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
807 |
self._ctx2str(lastcommitted), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
808 |
) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
809 |
else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
810 |
msg = _(b'became %s') % self._ctx2str(lastcommitted) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
811 |
if self.ui.verbose and msg: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
812 |
self.ui.write(_(b'%s: %s\n') % (self._ctx2str(ctx), msg)) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
813 |
self.finalnode = lastcommitted and lastcommitted.node() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
814 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
815 |
def _ctx2str(self, ctx): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
816 |
if self.ui.debugflag: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
817 |
return b'%d:%s' % (ctx.rev(), ctx.hex()) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
818 |
else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
819 |
return b'%d:%s' % (ctx.rev(), node.short(ctx.node())) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
820 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
821 |
def _getnewfilecontents(self, ctx): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
822 |
"""(ctx) -> {path: str} |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
823 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
824 |
fetch file contents from filefixupstates. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
825 |
return the working copy overrides - files different from ctx. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
826 |
""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
827 |
result = {} |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
828 |
for path in self.paths: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
829 |
ctx2fctx = self.fctxmap[path] # {ctx: fctx} |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
830 |
if ctx not in ctx2fctx: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
831 |
continue |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
832 |
fctx = ctx2fctx[ctx] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
833 |
content = fctx.data() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
834 |
newcontent = self.fixupmap[path].getfinalcontent(fctx) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
835 |
if content != newcontent: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
836 |
result[fctx.path()] = newcontent |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
837 |
return result |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
838 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
839 |
def _movebookmarks(self, tr): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
840 |
repo = self.repo |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
841 |
needupdate = [ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
842 |
(name, self.replacemap[hsh]) |
43105
649d3ac37a12
py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
843 |
for name, hsh in pycompat.iteritems(repo._bookmarks) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
844 |
if hsh in self.replacemap |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
845 |
] |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
846 |
changes = [] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
847 |
for name, hsh in needupdate: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
848 |
if hsh: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
849 |
changes.append((name, hsh)) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
850 |
if self.ui.verbose: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
851 |
self.ui.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
852 |
_(b'moving bookmark %s to %s\n') % (name, node.hex(hsh)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
853 |
) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
854 |
else: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
855 |
changes.append((name, None)) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
856 |
if self.ui.verbose: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
857 |
self.ui.write(_(b'deleting bookmark %s\n') % name) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
858 |
repo._bookmarks.applychanges(repo, tr, changes) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
859 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
860 |
def _moveworkingdirectoryparent(self): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
861 |
if not self.finalnode: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
862 |
# Find the latest not-{obsoleted,stripped} parent. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
863 |
revs = self.repo.revs(b'max(::. - %ln)', self.replacemap.keys()) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
864 |
ctx = self.repo[revs.first()] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
865 |
self.finalnode = ctx.node() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
866 |
else: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
867 |
ctx = self.repo[self.finalnode] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
868 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
869 |
dirstate = self.repo.dirstate |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
870 |
# dirstate.rebuild invalidates fsmonitorstate, causing "hg status" to |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
871 |
# be slow. in absorb's case, no need to invalidate fsmonitorstate. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
872 |
noop = lambda: 0 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
873 |
restore = noop |
43115
4aa72cdf616f
py3: delete b'' prefix from safehasattr arguments
Martin von Zweigbergk <martinvonz@google.com>
parents:
43105
diff
changeset
|
874 |
if util.safehasattr(dirstate, '_fsmonitorstate'): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
875 |
bak = dirstate._fsmonitorstate.invalidate |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
876 |
|
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
877 |
def restore(): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
878 |
dirstate._fsmonitorstate.invalidate = bak |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
879 |
|
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
880 |
dirstate._fsmonitorstate.invalidate = noop |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
881 |
try: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
882 |
with dirstate.parentchange(): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
883 |
dirstate.rebuild(ctx.node(), ctx.manifest(), self.paths) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
884 |
finally: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
885 |
restore() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
886 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
887 |
@staticmethod |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
888 |
def _willbecomenoop(memworkingcopy, ctx, pctx=None): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
889 |
"""({path: content}, ctx, ctx) -> bool. test if a commit will be noop |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
890 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
891 |
if it will become an empty commit (does not change anything, after the |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
892 |
memworkingcopy overrides), return True. otherwise return False. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
893 |
""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
894 |
if not pctx: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
895 |
parents = ctx.parents() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
896 |
if len(parents) != 1: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
897 |
return False |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
898 |
pctx = parents[0] |
44983
1b757f385549
absorb: preserve branch-changing changesets even if empty
Manuel Jacob <me@manueljacob.de>
parents:
44452
diff
changeset
|
899 |
if ctx.branch() != pctx.branch(): |
1b757f385549
absorb: preserve branch-changing changesets even if empty
Manuel Jacob <me@manueljacob.de>
parents:
44452
diff
changeset
|
900 |
return False |
44984
bfef35bb4ecb
absorb: preserve branch-closing changesets even if empty
Manuel Jacob <me@manueljacob.de>
parents:
44983
diff
changeset
|
901 |
if ctx.extra().get(b'close'): |
bfef35bb4ecb
absorb: preserve branch-closing changesets even if empty
Manuel Jacob <me@manueljacob.de>
parents:
44983
diff
changeset
|
902 |
return False |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
903 |
# ctx changes more files (not a subset of memworkingcopy) |
38987
9204445ad54c
absorb: port partway to Python 3
Augie Fackler <augie@google.com>
parents:
38961
diff
changeset
|
904 |
if not set(ctx.files()).issubset(set(memworkingcopy)): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
905 |
return False |
43105
649d3ac37a12
py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
906 |
for path, content in pycompat.iteritems(memworkingcopy): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
907 |
if path not in pctx or path not in ctx: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
908 |
return False |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
909 |
fctx = ctx[path] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
910 |
pfctx = pctx[path] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
911 |
if pfctx.flags() != fctx.flags(): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
912 |
return False |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
913 |
if pfctx.data() != content: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
914 |
return False |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
915 |
return True |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
916 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
917 |
def _commitsingle(self, memworkingcopy, ctx, p1=None): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
918 |
"""(ctx, {path: content}, node) -> node. make a single commit |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
919 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
920 |
the commit is a clone from ctx, with a (optionally) different p1, and |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
921 |
different file contents replaced by memworkingcopy. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
922 |
""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
923 |
parents = p1 and (p1, node.nullid) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
924 |
extra = ctx.extra() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
925 |
if self._useobsolete and self.ui.configbool(b'absorb', b'add-noise'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
926 |
extra[b'absorb_source'] = ctx.hex() |
45712
0a330055340c
absorb: update commit hash references in the new commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
45170
diff
changeset
|
927 |
|
0a330055340c
absorb: update commit hash references in the new commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
45170
diff
changeset
|
928 |
desc = rewriteutil.update_hash_refs( |
0a330055340c
absorb: update commit hash references in the new commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
45170
diff
changeset
|
929 |
ctx.repo(), |
0a330055340c
absorb: update commit hash references in the new commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
45170
diff
changeset
|
930 |
ctx.description(), |
0a330055340c
absorb: update commit hash references in the new commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
45170
diff
changeset
|
931 |
{ |
0a330055340c
absorb: update commit hash references in the new commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
45170
diff
changeset
|
932 |
oldnode: [newnode] |
0a330055340c
absorb: update commit hash references in the new commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
45170
diff
changeset
|
933 |
for oldnode, newnode in self.replacemap.items() |
0a330055340c
absorb: update commit hash references in the new commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
45170
diff
changeset
|
934 |
}, |
0a330055340c
absorb: update commit hash references in the new commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
45170
diff
changeset
|
935 |
) |
0a330055340c
absorb: update commit hash references in the new commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
45170
diff
changeset
|
936 |
mctx = overlaycontext( |
0a330055340c
absorb: update commit hash references in the new commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
45170
diff
changeset
|
937 |
memworkingcopy, ctx, parents, extra=extra, desc=desc |
0a330055340c
absorb: update commit hash references in the new commits
Matt Harbison <matt_harbison@yahoo.com>
parents:
45170
diff
changeset
|
938 |
) |
41813
b38c7304974f
absorb: let scmutil.cleanupnodes() take care of setting phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
41812
diff
changeset
|
939 |
return mctx.commit() |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
940 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
941 |
@util.propertycache |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
942 |
def _useobsolete(self): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
943 |
"""() -> bool""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
944 |
return obsolete.isenabled(self.repo, obsolete.createmarkersopt) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
945 |
|
41812
c91321e86071
absorb: use scmutil.cleanupnodes() also when obsmarkers are disabled
Martin von Zweigbergk <martinvonz@google.com>
parents:
41811
diff
changeset
|
946 |
def _cleanupoldcommits(self): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
947 |
replacements = { |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
948 |
k: ([v] if v is not None else []) |
43105
649d3ac37a12
py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
949 |
for k, v in pycompat.iteritems(self.replacemap) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
950 |
} |
41811
a008e0af892e
absorb: use scmutil.cleanupnodes() so operation gets set
Martin von Zweigbergk <martinvonz@google.com>
parents:
41778
diff
changeset
|
951 |
if replacements: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
952 |
scmutil.cleanupnodes( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
953 |
self.repo, replacements, operation=b'absorb', fixphase=True |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
954 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
955 |
|
45124
3ee8e2d5c0d8
absorb: consider rewrite.empty-successor configuration
Manuel Jacob <me@manueljacob.de>
parents:
44991
diff
changeset
|
956 |
@util.propertycache |
3ee8e2d5c0d8
absorb: consider rewrite.empty-successor configuration
Manuel Jacob <me@manueljacob.de>
parents:
44991
diff
changeset
|
957 |
def skip_empty_successor(self): |
3ee8e2d5c0d8
absorb: consider rewrite.empty-successor configuration
Manuel Jacob <me@manueljacob.de>
parents:
44991
diff
changeset
|
958 |
return rewriteutil.skip_empty_successor(self.ui, b'absorb') |
3ee8e2d5c0d8
absorb: consider rewrite.empty-successor configuration
Manuel Jacob <me@manueljacob.de>
parents:
44991
diff
changeset
|
959 |
|
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
960 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
961 |
def _parsechunk(hunk): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
962 |
"""(crecord.uihunk or patch.recordhunk) -> (path, (a1, a2, [bline]))""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
963 |
if type(hunk) not in (crecord.uihunk, patch.recordhunk): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
964 |
return None, None |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
965 |
path = hunk.header.filename() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
966 |
a1 = hunk.fromline + len(hunk.before) - 1 |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
967 |
# remove before and after context |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
968 |
hunk.before = hunk.after = [] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
969 |
buf = util.stringio() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
970 |
hunk.write(buf) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
971 |
patchlines = mdiff.splitnewlines(buf.getvalue()) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
972 |
# hunk.prettystr() will update hunk.removed |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
973 |
a2 = a1 + hunk.removed |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
974 |
blines = [l[1:] for l in patchlines[1:] if not l.startswith(b'-')] |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
975 |
return path, (a1, a2, blines) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
976 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
977 |
|
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
978 |
def overlaydiffcontext(ctx, chunks): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
979 |
"""(ctx, [crecord.uihunk]) -> memctx |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
980 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
981 |
return a memctx with some [1] patches (chunks) applied to ctx. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
982 |
[1]: modifications are handled. renames, mode changes, etc. are ignored. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
983 |
""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
984 |
# sadly the applying-patch logic is hardly reusable, and messy: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
985 |
# 1. the core logic "_applydiff" is too heavy - it writes .rej files, it |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
986 |
# needs a file stream of a patch and will re-parse it, while we have |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
987 |
# structured hunk objects at hand. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
988 |
# 2. a lot of different implementations about "chunk" (patch.hunk, |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
989 |
# patch.recordhunk, crecord.uihunk) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
990 |
# as we only care about applying changes to modified files, no mode |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
991 |
# change, no binary diff, and no renames, it's probably okay to |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
992 |
# re-invent the logic using much simpler code here. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
993 |
memworkingcopy = {} # {path: content} |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
994 |
patchmap = defaultdict(lambda: []) # {path: [(a1, a2, [bline])]} |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
995 |
for path, info in map(_parsechunk, chunks): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
996 |
if not path or not info: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
997 |
continue |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
998 |
patchmap[path].append(info) |
43105
649d3ac37a12
py3: define and use pycompat.iteritems() for hgext/
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43077
diff
changeset
|
999 |
for path, patches in pycompat.iteritems(patchmap): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1000 |
if path not in ctx or not patches: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1001 |
continue |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1002 |
patches.sort(reverse=True) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1003 |
lines = mdiff.splitnewlines(ctx[path].data()) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1004 |
for a1, a2, blines in patches: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1005 |
lines[a1:a2] = blines |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1006 |
memworkingcopy[path] = b''.join(lines) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1007 |
return overlaycontext(memworkingcopy, ctx) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1008 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1009 |
|
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1010 |
def absorb(ui, repo, stack=None, targetctx=None, pats=None, opts=None): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1011 |
"""pick fixup chunks from targetctx, apply them to stack. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1012 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1013 |
if targetctx is None, the working copy context will be used. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1014 |
if stack is None, the current draft stack will be used. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1015 |
return fixupstate. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1016 |
""" |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1017 |
if stack is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1018 |
limit = ui.configint(b'absorb', b'max-stack-size') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1019 |
headctx = repo[b'.'] |
42266
b3fc78c028ef
absorb: be more specific when erroring out on merge commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
42128
diff
changeset
|
1020 |
if len(headctx.parents()) > 1: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1021 |
raise error.Abort(_(b'cannot absorb into a merge')) |
42266
b3fc78c028ef
absorb: be more specific when erroring out on merge commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
42128
diff
changeset
|
1022 |
stack = getdraftstack(headctx, limit) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1023 |
if limit and len(stack) >= limit: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1024 |
ui.warn( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1025 |
_( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1026 |
b'absorb: only the recent %d changesets will ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1027 |
b'be analysed\n' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1028 |
) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1029 |
% limit |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1030 |
) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1031 |
if not stack: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1032 |
raise error.Abort(_(b'no mutable changeset to change')) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1033 |
if targetctx is None: # default to working copy |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1034 |
targetctx = repo[None] |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1035 |
if pats is None: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1036 |
pats = () |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1037 |
if opts is None: |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1038 |
opts = {} |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1039 |
state = fixupstate(stack, ui=ui, opts=opts) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1040 |
matcher = scmutil.match(targetctx, pats, opts) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1041 |
if opts.get(b'interactive'): |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1042 |
diff = patch.diff(repo, stack[-1].node(), targetctx.node(), matcher) |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1043 |
origchunks = patch.parsepatch(diff) |
42351
86f17fc31aa8
absorb: fix interactive mode I didn't know existed
Augie Fackler <augie@google.com>
parents:
42266
diff
changeset
|
1044 |
chunks = cmdutil.recordfilter(ui, origchunks, matcher)[0] |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1045 |
targetctx = overlaydiffcontext(stack[-1], chunks) |
40187
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
1046 |
fm = None |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1047 |
if opts.get(b'print_changes') or not opts.get(b'apply_changes'): |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1048 |
fm = ui.formatter(b'absorb', opts) |
40187
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
1049 |
state.diffwith(targetctx, matcher, fm) |
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
1050 |
if fm is not None: |
40188
2c5316796f45
absorb: print summary of changesets affected
Mark Thomas <mbthomas@fb.com>
parents:
40187
diff
changeset
|
1051 |
fm.startitem() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1052 |
fm.write( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1053 |
b"count", b"\n%d changesets affected\n", len(state.ctxaffected) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1054 |
) |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1055 |
fm.data(linetype=b'summary') |
40188
2c5316796f45
absorb: print summary of changesets affected
Mark Thomas <mbthomas@fb.com>
parents:
40187
diff
changeset
|
1056 |
for ctx in reversed(stack): |
2c5316796f45
absorb: print summary of changesets affected
Mark Thomas <mbthomas@fb.com>
parents:
40187
diff
changeset
|
1057 |
if ctx not in state.ctxaffected: |
2c5316796f45
absorb: print summary of changesets affected
Mark Thomas <mbthomas@fb.com>
parents:
40187
diff
changeset
|
1058 |
continue |
2c5316796f45
absorb: print summary of changesets affected
Mark Thomas <mbthomas@fb.com>
parents:
40187
diff
changeset
|
1059 |
fm.startitem() |
2c5316796f45
absorb: print summary of changesets affected
Mark Thomas <mbthomas@fb.com>
parents:
40187
diff
changeset
|
1060 |
fm.context(ctx=ctx) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1061 |
fm.data(linetype=b'changeset') |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1062 |
fm.write(b'node', b'%-7.7s ', ctx.hex(), label=b'absorb.node') |
40188
2c5316796f45
absorb: print summary of changesets affected
Mark Thomas <mbthomas@fb.com>
parents:
40187
diff
changeset
|
1063 |
descfirstline = ctx.description().splitlines()[0] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1064 |
fm.write( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1065 |
b'descfirstline', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1066 |
b'%s\n', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1067 |
descfirstline, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1068 |
label=b'absorb.description', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1069 |
) |
40187
dcda50856843
absorb: use a formatter to generate output
Mark Thomas <mbthomas@fb.com>
parents:
40150
diff
changeset
|
1070 |
fm.end() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1071 |
if not opts.get(b'dry_run'): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1072 |
if ( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1073 |
not opts.get(b'apply_changes') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1074 |
and state.ctxaffected |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1075 |
and ui.promptchoice( |
44991
65d19d9c8e76
absorb: make it clear what happens when no input
Sushil khanchi <sushilkhanchi97@gmail.com>
parents:
44985
diff
changeset
|
1076 |
b"apply changes (y/N)? $$ &Yes $$ &No", default=1 |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1077 |
) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1078 |
): |
45877
ac362d5a7893
errors: introduce CanceledError and use it in a few places
Martin von Zweigbergk <martinvonz@google.com>
parents:
45712
diff
changeset
|
1079 |
raise error.CanceledError(_(b'absorb cancelled\n')) |
40190
31dfa7dac4c9
absorb: prompt user to accept absorb changes by default
Mark Thomas <mbthomas@fb.com>
parents:
40188
diff
changeset
|
1080 |
|
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1081 |
state.apply() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1082 |
if state.commit(): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1083 |
state.printchunkstats() |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1084 |
elif not ui.quiet: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1085 |
ui.write(_(b'nothing applied\n')) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1086 |
return state |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1087 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1088 |
|
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1089 |
@command( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1090 |
b'absorb', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1091 |
[ |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1092 |
( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1093 |
b'a', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1094 |
b'apply-changes', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1095 |
None, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1096 |
_(b'apply changes without prompting for confirmation'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1097 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1098 |
( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1099 |
b'p', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1100 |
b'print-changes', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1101 |
None, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1102 |
_(b'always print which changesets are modified by which changes'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1103 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1104 |
( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1105 |
b'i', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1106 |
b'interactive', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1107 |
None, |
44236
e1ecfc7c84be
absorb: graduate -i flag from experimental
Martin von Zweigbergk <martinvonz@google.com>
parents:
43983
diff
changeset
|
1108 |
_(b'interactively select which chunks to apply'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1109 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1110 |
( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1111 |
b'e', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1112 |
b'edit-lines', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1113 |
None, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1114 |
_( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1115 |
b'edit what lines belong to which changesets before commit ' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1116 |
b'(EXPERIMENTAL)' |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1117 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1118 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1119 |
] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1120 |
+ commands.dryrunopts |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1121 |
+ commands.templateopts |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1122 |
+ commands.walkopts, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1123 |
_(b'hg absorb [OPTION] [FILE]...'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1124 |
helpcategory=command.CATEGORY_COMMITTING, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1125 |
helpbasic=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42442
diff
changeset
|
1126 |
) |
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1127 |
def absorbcmd(ui, repo, *pats, **opts): |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1128 |
"""incorporate corrections into the stack of draft changesets |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1129 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1130 |
absorb analyzes each change in your working directory and attempts to |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1131 |
amend the changed lines into the changesets in your stack that first |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1132 |
introduced those lines. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1133 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1134 |
If absorb cannot find an unambiguous changeset to amend for a change, |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1135 |
that change will be left in the working directory, untouched. They can be |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1136 |
observed by :hg:`status` or :hg:`diff` afterwards. In other words, |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1137 |
absorb does not write to the working directory. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1138 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1139 |
Changesets outside the revset `::. and not public() and not merge()` will |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1140 |
not be changed. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1141 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1142 |
Changesets that become empty after applying the changes will be deleted. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1143 |
|
40210 | 1144 |
By default, absorb will show what it plans to do and prompt for |
1145 |
confirmation. If you are confident that the changes will be absorbed |
|
1146 |
to the correct place, run :hg:`absorb -a` to apply the changes |
|
1147 |
immediately. |
|
38917
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1148 |
|
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1149 |
Returns 0 on success, 1 if all chunks were ignored and nothing amended. |
5111d11b8719
absorb: import extension from Facebook's hg-experimental
Augie Fackler <augie@google.com>
parents:
diff
changeset
|
1150 |
""" |
39786
d50125dec2c1
py3: fix kwargs handling in hgext/absorb.py
Pulkit Goyal <pulkit@yandex-team.ru>
parents:
39453
diff
changeset
|
1151 |
opts = pycompat.byteskwargs(opts) |
42128
537a8aeb9977
absorb: aborting if another operation is in progress
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
41830
diff
changeset
|
1152 |
|
537a8aeb9977
absorb: aborting if another operation is in progress
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
41830
diff
changeset
|
1153 |
with repo.wlock(), repo.lock(): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
1154 |
if not opts[b'dry_run']: |
42128
537a8aeb9977
absorb: aborting if another operation is in progress
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
41830
diff
changeset
|
1155 |
cmdutil.checkunfinished(repo) |
537a8aeb9977
absorb: aborting if another operation is in progress
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
41830
diff
changeset
|
1156 |
|
537a8aeb9977
absorb: aborting if another operation is in progress
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
41830
diff
changeset
|
1157 |
state = absorb(ui, repo, pats=pats, opts=opts) |
537a8aeb9977
absorb: aborting if another operation is in progress
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
41830
diff
changeset
|
1158 |
if sum(s[0] for s in state.chunkstats.values()) == 0: |
537a8aeb9977
absorb: aborting if another operation is in progress
Rodrigo Damazio Bovendorp <rdamazio@google.com>
parents:
41830
diff
changeset
|
1159 |
return 1 |