author | Pierre-Yves David <pierre-yves.david@octobus.net> |
Sun, 11 Jul 2021 16:09:38 +0200 | |
changeset 47638 | 55a715c36e3b |
parent 47432 | 7f7457f84311 |
child 48581 | 4f01821fa0ec |
permissions | -rw-r--r-- |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
1 |
# uncommit - undo the actions of a commit |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
2 |
# |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2011 Peter Arrenbrecht <peter.arrenbrecht@gmail.com> |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
4 |
# Logilab SA <contact@logilab.fr> |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
5 |
# Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
6 |
# Patrick Mezard <patrick@mezard.eu> |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
7 |
# Copyright 2016 Facebook, Inc. |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
8 |
# |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
9 |
# This software may be used and distributed according to the terms of the |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
10 |
# GNU General Public License version 2 or any later version. |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
11 |
|
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
12 |
"""uncommit part or all of a local changeset (EXPERIMENTAL) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
13 |
|
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
14 |
This command undoes the effect of a local commit, returning the affected |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
15 |
files to their uncommitted state. This means that files modified, added or |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
16 |
removed in the changeset will be left unchanged, and so will remain modified, |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
17 |
added and removed in the working directory. |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
18 |
""" |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
19 |
|
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
20 |
from __future__ import absolute_import |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
21 |
|
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
22 |
from mercurial.i18n import _ |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
23 |
|
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
24 |
from mercurial import ( |
34284
624c53e4121d
uncommit: don't allow bare uncommit on dirty working directory
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34283
diff
changeset
|
25 |
cmdutil, |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
26 |
commands, |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
27 |
context, |
41339
7be231f5a4ad
unamend: import "copies" module as "copiesmod" to avoid shadowing
Martin von Zweigbergk <martinvonz@google.com>
parents:
40295
diff
changeset
|
28 |
copies as copiesmod, |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
29 |
error, |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
30 |
obsutil, |
43523
c21aca51b392
utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43117
diff
changeset
|
31 |
pathutil, |
35004
3ebae3ec4664
py3: handle keyword arguments in hgext/uncommit.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34758
diff
changeset
|
32 |
pycompat, |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
33 |
registrar, |
35244
98f97eb20597
rewriteutil: use precheck() in uncommit and amend commands
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35200
diff
changeset
|
34 |
rewriteutil, |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
35 |
scmutil, |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
36 |
) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
37 |
|
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
38 |
cmdtable = {} |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
39 |
command = registrar.command(cmdtable) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
40 |
|
34758
9ea416a4b4f7
configitems: register the 'experimental.uncommitondirtywdir' config
Boris Feld <boris.feld@octobus.net>
parents:
34285
diff
changeset
|
41 |
configtable = {} |
9ea416a4b4f7
configitems: register the 'experimental.uncommitondirtywdir' config
Boris Feld <boris.feld@octobus.net>
parents:
34285
diff
changeset
|
42 |
configitem = registrar.configitem(configtable) |
9ea416a4b4f7
configitems: register the 'experimental.uncommitondirtywdir' config
Boris Feld <boris.feld@octobus.net>
parents:
34285
diff
changeset
|
43 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
44 |
configitem( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44452
diff
changeset
|
45 |
b'experimental', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44452
diff
changeset
|
46 |
b'uncommitondirtywdir', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44452
diff
changeset
|
47 |
default=False, |
34758
9ea416a4b4f7
configitems: register the 'experimental.uncommitondirtywdir' config
Boris Feld <boris.feld@octobus.net>
parents:
34285
diff
changeset
|
48 |
) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
49 |
configitem( |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44452
diff
changeset
|
50 |
b'experimental', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44452
diff
changeset
|
51 |
b'uncommit.keep', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
44452
diff
changeset
|
52 |
default=False, |
41750
1040d54eb7eb
uncommit: add config option to keep commit by default
Martin von Zweigbergk <martinvonz@google.com>
parents:
41745
diff
changeset
|
53 |
) |
34758
9ea416a4b4f7
configitems: register the 'experimental.uncommitondirtywdir' config
Boris Feld <boris.feld@octobus.net>
parents:
34285
diff
changeset
|
54 |
|
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
55 |
# Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
56 |
# extensions which SHIP WITH MERCURIAL. Non-mainline extensions should |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
57 |
# be specifying the version(s) of Mercurial they are tested with, or |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
58 |
# leave the attribute unspecified. |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
59 |
testedwith = b'ships-with-hg-core' |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
60 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
61 |
|
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
62 |
def _commitfiltered( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
63 |
repo, ctx, match, keepcommit, message=None, user=None, date=None |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
64 |
): |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
65 |
"""Recommit ctx with changed files not in match. Return the new |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
66 |
node identifier, or None if nothing changed. |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
67 |
""" |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
68 |
base = ctx.p1() |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
69 |
# ctx |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
70 |
initialfiles = set(ctx.files()) |
44452
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
43643
diff
changeset
|
71 |
exclude = {f for f in initialfiles if match(f)} |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
72 |
|
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
73 |
# No files matched commit, so nothing excluded |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
74 |
if not exclude: |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
75 |
return None |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
76 |
|
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
77 |
# return the p1 so that we don't create an obsmarker later |
36974
435b8b05affd
uncommit: simplify condition for keeping commit
Martin von Zweigbergk <martinvonz@google.com>
parents:
36973
diff
changeset
|
78 |
if not keepcommit: |
41397
0bd56c291359
cleanup: use p1() and p2() instead of parents()[0] and parents()[1]
Martin von Zweigbergk <martinvonz@google.com>
parents:
41342
diff
changeset
|
79 |
return ctx.p1().node() |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
80 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
81 |
files = initialfiles - exclude |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
82 |
# Filter copies |
41339
7be231f5a4ad
unamend: import "copies" module as "copiesmod" to avoid shadowing
Martin von Zweigbergk <martinvonz@google.com>
parents:
40295
diff
changeset
|
83 |
copied = copiesmod.pathcopies(base, ctx) |
44452
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
43643
diff
changeset
|
84 |
copied = { |
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
43643
diff
changeset
|
85 |
dst: src for dst, src in pycompat.iteritems(copied) if dst in files |
9d2b2df2c2ba
cleanup: run pyupgrade on our source tree to clean up varying things
Augie Fackler <augie@google.com>
parents:
43643
diff
changeset
|
86 |
} |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
87 |
|
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
88 |
def filectxfn(repo, memctx, path, contentctx=ctx, redirect=()): |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
89 |
if path not in contentctx: |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
90 |
return None |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
91 |
fctx = contentctx[path] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
92 |
mctx = context.memfilectx( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
93 |
repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
94 |
memctx, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
95 |
fctx.path(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
96 |
fctx.data(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
97 |
fctx.islink(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
98 |
fctx.isexec(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
99 |
copysource=copied.get(path), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
100 |
) |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
101 |
return mctx |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
102 |
|
41745
83d294c71f1e
uncommit: inform user if the commit is empty after uncommit
Martin von Zweigbergk <martinvonz@google.com>
parents:
41397
diff
changeset
|
103 |
if not files: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
104 |
repo.ui.status(_(b"note: keeping empty commit\n")) |
41745
83d294c71f1e
uncommit: inform user if the commit is empty after uncommit
Martin von Zweigbergk <martinvonz@google.com>
parents:
41397
diff
changeset
|
105 |
|
42902
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
106 |
if message is None: |
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
107 |
message = ctx.description() |
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
108 |
if not user: |
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
109 |
user = ctx.user() |
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
110 |
if not date: |
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
111 |
date = ctx.date() |
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
112 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
113 |
new = context.memctx( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
114 |
repo, |
47012
d55b71393907
node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents:
46465
diff
changeset
|
115 |
parents=[base.node(), repo.nullid], |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
116 |
text=message, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
117 |
files=files, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
118 |
filectxfn=filectxfn, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
119 |
user=user, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
120 |
date=date, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
121 |
extra=ctx.extra(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
122 |
) |
38423
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
36974
diff
changeset
|
123 |
return repo.commitctx(new) |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
124 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
125 |
|
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
126 |
@command( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
127 |
b'uncommit', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
128 |
[ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
129 |
(b'', b'keep', None, _(b'allow an empty commit after uncommitting')), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
130 |
( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
131 |
b'', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
132 |
b'allow-dirty-working-copy', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
133 |
False, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
134 |
_(b'allow uncommit with outstanding changes'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
135 |
), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
136 |
(b'n', b'note', b'', _(b'store a note on uncommit'), _(b'TEXT')), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
137 |
] |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
138 |
+ commands.walkopts |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
139 |
+ commands.commitopts |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
140 |
+ commands.commitopts2 |
42903
66048f6b5d0d
uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42902
diff
changeset
|
141 |
+ commands.commitopts3, |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
142 |
_(b'[OPTION]... [FILE]...'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
143 |
helpcategory=command.CATEGORY_CHANGE_MANAGEMENT, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
144 |
) |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
145 |
def uncommit(ui, repo, *pats, **opts): |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
146 |
"""uncommit part or all of a local changeset |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
147 |
|
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
148 |
This command undoes the effect of a local commit, returning the affected |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
149 |
files to their uncommitted state. This means that files modified or |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
150 |
deleted in the changeset will be left unchanged, and so will remain |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
151 |
modified in the working directory. |
36973
d63c5c651183
uncommit: document when the commit will be pruned
Martin von Zweigbergk <martinvonz@google.com>
parents:
36972
diff
changeset
|
152 |
|
d63c5c651183
uncommit: document when the commit will be pruned
Martin von Zweigbergk <martinvonz@google.com>
parents:
36972
diff
changeset
|
153 |
If no files are specified, the commit will be pruned, unless --keep is |
d63c5c651183
uncommit: document when the commit will be pruned
Martin von Zweigbergk <martinvonz@google.com>
parents:
36972
diff
changeset
|
154 |
given. |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
155 |
""" |
47428
54849b65dc5f
cmdutil: make checknotesize() work on str-keyed opts
Martin von Zweigbergk <martinvonz@google.com>
parents:
47012
diff
changeset
|
156 |
cmdutil.check_note_size(opts) |
47432
7f7457f84311
cmdutil: make resolvecommitoptions() work on str-keyed opts
Martin von Zweigbergk <martinvonz@google.com>
parents:
47428
diff
changeset
|
157 |
cmdutil.resolve_commit_options(ui, opts) |
35004
3ebae3ec4664
py3: handle keyword arguments in hgext/uncommit.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34758
diff
changeset
|
158 |
opts = pycompat.byteskwargs(opts) |
42903
66048f6b5d0d
uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42902
diff
changeset
|
159 |
|
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
160 |
with repo.wlock(), repo.lock(): |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
161 |
|
43643
d0310f21ee9e
uncommit: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents:
43523
diff
changeset
|
162 |
st = repo.status() |
d0310f21ee9e
uncommit: use field names instead of field numbers on scmutil.status
Augie Fackler <augie@google.com>
parents:
43523
diff
changeset
|
163 |
m, a, r, d = st.modified, st.added, st.removed, st.deleted |
41859
bf22e370ae9a
uncommit: don't allow dirty working copy with PATH (issue5977)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
41750
diff
changeset
|
164 |
isdirtypath = any(set(m + a + r + d) & set(pats)) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
165 |
allowdirtywcopy = opts[ |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
166 |
b'allow_dirty_working_copy' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
167 |
] or repo.ui.configbool(b'experimental', b'uncommitondirtywdir') |
41860
aa284d9a33ca
uncommit: add flag --allow-dirty-working-copy
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
41859
diff
changeset
|
168 |
if not allowdirtywcopy and (not pats or isdirtypath): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
169 |
cmdutil.bailifchanged( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
170 |
repo, |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43105
diff
changeset
|
171 |
hint=_(b'requires --allow-dirty-working-copy to uncommit'), |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
172 |
) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
173 |
old = repo[b'.'] |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
174 |
rewriteutil.precheck(repo, [old.rev()], b'uncommit') |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
175 |
if len(old.parents()) > 1: |
46465
0e2becd1fe0c
errors: use InputError in uncommit extension
Martin von Zweigbergk <martinvonz@google.com>
parents:
46113
diff
changeset
|
176 |
raise error.InputError(_(b"cannot uncommit merge changeset")) |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
177 |
|
42051
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
178 |
match = scmutil.match(old, pats, opts) |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
179 |
|
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
180 |
# Check all explicitly given files; abort if there's a problem. |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
181 |
if match.files(): |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
182 |
s = old.status(old.p1(), match, listclean=True) |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
183 |
eligible = set(s.added) | set(s.modified) | set(s.removed) |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
184 |
|
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
185 |
badfiles = set(match.files()) - eligible |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
186 |
|
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
187 |
# Naming a parent directory of an eligible file is OK, even |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
188 |
# if not everything tracked in that directory can be |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
189 |
# uncommitted. |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
190 |
if badfiles: |
43523
c21aca51b392
utils: move the `dirs` definition in pathutil (API)
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
43117
diff
changeset
|
191 |
badfiles -= {f for f in pathutil.dirs(eligible)} |
42051
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
192 |
|
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
193 |
for f in sorted(badfiles): |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
194 |
if f in s.clean: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
195 |
hint = _( |
43117
8ff1ecfadcd1
cleanup: join string literals that are already on one line
Martin von Zweigbergk <martinvonz@google.com>
parents:
43105
diff
changeset
|
196 |
b"file was not changed in working directory parent" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
197 |
) |
42051
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
198 |
elif repo.wvfs.exists(f): |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
199 |
hint = _(b"file was untracked in working directory parent") |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
200 |
else: |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
201 |
hint = _(b"file does not exist") |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
202 |
|
46465
0e2becd1fe0c
errors: use InputError in uncommit extension
Martin von Zweigbergk <martinvonz@google.com>
parents:
46113
diff
changeset
|
203 |
raise error.InputError( |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
204 |
_(b'cannot uncommit "%s"') % scmutil.getuipathfn(repo)(f), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
205 |
hint=hint, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
206 |
) |
42051
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
207 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
208 |
with repo.transaction(b'uncommit'): |
42902
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
209 |
if not (opts[b'message'] or opts[b'logfile']): |
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
210 |
opts[b'message'] = old.description() |
42952
44be33cf7a57
py3: don't double-convert "opts" to bytes
Martin von Zweigbergk <martinvonz@google.com>
parents:
42936
diff
changeset
|
211 |
message = cmdutil.logmessage(ui, opts) |
42902
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
212 |
|
41750
1040d54eb7eb
uncommit: add config option to keep commit by default
Martin von Zweigbergk <martinvonz@google.com>
parents:
41745
diff
changeset
|
213 |
keepcommit = pats |
1040d54eb7eb
uncommit: add config option to keep commit by default
Martin von Zweigbergk <martinvonz@google.com>
parents:
41745
diff
changeset
|
214 |
if not keepcommit: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
215 |
if opts.get(b'keep') is not None: |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
216 |
keepcommit = opts.get(b'keep') |
41750
1040d54eb7eb
uncommit: add config option to keep commit by default
Martin von Zweigbergk <martinvonz@google.com>
parents:
41745
diff
changeset
|
217 |
else: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
218 |
keepcommit = ui.configbool( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
219 |
b'experimental', b'uncommit.keep' |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
220 |
) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
221 |
newid = _commitfiltered( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
222 |
repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
223 |
old, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
224 |
match, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
225 |
keepcommit, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
226 |
message=message, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
227 |
user=opts.get(b'user'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
228 |
date=opts.get(b'date'), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
229 |
) |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
230 |
if newid is None: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
231 |
ui.status(_(b"nothing to uncommit\n")) |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
232 |
return 1 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
233 |
|
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
234 |
mapping = {} |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
235 |
if newid != old.p1().node(): |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
236 |
# Move local changes on filtered changeset |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
237 |
mapping[old.node()] = (newid,) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
238 |
else: |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
239 |
# Fully removed the old commit |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
240 |
mapping[old.node()] = () |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
241 |
|
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
242 |
with repo.dirstate.parentchange(): |
41937
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41935
diff
changeset
|
243 |
scmutil.movedirstate(repo, repo[newid], match) |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
244 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
245 |
scmutil.cleanupnodes(repo, mapping, b'uncommit', fixphase=True) |
41340
c9f1fd82a826
uncommit: mark old node obsolete after updating dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
41339
diff
changeset
|
246 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
247 |
|
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
248 |
def predecessormarkers(ctx): |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
249 |
"""yields the obsolete markers marking the given changeset as a successor""" |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
250 |
for data in ctx.repo().obsstore.predecessors.get(ctx.node(), ()): |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
251 |
yield obsutil.marker(ctx.repo(), data) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
252 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
253 |
|
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
254 |
@command( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
255 |
b'unamend', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
256 |
[], |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
257 |
helpcategory=command.CATEGORY_CHANGE_MANAGEMENT, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
258 |
helpbasic=True, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
259 |
) |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
260 |
def unamend(ui, repo, **opts): |
35809
f9a82b9b2c36
unamend: fix command summary line
Martin von Zweigbergk <martinvonz@google.com>
parents:
35435
diff
changeset
|
261 |
"""undo the most recent amend operation on a current changeset |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
262 |
|
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
263 |
This command will roll back to the previous version of a changeset, |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
264 |
leaving working directory in state in which it was before running |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
265 |
`hg amend` (e.g. files modified as part of an amend will be |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
266 |
marked as modified `hg status`) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
267 |
""" |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
268 |
|
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
269 |
unfi = repo.unfiltered() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
270 |
with repo.wlock(), repo.lock(), repo.transaction(b'unamend'): |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
271 |
|
35200
9e339c97fabb
unamend: drop unused vars, query after taking lock, use ctx.hex() for extras
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35183
diff
changeset
|
272 |
# identify the commit from which to unamend |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
273 |
curctx = repo[b'.'] |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
274 |
|
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
275 |
rewriteutil.precheck(repo, [curctx.rev()], b'unamend') |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
276 |
|
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
277 |
# identify the commit to which to unamend |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
278 |
markers = list(predecessormarkers(curctx)) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
279 |
if len(markers) != 1: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
280 |
e = _(b"changeset must have one predecessor, found %i predecessors") |
46465
0e2becd1fe0c
errors: use InputError in uncommit extension
Martin von Zweigbergk <martinvonz@google.com>
parents:
46113
diff
changeset
|
281 |
raise error.InputError(e % len(markers)) |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
282 |
|
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
283 |
prednode = markers[0].prednode() |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
284 |
predctx = unfi[prednode] |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
285 |
|
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
286 |
# add an extra so that we get a new hash |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
287 |
# note: allowing unamend to undo an unamend is an intentional feature |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
288 |
extras = predctx.extra() |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
289 |
extras[b'unamend_source'] = curctx.hex() |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
290 |
|
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
291 |
def filectxfn(repo, ctx_, path): |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
292 |
try: |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
293 |
return predctx.filectx(path) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
294 |
except KeyError: |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
295 |
return None |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
296 |
|
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
297 |
# Make a new commit same as predctx |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
298 |
newctx = context.memctx( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
299 |
repo, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
300 |
parents=(predctx.p1(), predctx.p2()), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
301 |
text=predctx.description(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
302 |
files=predctx.files(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
303 |
filectxfn=filectxfn, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
304 |
user=predctx.user(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
305 |
date=predctx.date(), |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
306 |
extra=extras, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
42974
diff
changeset
|
307 |
) |
38423
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
36974
diff
changeset
|
308 |
newprednode = repo.commitctx(newctx) |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
309 |
newpredctx = repo[newprednode] |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
310 |
dirstate = repo.dirstate |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
311 |
|
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
312 |
with dirstate.parentchange(): |
41937
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41935
diff
changeset
|
313 |
scmutil.movedirstate(repo, newpredctx) |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
314 |
|
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
315 |
mapping = {curctx.node(): (newprednode,)} |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
316 |
scmutil.cleanupnodes(repo, mapping, b'unamend', fixphase=True) |