annotate hgext/drophack.py @ 806:895fadf6ba3e

evolve: extend obsstore object to use prune parent information Now that we have the information, we can use it to build a mapping to access all marker that prune a children of a node. This is similar to what we do for successors and precursors. The performance impact is a few tens of second on my mercurial clone. Experimenting is worth the trouble.
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Wed, 19 Feb 2014 17:27:45 -0800
parents 5af309865040
children 60dd0c401034
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
790
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
1 # This software may be used and distributed according to the terms of the
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
2 # GNU General Public License version 2 or any later version.
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
3 '''This extension add a hacky command to drop changeset during review
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
4
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
5 This extension is intended as a temporary hack to allow Matt Mackall to use
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
6 evolve in the Mercurial review it self. You should probably not use it if your
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
7 name is not Matt Mackall.
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
8 '''
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
9
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
10 import os
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
11 import time
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
12 import contextlib
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
13
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
14 from mercurial.i18n import _
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
15 from mercurial import cmdutil
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
16 from mercurial import repair
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
17 from mercurial import scmutil
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
18 from mercurial import lock as lockmod
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
19 from mercurial import util
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
20 from mercurial import commands
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
21
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
22 cmdtable = {}
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
23 command = cmdutil.command(cmdtable)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
24
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
25
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
26 @contextlib.contextmanager
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
27 def timed(ui, caption):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
28 ostart = os.times()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
29 cstart = time.time()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
30 yield
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
31 cstop = time.time()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
32 ostop = os.times()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
33 wall = cstop - cstart
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
34 user = ostop[0] - ostart[0]
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
35 sys = ostop[1] - ostart[1]
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
36 comb = user + sys
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
37 ui.write("%s: wall %f comb %f user %f sys %f\n"
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
38 % (caption, wall, comb, user, sys))
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
39
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
40 def obsmarkerchainfrom(obsstore, nodes):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
41 """return all marker chain starting from node
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
42
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
43 Starting from mean "use as successors"."""
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
44 # XXX need something smarter for descendant of bumped changeset
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
45 seennodes = set(nodes)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
46 seenmarkers = set()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
47 pendingnodes = set(nodes)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
48 precursorsmarkers = obsstore.precursors
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
49 while pendingnodes:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
50 current = pendingnodes.pop()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
51 new = set()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
52 for precmark in precursorsmarkers.get(current, ()):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
53 if precmark in seenmarkers:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
54 continue
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
55 seenmarkers.add(precmark)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
56 new.add(precmark[0])
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
57 yield precmark
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
58 new -= seennodes
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
59 pendingnodes |= new
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
60
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
61 def stripmarker(ui, repo, markers):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
62 """remove <markers> from the repo obsstore
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
63
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
64 The old obsstore content is saved in a `obsstore.prestrip` file
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
65 """
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
66 repo = repo.unfiltered()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
67 repo.destroying()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
68 oldmarkers = list(repo.obsstore._all)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
69 util.rename(repo.sjoin('obsstore'),
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
70 repo.join('obsstore.prestrip'))
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
71 del repo.obsstore # drop the cache
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
72 newstore = repo.obsstore
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
73 assert not newstore # should be empty after rename
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
74 tr = repo.transaction('drophack')
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
75 try:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
76 for m in oldmarkers:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
77 if m not in markers:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
78 newstore.add(tr, [m])
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
79 tr.close()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
80 finally:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
81 tr.release()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
82 repo.destroyed()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
83
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
84
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
85 @command('drop', [('r', 'rev', [], 'revision to update')], _('[-r] revs'))
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
86 def cmddrop(ui, repo, *revs, **opts):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
87 """I'm hacky do not use me!
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
88
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
89 This command strip a changeset, its precursors and all obsolescence marker
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
90 associated to its chain.
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
91
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
92 There is no way to limit the extend of the purge yet. You may have to
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
93 repull from other source to get some changeset and obsolescence marker
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
94 back.
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
95
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
96 This intended for Matt Mackall usage only. do not use me.
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
97 """
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
98 revs = list(revs)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
99 revs.extend(opts['rev'])
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
100 if not revs:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
101 revs = ['.']
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
102 # get the changeset
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
103 revs = scmutil.revrange(repo, revs)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
104 if not revs:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
105 ui.write_err('no revision to drop\n')
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
106 return 1
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
107 # lock from the beginning to prevent race
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
108 wlock = lock = None
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
109 try:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
110 lock = repo.wlock()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
111 lock = repo.lock()
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
112 # check they have no children
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
113 if repo.revs('%ld and public()', revs):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
114 ui.write_err('cannot drop public revision')
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
115 return 1
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
116 if repo.revs('children(%ld) - %ld', revs, revs):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
117 ui.write_err('cannot drop revision with children')
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
118 return 1
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
119 if repo.revs('. and %ld', revs):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
120 newrevs = repo.revs('max(::. - %ld)', revs)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
121 if newrevs:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
122 assert len(newrevs) == 1
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
123 newrev = newrevs[0]
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
124 else:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
125 newrev = -1
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
126 commands.update(ui, repo, newrev)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
127 ui.status(_('working directory now at %s\n') % repo[newrev])
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
128 # get all markers and successors up to root
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
129 nodes = [repo[r].node() for r in revs]
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
130 with timed(ui, 'search obsmarker'):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
131 markers = set(obsmarkerchainfrom(repo.obsstore, nodes))
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
132 ui.write('%i obsmarkers found\n' % len(markers))
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
133 cl = repo.unfiltered().changelog
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
134 with timed(ui, 'search nodes'):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
135 allnodes = set(nodes)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
136 allnodes.update(m[0] for m in markers if cl.hasnode(m[0]))
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
137 ui.write('%i nodes found\n' % len(allnodes))
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
138 cl = repo.changelog
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
139 visiblenodes = set(n for n in allnodes if cl.hasnode(n))
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
140 # check constraint again
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
141 if repo.revs('%ln and public()', visiblenodes):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
142 ui.write_err('cannot drop public revision')
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
143 return 1
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
144 if repo.revs('children(%ln) - %ln', visiblenodes, visiblenodes):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
145 ui.write_err('cannot drop revision with children')
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
146 return 1
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
147
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
148 if markers:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
149 # strip them
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
150 with timed(ui, 'strip obsmarker'):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
151 stripmarker(ui, repo, markers)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
152 # strip the changeset
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
153 with timed(ui, 'strip nodes'):
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
154 repair.strip(ui, repo, allnodes, backup="all", topic='drophack')
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
155
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
156 finally:
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
157 lockmod.release(lock, wlock)
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
158
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
159 # rewrite the whole file.
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
160 # print data.
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
161 # - time to compute the chain
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
162 # - time to strip the changeset
5af309865040 drophack: add a new drop hack extension for Matt Mackall usage
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
163 # - time to strip the obs marker.