Mercurial > hg-stable
annotate hgext/uncommit.py @ 35193:867990238dc6
unamend: move fb extension unamend to core
unamend extension adds an unamend command which undoes the effect of the amend
command. This patch moves the unamend command from that extension to uncommit
extension and this one does not completely undoes the effect of amend command as
it creates a new commit, rather than reviving the old one back.
This also adds tests for the same.
.. feature::
A new unamend command in uncommit extension which undoes the effect of the
amend command by creating a new changeset which was there before amend and
moving the changes that were amended to the working directory.
Differential Revision: https://phab.mercurial-scm.org/D821
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Sun, 24 Sep 2017 00:56:52 +0530 |
parents | 3ebae3ec4664 |
children | 9dadcb99cc17 |
rev | line source |
---|---|
34204
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 ( |
34291
624c53e4121d
uncommit: don't allow bare uncommit on dirty working directory
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34290
diff
changeset
|
25 cmdutil, |
34204
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, |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
28 copies, |
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, |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
31 obsolete, |
35193
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
32 obsutil, |
35045
3ebae3ec4664
py3: handle keyword arguments in hgext/uncommit.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34758
diff
changeset
|
33 pycompat, |
34204
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
34 registrar, |
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:
34292
diff
changeset
|
41 configtable = {} |
9ea416a4b4f7
configitems: register the 'experimental.uncommitondirtywdir' config
Boris Feld <boris.feld@octobus.net>
parents:
34292
diff
changeset
|
42 configitem = registrar.configitem(configtable) |
9ea416a4b4f7
configitems: register the 'experimental.uncommitondirtywdir' config
Boris Feld <boris.feld@octobus.net>
parents:
34292
diff
changeset
|
43 |
9ea416a4b4f7
configitems: register the 'experimental.uncommitondirtywdir' config
Boris Feld <boris.feld@octobus.net>
parents:
34292
diff
changeset
|
44 configitem('experimental', 'uncommitondirtywdir', |
9ea416a4b4f7
configitems: register the 'experimental.uncommitondirtywdir' config
Boris Feld <boris.feld@octobus.net>
parents:
34292
diff
changeset
|
45 default=False, |
9ea416a4b4f7
configitems: register the 'experimental.uncommitondirtywdir' config
Boris Feld <boris.feld@octobus.net>
parents:
34292
diff
changeset
|
46 ) |
9ea416a4b4f7
configitems: register the 'experimental.uncommitondirtywdir' config
Boris Feld <boris.feld@octobus.net>
parents:
34292
diff
changeset
|
47 |
34204
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
48 # 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
|
49 # 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
|
50 # 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
|
51 # leave the attribute unspecified. |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
52 testedwith = 'ships-with-hg-core' |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
53 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
54 def _commitfiltered(repo, ctx, match, allowempty): |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
55 """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
|
56 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
|
57 """ |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
58 base = ctx.p1() |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
59 # ctx |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
60 initialfiles = set(ctx.files()) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
61 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
|
62 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
63 # 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
|
64 if not exclude: |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
65 return None |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
66 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
67 files = (initialfiles - exclude) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
68 # return the p1 so that we don't create an obsmarker later |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
69 if not files and not allowempty: |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
70 return ctx.parents()[0].node() |
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 # Filter copies |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
73 copied = copies.pathcopies(base, ctx) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
74 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
|
75 if dst in files) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
76 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
|
77 if path not in contentctx: |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
78 return None |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
79 fctx = contentctx[path] |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
80 mctx = context.memfilectx(repo, fctx.path(), fctx.data(), |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
81 fctx.islink(), |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
82 fctx.isexec(), |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
83 copied=copied.get(path)) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
84 return mctx |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
85 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
86 new = context.memctx(repo, |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
87 parents=[base.node(), node.nullid], |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
88 text=ctx.description(), |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
89 files=files, |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
90 filectxfn=filectxfn, |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
91 user=ctx.user(), |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
92 date=ctx.date(), |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
93 extra=ctx.extra()) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
94 # phase handling |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
95 commitphase = ctx.phase() |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
96 overrides = {('phases', 'new-commit'): commitphase} |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
97 with repo.ui.configoverride(overrides, 'uncommit'): |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
98 newid = repo.commitctx(new) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
99 return newid |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
100 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
101 def _uncommitdirstate(repo, oldctx, match): |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
102 """Fix the dirstate after switching the working directory from |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
103 oldctx to a copy of oldctx not containing changed files matched by |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
104 match. |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
105 """ |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
106 ctx = repo['.'] |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
107 ds = repo.dirstate |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
108 copies = dict(ds.copies()) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
109 s = repo.status(oldctx.p1(), oldctx, match=match) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
110 for f in s.modified: |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
111 if ds[f] == 'r': |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
112 # modified + removed -> removed |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
113 continue |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
114 ds.normallookup(f) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
115 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
116 for f in s.added: |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
117 if ds[f] == 'r': |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
118 # added + removed -> unknown |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
119 ds.drop(f) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
120 elif ds[f] != 'a': |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
121 ds.add(f) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
122 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
123 for f in s.removed: |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
124 if ds[f] == 'a': |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
125 # removed + added -> normal |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
126 ds.normallookup(f) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
127 elif ds[f] != 'r': |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
128 ds.remove(f) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
129 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
130 # Merge old parent and old working dir copies |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
131 oldcopies = {} |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
132 for f in (s.modified + s.added): |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
133 src = oldctx[f].renamed() |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
134 if src: |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
135 oldcopies[f] = src[0] |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
136 oldcopies.update(copies) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
137 copies = dict((dst, oldcopies.get(src, src)) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
138 for dst, src in oldcopies.iteritems()) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
139 # Adjust the dirstate copies |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
140 for dst, src in copies.iteritems(): |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
141 if (src not in ctx or dst in ctx or ds[dst] != 'a'): |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
142 src = None |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
143 ds.copy(src, dst) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
144 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
145 @command('uncommit', |
34290
f94442d46984
uncommit: rename the flag 'empty' to 'keep' which retains empty changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34204
diff
changeset
|
146 [('', 'keep', False, _('allow an empty commit after uncommiting')), |
34204
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
147 ] + commands.walkopts, |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
148 _('[OPTION]... [FILE]...')) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
149 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
|
150 """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
|
151 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
152 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
|
153 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
|
154 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
|
155 modified in the working directory. |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
156 """ |
35045
3ebae3ec4664
py3: handle keyword arguments in hgext/uncommit.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34758
diff
changeset
|
157 opts = pycompat.byteskwargs(opts) |
34204
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
158 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
159 with repo.wlock(), repo.lock(): |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
160 wctx = repo[None] |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
161 |
34292
7b1e524ad73f
uncommit: add an experimental.uncommitondirtywdir config
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34291
diff
changeset
|
162 if not pats and not repo.ui.configbool('experimental', |
34758
9ea416a4b4f7
configitems: register the 'experimental.uncommitondirtywdir' config
Boris Feld <boris.feld@octobus.net>
parents:
34292
diff
changeset
|
163 'uncommitondirtywdir'): |
34291
624c53e4121d
uncommit: don't allow bare uncommit on dirty working directory
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34290
diff
changeset
|
164 cmdutil.bailifchanged(repo) |
34204
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
165 if wctx.parents()[0].node() == node.nullid: |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
166 raise error.Abort(_("cannot uncommit null changeset")) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
167 if len(wctx.parents()) > 1: |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
168 raise error.Abort(_("cannot uncommit while merging")) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
169 old = repo['.'] |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
170 if not old.mutable(): |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
171 raise error.Abort(_('cannot uncommit public changesets')) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
172 if len(old.parents()) > 1: |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
173 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
|
174 allowunstable = obsolete.isenabled(repo, obsolete.allowunstableopt) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
175 if not allowunstable and old.children(): |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
176 raise error.Abort(_('cannot uncommit changeset with children')) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
177 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
178 with repo.transaction('uncommit'): |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
179 match = scmutil.match(old, pats, opts) |
34290
f94442d46984
uncommit: rename the flag 'empty' to 'keep' which retains empty changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
34204
diff
changeset
|
180 newid = _commitfiltered(repo, old, match, opts.get('keep')) |
34204
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
181 if newid is None: |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
182 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
|
183 return 1 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
184 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
185 mapping = {} |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
186 if newid != old.p1().node(): |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
187 # 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
|
188 mapping[old.node()] = (newid,) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
189 else: |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
190 # Fully removed the old commit |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
191 mapping[old.node()] = () |
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 scmutil.cleanupnodes(repo, mapping, 'uncommit') |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
194 |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
195 with repo.dirstate.parentchange(): |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
196 repo.dirstate.setparents(newid, node.nullid) |
da2f5f19312c
uncommit: move fb-extension to core which uncommits a changeset
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
197 _uncommitdirstate(repo, old, match) |
35193
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
198 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
199 def predecessormarkers(ctx): |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
200 """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:
35045
diff
changeset
|
201 for data in ctx.repo().obsstore.predecessors.get(ctx.node(), ()): |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
202 yield obsutil.marker(ctx.repo(), data) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
203 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
204 def _unamenddirstate(repo, predctx, curctx): |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
205 """""" |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
206 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
207 s = repo.status(predctx, curctx) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
208 ds = repo.dirstate |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
209 copies = dict(ds.copies()) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
210 for f in s.modified: |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
211 if ds[f] == 'r': |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
212 # modified + removed -> removed |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
213 continue |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
214 ds.normallookup(f) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
215 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
216 for f in s.added: |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
217 if ds[f] == 'r': |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
218 # added + removed -> unknown |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
219 ds.drop(f) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
220 elif ds[f] != 'a': |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
221 ds.add(f) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
222 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
223 for f in s.removed: |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
224 if ds[f] == 'a': |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
225 # removed + added -> normal |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
226 ds.normallookup(f) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
227 elif ds[f] != 'r': |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
228 ds.remove(f) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
229 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
230 # Merge old parent and old working dir copies |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
231 oldcopies = {} |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
232 for f in (s.modified + s.added): |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
233 src = curctx[f].renamed() |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
234 if src: |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
235 oldcopies[f] = src[0] |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
236 oldcopies.update(copies) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
237 copies = dict((dst, oldcopies.get(src, src)) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
238 for dst, src in oldcopies.iteritems()) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
239 # Adjust the dirstate copies |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
240 for dst, src in copies.iteritems(): |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
241 if (src not in predctx or dst in predctx or ds[dst] != 'a'): |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
242 src = None |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
243 ds.copy(src, dst) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
244 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
245 @command('^unamend', []) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
246 def unamend(ui, repo, **opts): |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
247 """ |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
248 undo the most recent amend operation on a current changeset |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
249 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
250 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:
35045
diff
changeset
|
251 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:
35045
diff
changeset
|
252 `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:
35045
diff
changeset
|
253 marked as modified `hg status`) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
254 """ |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
255 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
256 unfi = repo.unfiltered() |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
257 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
258 # identify the commit from which to unamend |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
259 curctx = repo['.'] |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
260 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
261 with repo.wlock(), repo.lock(), repo.transaction('unamend'): |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
262 if not curctx.mutable(): |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
263 raise error.Abort(_('cannot unamend public changesets')) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
264 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
265 # identify the commit to which to unamend |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
266 markers = list(predecessormarkers(curctx)) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
267 if len(markers) != 1: |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
268 e = _("changeset must have one predecessor, found %i predecessors") |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
269 raise error.Abort(e % len(markers)) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
270 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
271 prednode = markers[0].prednode() |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
272 predctx = unfi[prednode] |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
273 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
274 if curctx.children(): |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
275 raise error.Abort(_("cannot unamend a changeset with children")) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
276 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
277 # add an extra so that we get a new hash |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
278 # 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:
35045
diff
changeset
|
279 extras = predctx.extra() |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
280 extras['unamend_source'] = curctx.node() |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
281 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
282 def filectxfn(repo, ctx_, path): |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
283 try: |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
284 return predctx.filectx(path) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
285 except KeyError: |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
286 return None |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
287 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
288 # Make a new commit same as predctx |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
289 newctx = context.memctx(repo, |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
290 parents=(predctx.p1(), predctx.p2()), |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
291 text=predctx.description(), |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
292 files=predctx.files(), |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
293 filectxfn=filectxfn, |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
294 user=predctx.user(), |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
295 date=predctx.date(), |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
296 extra=extras) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
297 # phase handling |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
298 commitphase = curctx.phase() |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
299 overrides = {('phases', 'new-commit'): commitphase} |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
300 with repo.ui.configoverride(overrides, 'uncommit'): |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
301 newprednode = repo.commitctx(newctx) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
302 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
303 newpredctx = repo[newprednode] |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
304 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
305 changedfiles = [] |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
306 wctx = repo[None] |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
307 wm = wctx.manifest() |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
308 cm = newpredctx.manifest() |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
309 dirstate = repo.dirstate |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
310 diff = cm.diff(wm) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
311 changedfiles.extend(diff.iterkeys()) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
312 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
313 with dirstate.parentchange(): |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
314 dirstate.setparents(newprednode, node.nullid) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
315 _unamenddirstate(repo, newpredctx, curctx) |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
316 |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
317 mapping = {curctx.node(): (newprednode,)} |
867990238dc6
unamend: move fb extension unamend to core
Pulkit Goyal <7895pulkit@gmail.com>
parents:
35045
diff
changeset
|
318 scmutil.cleanupnodes(repo, mapping, 'unamend') |