author | Pierre-Yves David <pierre-yves.david@logilab.fr> |
Mon, 19 Dec 2011 12:18:04 +0100 | |
changeset 108 | 85271a8a7fb9 |
parent 104 | 6c3c7a18f079 |
child 113 | 3bdabdbb4140 |
permissions | -rw-r--r-- |
81
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
1 |
# states.py - introduce the state concept for mercurial changeset |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
2 |
# |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
3 |
# Copyright 2011 Peter Arrenbrecht <peter.arrenbrecht@gmail.com> |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
4 |
# Logilab SA <contact@logilab.fr> |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
5 |
# Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
6 |
# |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
7 |
# This software may be used and distributed according to the terms of the |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
8 |
# GNU General Public License version 2 or any later version. |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
9 |
|
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
10 |
'''A set of command to make changeset evolve.''' |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
11 |
|
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
12 |
from mercurial import cmdutil |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
13 |
from mercurial import scmutil |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
14 |
from mercurial import node |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
15 |
from mercurial import error |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
16 |
from mercurial import extensions |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
17 |
from mercurial import commands |
82
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
18 |
from mercurial import bookmarks |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
19 |
from mercurial import context |
88
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
20 |
from mercurial import util |
81
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
21 |
from mercurial.i18n import _ |
82
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
22 |
from mercurial.commands import walkopts, commitopts, commitopts2, logopts |
81
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
23 |
|
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
24 |
### util function |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
25 |
############################# |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
26 |
def noderange(repo, revsets): |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
27 |
"""The same as revrange but return node""" |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
28 |
return map(repo.changelog.node, |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
29 |
scmutil.revrange(repo, revsets)) |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
30 |
|
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
31 |
### extension check |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
32 |
############################# |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
33 |
|
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
34 |
def extsetup(ui): |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
35 |
try: |
87
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
36 |
obsolete = extensions.find('obsolete') |
81
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
37 |
except KeyError: |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
38 |
raise error.Abort(_('evolution extension require obsolete extension.')) |
87
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
39 |
try: |
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
40 |
rebase = extensions.find('rebase') |
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
41 |
except KeyError: |
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
42 |
raise error.Abort(_('evolution extension require rebase extension.')) |
81
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
43 |
|
82
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
44 |
### changeset rewriting logic |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
45 |
############################# |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
46 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
47 |
def rewrite(repo, old, updates, head, newbases, commitopts): |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
48 |
if len(old.parents()) > 1: #XXX remove this unecessary limitation. |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
49 |
raise error.Abort(_('cannot amend merge changesets')) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
50 |
base = old.p1() |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
51 |
bm = bookmarks.readcurrent(repo) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
52 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
53 |
wlock = repo.wlock() |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
54 |
try: |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
55 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
56 |
# commit a new version of the old changeset, including the update |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
57 |
# collect all files which might be affected |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
58 |
files = set(old.files()) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
59 |
for u in updates: |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
60 |
files.update(u.files()) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
61 |
# prune files which were reverted by the updates |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
62 |
def samefile(f): |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
63 |
if f in head.manifest(): |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
64 |
a = head.filectx(f) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
65 |
if f in base.manifest(): |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
66 |
b = base.filectx(f) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
67 |
return (a.data() == b.data() |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
68 |
and a.flags() == b.flags() |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
69 |
and a.renamed() == b.renamed()) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
70 |
else: |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
71 |
return False |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
72 |
else: |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
73 |
return f not in base.manifest() |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
74 |
files = [f for f in files if not samefile(f)] |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
75 |
# commit version of these files as defined by head |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
76 |
headmf = head.manifest() |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
77 |
def filectxfn(repo, ctx, path): |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
78 |
if path in headmf: |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
79 |
return head.filectx(path) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
80 |
raise IOError() |
104
6c3c7a18f079
propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
103
diff
changeset
|
81 |
if commitopts.get('message') and commitopts.get('logfile'): |
6c3c7a18f079
propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
103
diff
changeset
|
82 |
raise util.Abort(_('options --message and --logfile are mutually' |
6c3c7a18f079
propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
103
diff
changeset
|
83 |
' exclusive')) |
6c3c7a18f079
propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
103
diff
changeset
|
84 |
if commitopts.get('logfile'): |
6c3c7a18f079
propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
103
diff
changeset
|
85 |
message= open(commitopts['logfile']).read() |
6c3c7a18f079
propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
103
diff
changeset
|
86 |
elif commitopts.get('message'): |
6c3c7a18f079
propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
103
diff
changeset
|
87 |
message = commitopts['message'] |
6c3c7a18f079
propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
103
diff
changeset
|
88 |
else: |
6c3c7a18f079
propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
103
diff
changeset
|
89 |
message = old.description() |
6c3c7a18f079
propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
103
diff
changeset
|
90 |
|
82
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
91 |
new = context.memctx(repo, |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
92 |
parents=newbases, |
104
6c3c7a18f079
propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
103
diff
changeset
|
93 |
text=message, |
82
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
94 |
files=files, |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
95 |
filectxfn=filectxfn, |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
96 |
user=commitopts.get('user') or None, |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
97 |
date=commitopts.get('date') or None, |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
98 |
extra=commitopts.get('extra') or None) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
99 |
newid = repo.commitctx(new) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
100 |
new = repo[newid] |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
101 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
102 |
# update the bookmark |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
103 |
if bm: |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
104 |
repo._bookmarks[bm] = newid |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
105 |
bookmarks.write(repo) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
106 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
107 |
# hide obsolete csets |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
108 |
repo.changelog.hiddeninit = False |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
109 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
110 |
# add evolution metadata |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
111 |
repo.addobsolete(new.node(), old.node()) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
112 |
for u in updates: |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
113 |
repo.addobsolete(u.node(), old.node()) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
114 |
repo.addobsolete(new.node(), u.node()) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
115 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
116 |
finally: |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
117 |
wlock.release() |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
118 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
119 |
return newid |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
120 |
|
88
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
121 |
def relocate(repo, rev, dest): |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
122 |
"""rewrite <rev> on dest""" |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
123 |
try: |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
124 |
rebase = extensions.find('rebase') |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
125 |
# dummy state to trick rebase node |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
126 |
assert repo[rev].p2().rev() == node.nullrev, 'no support yet' |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
127 |
rebase.updatedirstate(repo, rev, repo[dest].node(), |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
128 |
repo[rev].p2().node()) |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
129 |
rebase.rebasenode(repo, rev, dest, {node.nullrev: node.nullrev}) |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
130 |
nodenew = rebase.concludenode(repo, rev, dest, node.nullid) |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
131 |
nodesrc = repo.changelog.node(rev) |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
132 |
repo.addobsolete(nodenew, nodesrc) |
108
85271a8a7fb9
Properly inherit phase of relocated changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
104
diff
changeset
|
133 |
repo.setstate(repo.nodestate(nodesrc), [nodenew]) |
88
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
134 |
oldbookmarks = repo.nodebookmarks(nodesrc) |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
135 |
for book in oldbookmarks: |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
136 |
repo._bookmarks[book] = nodenew |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
137 |
if oldbookmarks: |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
138 |
bookmarks.write(repo) |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
139 |
except util.Abort: |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
140 |
# Invalidate the previous setparents |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
141 |
repo.dirstate.invalidate() |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
142 |
raise |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
143 |
|
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
144 |
|
82
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
145 |
|
81
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
146 |
### new command |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
147 |
############################# |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
148 |
cmdtable = {} |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
149 |
command = cmdutil.command(cmdtable) |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
150 |
|
87
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
151 |
@command('^evolve', |
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
152 |
[], |
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
153 |
'') |
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
154 |
def evolve(ui, repo): |
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
155 |
"""suggest the next evolution step""" |
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
156 |
obsolete = extensions.find('obsolete') |
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
157 |
next = min(obsolete.unstables(repo)) |
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
158 |
obs = repo[next].parents()[0] |
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
159 |
if not obs.obsolete(): |
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
160 |
obs = next.parents()[1] |
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
161 |
assert obs.obsolete() |
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
162 |
newer = obsolete.newerversion(repo, obs.node()) |
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
163 |
target = newer[-1] |
94
780a222d547d
[evolution:evolve] use short hex instead of rev number
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
92
diff
changeset
|
164 |
repo.ui.status('hg relocate --rev %s %s\n' % (repo[next], repo[target])) |
88
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
165 |
|
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
166 |
@command('^relocate', |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
167 |
[ |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
168 |
('r', 'rev', '.', |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
169 |
_('revision to relocate')), |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
170 |
], |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
171 |
'') |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
172 |
def cmdrelocate(ui, repo, dest, rev='.'): |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
173 |
"""relocate a changeset""" |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
174 |
wlock = repo.wlock() |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
175 |
try: |
91
5b8d08c78854
[evolution:relocate] propertly interpred src and destination.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
88
diff
changeset
|
176 |
src = scmutil.revsingle(repo, rev, rev) |
5b8d08c78854
[evolution:relocate] propertly interpred src and destination.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
88
diff
changeset
|
177 |
dest = scmutil.revsingle(repo, dest, dest) |
88
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
178 |
if src == src.ancestor(dest): |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
179 |
raise util.Abort(_('source is ancestor of destination')) |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
180 |
relocate(repo, src.rev(), dest.rev()) |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
181 |
return 0 |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
182 |
finally: |
64fe5a4f877e
[evolution] first workign draft of a relocate function
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
87
diff
changeset
|
183 |
wlock.release() |
87
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
184 |
|
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
185 |
|
246b8fefd0a5
[evolution/obsolete] very experimental and crude evolve support.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
82
diff
changeset
|
186 |
|
81
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
187 |
@command('^kill', |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
188 |
[], |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
189 |
'<revs>') |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
190 |
def kill(ui, repo, *revs): |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
191 |
"""mark a changeset as obsolete |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
192 |
|
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
193 |
This update the parent directory to a not-killed parent if the current |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
194 |
working directory parent are killed. |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
195 |
|
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
196 |
XXX bookmark support |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
197 |
XXX handle merge |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
198 |
XXX check immutable first |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
199 |
""" |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
200 |
wlock = repo.wlock() |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
201 |
try: |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
202 |
targetnodes = set(noderange(repo, revs)) |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
203 |
for n in targetnodes: |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
204 |
repo.addobsolete(node.nullid, n) |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
205 |
# update to an unkilled parent |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
206 |
wdp = repo['.'] |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
207 |
newnode = wdp |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
208 |
while newnode.obsolete(): |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
209 |
newnode = newnode.parents()[0] |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
210 |
if newnode.node() != wdp.node(): |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
211 |
commands.update(ui, repo, newnode.rev()) |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
212 |
ui.status(_('working directory now at %s\n') % newnode) |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
213 |
|
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
214 |
finally: |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
215 |
wlock.release() |
5cec25ce019c
Basic kill command
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
216 |
|
82
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
217 |
@command('^amend', |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
218 |
[('A', 'addremove', None, |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
219 |
_('mark new/missing files as added/removed before committing')), |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
220 |
('n', 'note', '', |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
221 |
_('use text as commit message for this update')), |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
222 |
('c', 'change', '', |
103
23c232a81fbe
amend: add a --branch option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
94
diff
changeset
|
223 |
_('specifies the changeset to amend'), _('REV')), |
23c232a81fbe
amend: add a --branch option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
94
diff
changeset
|
224 |
('b', 'branch', '', |
23c232a81fbe
amend: add a --branch option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
94
diff
changeset
|
225 |
_('specifies a branch for the new.'), _('REV')), |
82
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
226 |
] + walkopts + commitopts + commitopts2, |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
227 |
_('[OPTION]... [FILE]...')) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
228 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
229 |
def amend(ui, repo, *pats, **opts): |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
230 |
"""combine a changeset with updates and replace it with a new one |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
231 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
232 |
Commits a new changeset incorporating both the changes to the given files |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
233 |
and all the changes from the current parent changeset into the repository. |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
234 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
235 |
See :hg:`commit` for details about committing changes. |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
236 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
237 |
If you don't specify -m, the parent's message will be reused. |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
238 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
239 |
If you specify --change, amend additionally considers all changesets between |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
240 |
the indicated changeset and the working copy parent as updates to be subsumed. |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
241 |
This allows you to commit updates manually first. As a special shorthand you |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
242 |
can say `--amend .` instead of '--amend p1(p1())', which subsumes your latest |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
243 |
commit as an update of its parent. |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
244 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
245 |
Behind the scenes, Mercurial first commits the update as a regular child |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
246 |
of the current parent. Then it creates a new commit on the parent's parents |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
247 |
with the updated contents. Then it changes the working copy parent to this |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
248 |
new combined changeset. Finally, the old changeset and its update are hidden |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
249 |
from :hg:`log` (unless you use --hidden with log). |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
250 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
251 |
Returns 0 on success, 1 if nothing changed. |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
252 |
""" |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
253 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
254 |
# determine updates to subsume |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
255 |
change = opts.get('change') |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
256 |
if change == '.': |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
257 |
change = 'p1(p1())' |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
258 |
old = scmutil.revsingle(repo, change) |
103
23c232a81fbe
amend: add a --branch option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
94
diff
changeset
|
259 |
branch = opts.get('branch') |
23c232a81fbe
amend: add a --branch option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
94
diff
changeset
|
260 |
if branch: |
23c232a81fbe
amend: add a --branch option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
94
diff
changeset
|
261 |
opts.setdefault('extra', {})['branch'] = branch |
82
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
262 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
263 |
wlock = repo.wlock() |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
264 |
try: |
92
5b23cdf998d0
[evolution:amend] prevent amending immutable changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
91
diff
changeset
|
265 |
if not old.state().mutable: |
5b23cdf998d0
[evolution:amend] prevent amending immutable changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
91
diff
changeset
|
266 |
raise util.Abort(_("can not rewrite immutable changeset %s") % old) |
82
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
267 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
268 |
# commit current changes as update |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
269 |
# code copied from commands.commit to avoid noisy messages |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
270 |
ciopts = dict(opts) |
104
6c3c7a18f079
propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
103
diff
changeset
|
271 |
ciopts.pop('message', None) |
6c3c7a18f079
propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
103
diff
changeset
|
272 |
ciopts.pop('logfile', None) |
82
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
273 |
ciopts['message'] = opts.get('note') or ('amends %s' % old.hex()) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
274 |
e = cmdutil.commiteditor |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
275 |
if ciopts.get('force_editor'): |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
276 |
e = cmdutil.commitforceeditor |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
277 |
def commitfunc(ui, repo, message, match, opts): |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
278 |
return repo.commit(message, opts.get('user'), opts.get('date'), match, |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
279 |
editor=e) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
280 |
cmdutil.commit(ui, repo, commitfunc, pats, ciopts) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
281 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
282 |
# find all changesets to be considered updates |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
283 |
cl = repo.changelog |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
284 |
head = repo['.'] |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
285 |
updatenodes = set(cl.nodesbetween(roots=[old.node()], |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
286 |
heads=[head.node()])[0]) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
287 |
updatenodes.remove(old.node()) |
104
6c3c7a18f079
propertly handle -m and -l option
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
103
diff
changeset
|
288 |
if not updatenodes and not (opts.get('message') or opts.get('logfile')): |
82
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
289 |
raise error.Abort(_('no updates found')) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
290 |
updates = [repo[n] for n in updatenodes] |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
291 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
292 |
# perform amend |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
293 |
newid = rewrite(repo, old, updates, head, |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
294 |
[old.p1().node(), old.p2().node()], opts) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
295 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
296 |
# reroute the working copy parent to the new changeset |
108
85271a8a7fb9
Properly inherit phase of relocated changeset.
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
104
diff
changeset
|
297 |
repo.setstate(repo.nodestate(old.node()), [newid]) |
82
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
298 |
repo.dirstate.setparents(newid, node.nullid) |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
299 |
|
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
300 |
finally: |
8108d566a8b5
[evolution] imported hg amend from parren works
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
81
diff
changeset
|
301 |
wlock.release() |