changeset 1860:97f07d311a50

Merged tah and crew
author Thomas Arendsen Hein <thomas@intevation.de>
date Wed, 08 Mar 2006 06:20:32 +0100
parents 39c46510ed25 (current diff) b8bd84ad9b67 (diff)
children 65949d1c9bf7 7a09785d3237
files
diffstat 1 files changed, 24 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/hbisect.py	Wed Mar 08 06:13:24 2006 +0100
+++ b/contrib/hbisect.py	Wed Mar 08 06:20:32 2006 +0100
@@ -1,11 +1,10 @@
-#!/usr/bin/env python
+# bisect extension for mercurial
 #
 # This software may be used and distributed according to the terms
 # of the GNU General Public License, incorporated herein by reference.
 
 from mercurial.demandload import demandload
-demandload(globals(), "os sys sets")
-from mercurial import hg
+demandload(globals(), "os sys sets mercurial:hg,util")
 
 versionstr = "0.0.3"
 
@@ -30,33 +29,32 @@
     """dichotomic search in the DAG of changesets"""
     def __init__(self, ui, repo):
         self.repo = repo
-        self.path = os.path.join(repo.join(""), "bisect")
+        self.path = repo.join("bisect")
+        self.opener = util.opener(self.path)
         self.ui = ui
         self.goodrevs = []
         self.badrev = None
         self.good_dirty = 0
         self.bad_dirty = 0
-        self.good_path = os.path.join(self.path, "good")
-        self.bad_path = os.path.join(self.path, "bad")
+        self.good_path = "good"
+        self.bad_path = "bad"
 
-        s = self.good_path
-        if os.path.exists(s):
-            self.goodrevs = self.repo.opener(s).read().splitlines()
+        if os.path.exists(os.path.join(self.path, self.good_path)):
+            self.goodrevs = self.opener(self.good_path).read().splitlines()
             self.goodrevs = [hg.bin(x) for x in self.goodrevs]
-        s = self.bad_path
-        if os.path.exists(s):
-            r = self.repo.opener(s).read().splitlines()
+        if os.path.exists(os.path.join(self.path, self.bad_path)):
+            r = self.opener(self.bad_path).read().splitlines()
             if r:
                 self.badrev = hg.bin(r.pop(0))
 
     def __del__(self):
         if not os.path.isdir(self.path):
             return
-        f = self.repo.opener(self.good_path, "w")
+        f = self.opener(self.good_path, "w")
         f.write("\n".join([hg.hex(r) for r in  self.goodrevs]))
         if len(self.goodrevs) > 0:
             f.write("\n")
-        f = self.repo.opener(self.bad_path, "w")
+        f = self.opener(self.bad_path, "w")
         if self.badrev:
             f.write(hg.hex(self.badrev) + "\n")
 
@@ -72,7 +70,8 @@
     def reset(self):
         """finish a bisection"""
         if os.path.isdir(self.path):
-            sl = [self.bad_path, self.good_path]
+            sl = [os.path.join(self.path, p)
+                  for p in [self.bad_path, self.good_path]]
             for s in sl:
                 if os.path.exists(s):
                     os.unlink(s)
@@ -92,7 +91,7 @@
         if head is None:
             head = self.badrev
         return self.__ancestors_and_nb_ancestors(head, stop)[1]
-        
+
     def ancestors(self, head=None, stop=None):
         """
         returns the set of the ancestors of head (self included)
@@ -101,7 +100,7 @@
         if head is None:
             head = self.badrev
         return self.__ancestors_and_nb_ancestors(head, stop)[0]
-        
+
     def __ancestors_and_nb_ancestors(self, head, stop=None):
         """
         if stop is None then ancestors of goodrevs are used as
@@ -114,7 +113,8 @@
         cl = self.repo.changelog
         if not stop:
             stop = sets.Set([])
-            for g in reversed(self.goodrevs):
+            for i in xrange(len(self.goodrevs)-1, -1, -1):
+                g = self.goodrevs[i]
                 if g in stop:
                     continue
                 stop.update(cl.reachable(g))
@@ -132,7 +132,7 @@
                 for p in parents:
                     d[p][0] += 1
             return d
-        
+
         if head in stop:
             self.ui.warn("Unconsistent state, %s is good and bad\n"
                           % hg.hex(head))
@@ -162,7 +162,8 @@
         if not self.goodrevs:
             self.ui.warn("No good revision given\n")
             self.ui.warn("Assuming the first revision is good\n")
-        ancestors, num_ancestors = self.__ancestors_and_nb_ancestors(self.badrev)
+        ancestors, num_ancestors = self.__ancestors_and_nb_ancestors(
+                                    self.badrev)
         tot = len(ancestors)
         if tot == 1:
             if ancestors.pop() != self.badrev:
@@ -261,7 +262,7 @@
         for cmd in cmds:
             doc = cmdtable[cmd][0].__doc__.splitlines(0)[0].rstrip()
             ui.write(" %-*s   %s\n" % (m, cmd, doc))
-    
+
     b = bisect(ui, repo)
     bisectcmdtable = {
         "init": (b.init, 0, "hg bisect init"),
@@ -271,7 +272,7 @@
         "reset": (b.reset, 0, "hg bisect reset"),
         "help": (help_, 1, "hg bisect help [<subcommand>]"),
     }
-            
+
     if not bisectcmdtable.has_key(cmd):
         ui.warn("bisect: Unknown sub-command\n")
         return help_()
@@ -281,7 +282,6 @@
     return bisectcmdtable[cmd][0](*args)
 
 cmdtable = {
-    "bisect": (bisect_run, [], 
-               "hg bisect [help|init|reset|next|good|bad]"),
+    "bisect": (bisect_run, [], "hg bisect [help|init|reset|next|good|bad]"),
     #"bisect-test": (test, [], "hg bisect-test rev"),
 }