Mercurial > public > mercurial-scm > hg
annotate hgext/uncommit.py @ 42903:66048f6b5d0d
uncommit: add options to update to the current user or current date
These are also from the evolve extension's version of uncommit.
I tried adding validation that both forms of user or date can't be specified at
the same time, but that fails because these show up in `opts` with a None value
whether or not the option was given on the command line. Presumably that means
the conditional in `resolvecommitoptions` could be simplified. But this is how
both evolve and MQ handle it.
Differential Revision: https://phab.mercurial-scm.org/D6828
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sat, 07 Sep 2019 23:20:11 -0400 |
parents | ff1ff2aae132 |
children | 2da754532dd3 |
rev | line source |
---|---|
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, |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
30 node, |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
31 obsutil, |
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, |
42051
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
36 util, |
34192
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 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
39 cmdtable = {} |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
40 command = registrar.command(cmdtable) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
41 |
34758
9ea416a4b4f7
configitems: register the 'experimental.uncommitondirtywdir' config
Boris Feld <boris.feld@octobus.net>
parents:
34285
diff
changeset
|
42 configtable = {} |
9ea416a4b4f7
configitems: register the 'experimental.uncommitondirtywdir' config
Boris Feld <boris.feld@octobus.net>
parents:
34285
diff
changeset
|
43 configitem = registrar.configitem(configtable) |
9ea416a4b4f7
configitems: register the 'experimental.uncommitondirtywdir' config
Boris Feld <boris.feld@octobus.net>
parents:
34285
diff
changeset
|
44 |
9ea416a4b4f7
configitems: register the 'experimental.uncommitondirtywdir' config
Boris Feld <boris.feld@octobus.net>
parents:
34285
diff
changeset
|
45 configitem('experimental', 'uncommitondirtywdir', |
9ea416a4b4f7
configitems: register the 'experimental.uncommitondirtywdir' config
Boris Feld <boris.feld@octobus.net>
parents:
34285
diff
changeset
|
46 default=False, |
9ea416a4b4f7
configitems: register the 'experimental.uncommitondirtywdir' config
Boris Feld <boris.feld@octobus.net>
parents:
34285
diff
changeset
|
47 ) |
41750
1040d54eb7eb
uncommit: add config option to keep commit by default
Martin von Zweigbergk <martinvonz@google.com>
parents:
41745
diff
changeset
|
48 configitem('experimental', 'uncommit.keep', |
1040d54eb7eb
uncommit: add config option to keep commit by default
Martin von Zweigbergk <martinvonz@google.com>
parents:
41745
diff
changeset
|
49 default=False, |
1040d54eb7eb
uncommit: add config option to keep commit by default
Martin von Zweigbergk <martinvonz@google.com>
parents:
41745
diff
changeset
|
50 ) |
34758
9ea416a4b4f7
configitems: register the 'experimental.uncommitondirtywdir' config
Boris Feld <boris.feld@octobus.net>
parents:
34285
diff
changeset
|
51 |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
52 # 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
|
53 # 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
|
54 # 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
|
55 # leave the attribute unspecified. |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
56 testedwith = 'ships-with-hg-core' |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
57 |
42902
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
58 def _commitfiltered(repo, ctx, match, keepcommit, message=None, user=None, |
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
59 date=None): |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
60 """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
|
61 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
|
62 """ |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
63 base = ctx.p1() |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
64 # ctx |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
65 initialfiles = set(ctx.files()) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
66 exclude = set(f for f in initialfiles if match(f)) |
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 # 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
|
69 if not exclude: |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
70 return None |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
71 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
72 # 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
|
73 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
|
74 return ctx.p1().node() |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
75 |
41745
83d294c71f1e
uncommit: inform user if the commit is empty after uncommit
Martin von Zweigbergk <martinvonz@google.com>
parents:
41397
diff
changeset
|
76 files = (initialfiles - exclude) |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
77 # Filter copies |
41339
7be231f5a4ad
unamend: import "copies" module as "copiesmod" to avoid shadowing
Martin von Zweigbergk <martinvonz@google.com>
parents:
40295
diff
changeset
|
78 copied = copiesmod.pathcopies(base, ctx) |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
79 copied = dict((dst, src) for dst, src in copied.iteritems() |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
80 if dst in files) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
81 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
|
82 if path not in contentctx: |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
83 return None |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
84 fctx = contentctx[path] |
35400
8a0cac20a1ad
memfilectx: make changectx argument mandatory in constructor (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
35244
diff
changeset
|
85 mctx = context.memfilectx(repo, memctx, fctx.path(), fctx.data(), |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
86 fctx.islink(), |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
87 fctx.isexec(), |
41994
550a172a603b
memctx: rename constructor argument "copied" to "copysource" (API)
Martin von Zweigbergk <martinvonz@google.com>
parents:
41937
diff
changeset
|
88 copysource=copied.get(path)) |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
89 return mctx |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
90 |
41745
83d294c71f1e
uncommit: inform user if the commit is empty after uncommit
Martin von Zweigbergk <martinvonz@google.com>
parents:
41397
diff
changeset
|
91 if not files: |
83d294c71f1e
uncommit: inform user if the commit is empty after uncommit
Martin von Zweigbergk <martinvonz@google.com>
parents:
41397
diff
changeset
|
92 repo.ui.status(_("note: keeping empty commit\n")) |
83d294c71f1e
uncommit: inform user if the commit is empty after uncommit
Martin von Zweigbergk <martinvonz@google.com>
parents:
41397
diff
changeset
|
93 |
42902
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
94 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
|
95 message = ctx.description() |
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
96 if not user: |
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
97 user = ctx.user() |
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
98 if not date: |
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
99 date = ctx.date() |
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
100 |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
101 new = context.memctx(repo, |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
102 parents=[base.node(), node.nullid], |
42902
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
103 text=message, |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
104 files=files, |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
105 filectxfn=filectxfn, |
42902
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
106 user=user, |
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
107 date=date, |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
108 extra=ctx.extra()) |
38423
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
36974
diff
changeset
|
109 return repo.commitctx(new) |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
110 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
111 @command('uncommit', |
41750
1040d54eb7eb
uncommit: add config option to keep commit by default
Martin von Zweigbergk <martinvonz@google.com>
parents:
41745
diff
changeset
|
112 [('', 'keep', None, _('allow an empty commit after uncommiting')), |
41860
aa284d9a33ca
uncommit: add flag --allow-dirty-working-copy
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
41859
diff
changeset
|
113 ('', 'allow-dirty-working-copy', False, |
aa284d9a33ca
uncommit: add flag --allow-dirty-working-copy
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
41859
diff
changeset
|
114 _('allow uncommit with outstanding changes')) |
42903
66048f6b5d0d
uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42902
diff
changeset
|
115 ] + commands.walkopts + commands.commitopts + commands.commitopts2 |
66048f6b5d0d
uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42902
diff
changeset
|
116 + commands.commitopts3, |
40293
c303d65d2e34
help: assigning categories to existing commands
rdamazio@google.com
parents:
38771
diff
changeset
|
117 _('[OPTION]... [FILE]...'), |
c303d65d2e34
help: assigning categories to existing commands
rdamazio@google.com
parents:
38771
diff
changeset
|
118 helpcategory=command.CATEGORY_CHANGE_MANAGEMENT) |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
119 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
|
120 """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
|
121 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
122 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
|
123 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
|
124 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
|
125 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
|
126 |
d63c5c651183
uncommit: document when the commit will be pruned
Martin von Zweigbergk <martinvonz@google.com>
parents:
36972
diff
changeset
|
127 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
|
128 given. |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
129 """ |
35004
3ebae3ec4664
py3: handle keyword arguments in hgext/uncommit.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34758
diff
changeset
|
130 opts = pycompat.byteskwargs(opts) |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
131 |
42903
66048f6b5d0d
uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42902
diff
changeset
|
132 cmdutil.resolvecommitoptions(ui, opts) |
66048f6b5d0d
uncommit: add options to update to the current user or current date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42902
diff
changeset
|
133 |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
134 with repo.wlock(), repo.lock(): |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
135 |
41859
bf22e370ae9a
uncommit: don't allow dirty working copy with PATH (issue5977)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
41750
diff
changeset
|
136 m, a, r, d = repo.status()[:4] |
bf22e370ae9a
uncommit: don't allow dirty working copy with PATH (issue5977)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
41750
diff
changeset
|
137 isdirtypath = any(set(m + a + r + d) & set(pats)) |
41860
aa284d9a33ca
uncommit: add flag --allow-dirty-working-copy
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
41859
diff
changeset
|
138 allowdirtywcopy = (opts['allow_dirty_working_copy'] or |
aa284d9a33ca
uncommit: add flag --allow-dirty-working-copy
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
41859
diff
changeset
|
139 repo.ui.configbool('experimental', 'uncommitondirtywdir')) |
aa284d9a33ca
uncommit: add flag --allow-dirty-working-copy
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
41859
diff
changeset
|
140 if not allowdirtywcopy and (not pats or isdirtypath): |
41859
bf22e370ae9a
uncommit: don't allow dirty working copy with PATH (issue5977)
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
41750
diff
changeset
|
141 cmdutil.bailifchanged(repo, hint=_('requires ' |
41860
aa284d9a33ca
uncommit: add flag --allow-dirty-working-copy
Navaneeth Suresh <navaneeths1998@gmail.com>
parents:
41859
diff
changeset
|
142 '--allow-dirty-working-copy to uncommit')) |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
143 old = repo['.'] |
35244
98f97eb20597
rewriteutil: use precheck() in uncommit and amend commands
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35200
diff
changeset
|
144 rewriteutil.precheck(repo, [old.rev()], 'uncommit') |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
145 if len(old.parents()) > 1: |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
146 raise error.Abort(_("cannot uncommit merge changeset")) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
147 |
42051
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
148 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
|
149 |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
150 # 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
|
151 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
|
152 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
|
153 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
|
154 |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
155 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
|
156 |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
157 # 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
|
158 # 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
|
159 # uncommitted. |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
160 if badfiles: |
42057
566daffc607d
cleanup: use set literals where possible
Martin von Zweigbergk <martinvonz@google.com>
parents:
42051
diff
changeset
|
161 badfiles -= {f for f in util.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
|
162 |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
163 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
|
164 if f in s.clean: |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
165 hint = _(b"file was not changed in working directory " |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
166 b"parent") |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
167 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
|
168 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
|
169 else: |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
170 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
|
171 |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
172 raise error.Abort(_(b'cannot uncommit "%s"') |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
173 % scmutil.getuipathfn(repo)(f), hint=hint) |
f4147ca63d39
uncommit: abort if an explicitly given file cannot be uncommitted (BC)
Matt Harbison <matt_harbison@yahoo.com>
parents:
41994
diff
changeset
|
174 |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
175 with repo.transaction('uncommit'): |
42902
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
176 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
|
177 opts[b'message'] = old.description() |
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
178 message = cmdutil.logmessage(ui, pycompat.byteskwargs(opts)) |
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
179 |
41750
1040d54eb7eb
uncommit: add config option to keep commit by default
Martin von Zweigbergk <martinvonz@google.com>
parents:
41745
diff
changeset
|
180 keepcommit = pats |
1040d54eb7eb
uncommit: add config option to keep commit by default
Martin von Zweigbergk <martinvonz@google.com>
parents:
41745
diff
changeset
|
181 if not keepcommit: |
1040d54eb7eb
uncommit: add config option to keep commit by default
Martin von Zweigbergk <martinvonz@google.com>
parents:
41745
diff
changeset
|
182 if opts.get('keep') is not None: |
1040d54eb7eb
uncommit: add config option to keep commit by default
Martin von Zweigbergk <martinvonz@google.com>
parents:
41745
diff
changeset
|
183 keepcommit = opts.get('keep') |
1040d54eb7eb
uncommit: add config option to keep commit by default
Martin von Zweigbergk <martinvonz@google.com>
parents:
41745
diff
changeset
|
184 else: |
1040d54eb7eb
uncommit: add config option to keep commit by default
Martin von Zweigbergk <martinvonz@google.com>
parents:
41745
diff
changeset
|
185 keepcommit = ui.configbool('experimental', 'uncommit.keep') |
42902
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
186 newid = _commitfiltered(repo, old, match, keepcommit, |
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
187 message=message, user=opts.get(b'user'), |
ff1ff2aae132
uncommit: add support to modify the commit message and date
Matt Harbison <matt_harbison@yahoo.com>
parents:
42057
diff
changeset
|
188 date=opts.get(b'date')) |
34192
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
189 if newid is None: |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
190 ui.status(_("nothing to uncommit\n")) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
191 return 1 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
192 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
193 mapping = {} |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
194 if newid != old.p1().node(): |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
195 # 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
|
196 mapping[old.node()] = (newid,) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
197 else: |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
198 # Fully removed the old commit |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
199 mapping[old.node()] = () |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
200 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
201 with repo.dirstate.parentchange(): |
41937
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41935
diff
changeset
|
202 scmutil.movedirstate(repo, repo[newid], match) |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
203 |
41340
c9f1fd82a826
uncommit: mark old node obsolete after updating dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
41339
diff
changeset
|
204 scmutil.cleanupnodes(repo, mapping, 'uncommit', fixphase=True) |
c9f1fd82a826
uncommit: mark old node obsolete after updating dirstate
Martin von Zweigbergk <martinvonz@google.com>
parents:
41339
diff
changeset
|
205 |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
206 def predecessormarkers(ctx): |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
207 """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
|
208 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
|
209 yield obsutil.marker(ctx.repo(), data) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
210 |
40295
fa88170c10bb
help: adding a proper declaration for shortlist/basic commands (API)
Rodrigo Damazio <rdamazio@google.com>
parents:
40293
diff
changeset
|
211 @command('unamend', [], helpcategory=command.CATEGORY_CHANGE_MANAGEMENT, |
fa88170c10bb
help: adding a proper declaration for shortlist/basic commands (API)
Rodrigo Damazio <rdamazio@google.com>
parents:
40293
diff
changeset
|
212 helpbasic=True) |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
213 def unamend(ui, repo, **opts): |
35809
f9a82b9b2c36
unamend: fix command summary line
Martin von Zweigbergk <martinvonz@google.com>
parents:
35435
diff
changeset
|
214 """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
|
215 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
216 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
|
217 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
|
218 `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
|
219 marked as modified `hg status`) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
220 """ |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
221 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
222 unfi = repo.unfiltered() |
35200
9e339c97fabb
unamend: drop unused vars, query after taking lock, use ctx.hex() for extras
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35183
diff
changeset
|
223 with repo.wlock(), repo.lock(), repo.transaction('unamend'): |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
224 |
35200
9e339c97fabb
unamend: drop unused vars, query after taking lock, use ctx.hex() for extras
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35183
diff
changeset
|
225 # identify the commit from which to unamend |
9e339c97fabb
unamend: drop unused vars, query after taking lock, use ctx.hex() for extras
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35183
diff
changeset
|
226 curctx = repo['.'] |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
227 |
35435
f01101100043
unamend: allow unamending if allowunstable is set
Martin von Zweigbergk <martinvonz@google.com>
parents:
35400
diff
changeset
|
228 rewriteutil.precheck(repo, [curctx.rev()], 'unamend') |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
229 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
230 # identify the commit to which to unamend |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
231 markers = list(predecessormarkers(curctx)) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
232 if len(markers) != 1: |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
233 e = _("changeset must have one predecessor, found %i predecessors") |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
234 raise error.Abort(e % len(markers)) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
235 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
236 prednode = markers[0].prednode() |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
237 predctx = unfi[prednode] |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
238 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
239 # 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
|
240 # 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
|
241 extras = predctx.extra() |
35200
9e339c97fabb
unamend: drop unused vars, query after taking lock, use ctx.hex() for extras
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35183
diff
changeset
|
242 extras['unamend_source'] = curctx.hex() |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
243 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
244 def filectxfn(repo, ctx_, path): |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
245 try: |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
246 return predctx.filectx(path) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
247 except KeyError: |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
248 return None |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
249 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
250 # Make a new commit same as predctx |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
251 newctx = context.memctx(repo, |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
252 parents=(predctx.p1(), predctx.p2()), |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
253 text=predctx.description(), |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
254 files=predctx.files(), |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
255 filectxfn=filectxfn, |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
256 user=predctx.user(), |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
257 date=predctx.date(), |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
258 extra=extras) |
38423
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
36974
diff
changeset
|
259 newprednode = repo.commitctx(newctx) |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
260 newpredctx = repo[newprednode] |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
261 dirstate = repo.dirstate |
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 with dirstate.parentchange(): |
41937
232d4b9d391a
uncommit: move _movedirstate() to scmutil for reuse
Martin von Zweigbergk <martinvonz@google.com>
parents:
41935
diff
changeset
|
264 scmutil.movedirstate(repo, newpredctx) |
35182
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
265 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35004
diff
changeset
|
266 mapping = {curctx.node(): (newprednode,)} |
38423
32fba6fe893d
scmutil: make cleanupnodes optionally also fix the phase
Martin von Zweigbergk <martinvonz@google.com>
parents:
36974
diff
changeset
|
267 scmutil.cleanupnodes(repo, mapping, 'unamend', fixphase=True) |