##// END OF EJS Templates
Merged tah and crew
Thomas Arendsen Hein -
r1860:97f07d31 merge default
parent child Browse files
Show More
@@ -1,11 +1,10 b''
1 #!/usr/bin/env python
1 # bisect extension for mercurial
2 #
2 #
3 # This software may be used and distributed according to the terms
3 # This software may be used and distributed according to the terms
4 # of the GNU General Public License, incorporated herein by reference.
4 # of the GNU General Public License, incorporated herein by reference.
5
5
6 from mercurial.demandload import demandload
6 from mercurial.demandload import demandload
7 demandload(globals(), "os sys sets")
7 demandload(globals(), "os sys sets mercurial:hg,util")
8 from mercurial import hg
9
8
10 versionstr = "0.0.3"
9 versionstr = "0.0.3"
11
10
@@ -30,33 +29,32 b' class bisect(object):'
30 """dichotomic search in the DAG of changesets"""
29 """dichotomic search in the DAG of changesets"""
31 def __init__(self, ui, repo):
30 def __init__(self, ui, repo):
32 self.repo = repo
31 self.repo = repo
33 self.path = os.path.join(repo.join(""), "bisect")
32 self.path = repo.join("bisect")
33 self.opener = util.opener(self.path)
34 self.ui = ui
34 self.ui = ui
35 self.goodrevs = []
35 self.goodrevs = []
36 self.badrev = None
36 self.badrev = None
37 self.good_dirty = 0
37 self.good_dirty = 0
38 self.bad_dirty = 0
38 self.bad_dirty = 0
39 self.good_path = os.path.join(self.path, "good")
39 self.good_path = "good"
40 self.bad_path = os.path.join(self.path, "bad")
40 self.bad_path = "bad"
41
41
42 s = self.good_path
42 if os.path.exists(os.path.join(self.path, self.good_path)):
43 if os.path.exists(s):
43 self.goodrevs = self.opener(self.good_path).read().splitlines()
44 self.goodrevs = self.repo.opener(s).read().splitlines()
45 self.goodrevs = [hg.bin(x) for x in self.goodrevs]
44 self.goodrevs = [hg.bin(x) for x in self.goodrevs]
46 s = self.bad_path
45 if os.path.exists(os.path.join(self.path, self.bad_path)):
47 if os.path.exists(s):
46 r = self.opener(self.bad_path).read().splitlines()
48 r = self.repo.opener(s).read().splitlines()
49 if r:
47 if r:
50 self.badrev = hg.bin(r.pop(0))
48 self.badrev = hg.bin(r.pop(0))
51
49
52 def __del__(self):
50 def __del__(self):
53 if not os.path.isdir(self.path):
51 if not os.path.isdir(self.path):
54 return
52 return
55 f = self.repo.opener(self.good_path, "w")
53 f = self.opener(self.good_path, "w")
56 f.write("\n".join([hg.hex(r) for r in self.goodrevs]))
54 f.write("\n".join([hg.hex(r) for r in self.goodrevs]))
57 if len(self.goodrevs) > 0:
55 if len(self.goodrevs) > 0:
58 f.write("\n")
56 f.write("\n")
59 f = self.repo.opener(self.bad_path, "w")
57 f = self.opener(self.bad_path, "w")
60 if self.badrev:
58 if self.badrev:
61 f.write(hg.hex(self.badrev) + "\n")
59 f.write(hg.hex(self.badrev) + "\n")
62
60
@@ -72,7 +70,8 b' class bisect(object):'
72 def reset(self):
70 def reset(self):
73 """finish a bisection"""
71 """finish a bisection"""
74 if os.path.isdir(self.path):
72 if os.path.isdir(self.path):
75 sl = [self.bad_path, self.good_path]
73 sl = [os.path.join(self.path, p)
74 for p in [self.bad_path, self.good_path]]
76 for s in sl:
75 for s in sl:
77 if os.path.exists(s):
76 if os.path.exists(s):
78 os.unlink(s)
77 os.unlink(s)
@@ -92,7 +91,7 b' class bisect(object):'
92 if head is None:
91 if head is None:
93 head = self.badrev
92 head = self.badrev
94 return self.__ancestors_and_nb_ancestors(head, stop)[1]
93 return self.__ancestors_and_nb_ancestors(head, stop)[1]
95
94
96 def ancestors(self, head=None, stop=None):
95 def ancestors(self, head=None, stop=None):
97 """
96 """
98 returns the set of the ancestors of head (self included)
97 returns the set of the ancestors of head (self included)
@@ -101,7 +100,7 b' class bisect(object):'
101 if head is None:
100 if head is None:
102 head = self.badrev
101 head = self.badrev
103 return self.__ancestors_and_nb_ancestors(head, stop)[0]
102 return self.__ancestors_and_nb_ancestors(head, stop)[0]
104
103
105 def __ancestors_and_nb_ancestors(self, head, stop=None):
104 def __ancestors_and_nb_ancestors(self, head, stop=None):
106 """
105 """
107 if stop is None then ancestors of goodrevs are used as
106 if stop is None then ancestors of goodrevs are used as
@@ -114,7 +113,8 b' class bisect(object):'
114 cl = self.repo.changelog
113 cl = self.repo.changelog
115 if not stop:
114 if not stop:
116 stop = sets.Set([])
115 stop = sets.Set([])
117 for g in reversed(self.goodrevs):
116 for i in xrange(len(self.goodrevs)-1, -1, -1):
117 g = self.goodrevs[i]
118 if g in stop:
118 if g in stop:
119 continue
119 continue
120 stop.update(cl.reachable(g))
120 stop.update(cl.reachable(g))
@@ -132,7 +132,7 b' class bisect(object):'
132 for p in parents:
132 for p in parents:
133 d[p][0] += 1
133 d[p][0] += 1
134 return d
134 return d
135
135
136 if head in stop:
136 if head in stop:
137 self.ui.warn("Unconsistent state, %s is good and bad\n"
137 self.ui.warn("Unconsistent state, %s is good and bad\n"
138 % hg.hex(head))
138 % hg.hex(head))
@@ -162,7 +162,8 b' class bisect(object):'
162 if not self.goodrevs:
162 if not self.goodrevs:
163 self.ui.warn("No good revision given\n")
163 self.ui.warn("No good revision given\n")
164 self.ui.warn("Assuming the first revision is good\n")
164 self.ui.warn("Assuming the first revision is good\n")
165 ancestors, num_ancestors = self.__ancestors_and_nb_ancestors(self.badrev)
165 ancestors, num_ancestors = self.__ancestors_and_nb_ancestors(
166 self.badrev)
166 tot = len(ancestors)
167 tot = len(ancestors)
167 if tot == 1:
168 if tot == 1:
168 if ancestors.pop() != self.badrev:
169 if ancestors.pop() != self.badrev:
@@ -261,7 +262,7 b' for subcommands see "hg bisect help\\"'
261 for cmd in cmds:
262 for cmd in cmds:
262 doc = cmdtable[cmd][0].__doc__.splitlines(0)[0].rstrip()
263 doc = cmdtable[cmd][0].__doc__.splitlines(0)[0].rstrip()
263 ui.write(" %-*s %s\n" % (m, cmd, doc))
264 ui.write(" %-*s %s\n" % (m, cmd, doc))
264
265
265 b = bisect(ui, repo)
266 b = bisect(ui, repo)
266 bisectcmdtable = {
267 bisectcmdtable = {
267 "init": (b.init, 0, "hg bisect init"),
268 "init": (b.init, 0, "hg bisect init"),
@@ -271,7 +272,7 b' for subcommands see "hg bisect help\\"'
271 "reset": (b.reset, 0, "hg bisect reset"),
272 "reset": (b.reset, 0, "hg bisect reset"),
272 "help": (help_, 1, "hg bisect help [<subcommand>]"),
273 "help": (help_, 1, "hg bisect help [<subcommand>]"),
273 }
274 }
274
275
275 if not bisectcmdtable.has_key(cmd):
276 if not bisectcmdtable.has_key(cmd):
276 ui.warn("bisect: Unknown sub-command\n")
277 ui.warn("bisect: Unknown sub-command\n")
277 return help_()
278 return help_()
@@ -281,7 +282,6 b' for subcommands see "hg bisect help\\"'
281 return bisectcmdtable[cmd][0](*args)
282 return bisectcmdtable[cmd][0](*args)
282
283
283 cmdtable = {
284 cmdtable = {
284 "bisect": (bisect_run, [],
285 "bisect": (bisect_run, [], "hg bisect [help|init|reset|next|good|bad]"),
285 "hg bisect [help|init|reset|next|good|bad]"),
286 #"bisect-test": (test, [], "hg bisect-test rev"),
286 #"bisect-test": (test, [], "hg bisect-test rev"),
287 }
287 }
General Comments 0
You need to be logged in to leave comments. Login now