Rev 8: Fix handling of inventory sha1, add global-stats command. in file:///data/jelmer/bzr-global-log/trunk/

Jelmer Vernooij jelmer at samba.org
Tue Nov 20 18:22:46 GMT 2007


At file:///data/jelmer/bzr-global-log/trunk/

------------------------------------------------------------
revno: 8
revision-id:jelmer at samba.org-20071105042458-8n8cy01vujomehzr
parent: jelmer at samba.org-20071105035535-c83m79si303p8osw
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Mon 2007-11-05 05:24:58 +0100
message:
  Fix handling of inventory sha1, add global-stats command.
modified:
  __init__.py                    __init__.py-20071029004222-avdgq0mc7n1q6q8f-1
  cache.py                       db.py-20071105012118-v51dlgcjf12dagnc-1
=== modified file '__init__.py'
--- a/__init__.py	2007-11-05 03:55:35 +0000
+++ b/__init__.py	2007-11-05 04:24:58 +0000
@@ -27,6 +27,56 @@
     return osutils.pathjoin(config_dir(), "global-log-cache.db")
 
 
+def gather_revids(location_list):
+    pb = ui.ui_factory.nested_progress_bar()
+    try:
+        repos = set()
+        revids = set()
+        for location in location_list:
+            pb.update("discovering revisions", 
+                      location_list.index(location),
+                      len(location_list))
+            branch = Branch.open(location)
+            repos.add(branch.repository)
+            revids.update(branch.repository.get_ancestry(branch.last_revision()))
+    finally:
+        pb.finished()
+
+    revids.remove(None)
+    return revids, repos
+
+
+
+class cmd_global_stats(Command):
+    """Global statistics."""
+
+    takes_options = [Option('cache', help="Use cache")]
+    takes_args = ["location*"]
+
+    def run(self, location_list, cache=False):
+        from bzrlib.plugins.global_log.cache import RevisionCachingRepository
+        from bzrlib.plugins.global_log.log import cmp_log_by_time
+        from bzrlib.plugins.global_log.stack import SimpleStackingRepository
+        if location_list is None:
+            location_list = ["."]
+
+        if cache:
+            repository = RevisionCachingRepository(get_cache_db_path())
+        else:
+            repository = SimpleStackingRepository()
+
+        revids, repos = gather_revids(location_list)
+
+        for repo in repos:
+            repository.add_repository(repo)
+
+        from bzrlib.plugins.stats import (sort_by_committer, collapse_by_author,
+                                          display_info)
+
+        info = collapse_by_author(sort_by_committer(repository, revids))
+        display_info(info, self.outf)
+
+
 class cmd_global_log(Command):
     """Log global revisions."""
 
@@ -42,30 +92,30 @@
         from bzrlib.plugins.global_log.cache import RevisionCachingRepository
         from bzrlib.plugins.global_log.log import cmp_log_by_time
         from bzrlib.plugins.global_log.stack import SimpleStackingRepository
+        if location_list is None:
+            location_list = ["."]
+
+        if cache:
+            repository = RevisionCachingRepository(get_cache_db_path())
+        else:
+            repository = SimpleStackingRepository()
+
+        revids, repos = gather_revids(location_list)
+
+        for repo in repos:
+            repository.add_repository(repo)
+
+        revs = set()
         pb = ui.ui_factory.nested_progress_bar()
-        if location_list is None:
-            location_list = ["."]
-
-        if cache:
-            repository = RevisionCachingRepository(get_cache_db_path())
-        else:
-            repository = SimpleStackingRepository()
-
         try:
-            revids = set()
-            for location in location_list:
-                pb.update("discovering revisions", 
-                          location_list.index(location),
-                          len(location_list))
-                branch = Branch.open(location)
-                repository.add_repository(branch.repository)
-                revids.update(branch.repository.get_ancestry(branch.last_revision()))
+            count = 0
+            for rev in repository.get_revisions(revids):
+                pb.update("getting revision info", count, len(revids))
+                revs.add(LogRevision(rev=rev))
+                count += 1
         finally:
             pb.finished()
 
-        revids.remove(None)
-        revs = [LogRevision(rev=rev) for rev in repository.get_revisions(revids)]
-
         if log_format is None:
             log_format = LineLogFormatter
         lf = log_format(to_file=self.outf, show_timezone='original')
@@ -80,4 +130,5 @@
 
 
 register_command(cmd_global_log)
+register_command(cmd_global_stats)
 

=== modified file 'cache.py'
--- a/cache.py	2007-11-05 03:37:40 +0000
+++ b/cache.py	2007-11-05 04:24:58 +0000
@@ -54,7 +54,7 @@
         self.db.executescript("""
             CREATE TABLE IF NOT EXISTS revision (revid text, committer text, 
                                    timestamp integer, timezone integer, 
-                                   message text);
+                                   message text, inventory_sha1 text);
             CREATE UNIQUE INDEX IF NOT EXISTS idx_revision_revid ON revision (revid);
             CREATE INDEX IF NOT EXISTS idx_timestamp ON revision (timestamp);
             CREATE TABLE IF NOT EXISTS revision_location (revid text, repository text);
@@ -74,10 +74,12 @@
 
     def add_revision(self, rev):
         self.db.execute("""INSERT INTO revision (revid, committer, 
-                                               timestamp, timezone, message)
-                         VALUES (?, ?, ?, ?, ?)""",
+                                               timestamp, timezone, message,
+                                               inventory_sha1)
+                         VALUES (?, ?, ?, ?, ?, ?)""",
                          (rev.revision_id, rev.committer,
-                          rev.timestamp, rev.timezone, rev.message))
+                          rev.timestamp, rev.timezone, rev.message, 
+                          rev.inventory_sha1))
         for name, value in rev.properties.items():
             self.db.execute("INSERT INTO revision_property (revid, name, value) VALUES (?, ?, ?)", (rev.revision_id, name, value))
         for p in rev.parent_ids:
@@ -85,7 +87,7 @@
         self.db.commit()
 
     def get_revision(self, revid):
-        row = self.db.execute("SELECT committer, timestamp, timezone, message FROM revision WHERE revid=?", (revid,)).fetchone()
+        row = self.db.execute("SELECT committer, timestamp, timezone, message, inventory_sha1 FROM revision WHERE revid=?", (revid,)).fetchone()
         if row is None:
             raise NoSuchRevision(revid, self)
         rev = Revision(revid)
@@ -93,6 +95,7 @@
         rev.timestamp = int(row[1])
         rev.timezone = int(row[2])
         rev.message = row[3]
+        rev.inventory_sha1 = row[4]
         rev.properties = dict(self.db.execute("SELECT name, value FROM revision_property WHERE revid=?", (revid,)).fetchall())
         rev.parent_ids = map(lambda x: x[0], self.db.execute("SELECT parent_revid FROM revision_parent WHERE child_revid = ?", (revid,)).fetchall())
         return rev




More information about the bazaar-commits mailing list