Rev 4: Introduce simple stacked repository - no duplicate revisions printed anymore, at the cost of speed. in file:///data/jelmer/bzr-global-log/trunk/
Jelmer Vernooij
jelmer at samba.org
Tue Nov 20 18:22:45 GMT 2007
At file:///data/jelmer/bzr-global-log/trunk/
------------------------------------------------------------
revno: 4
revision-id:jelmer at samba.org-20071105024001-zjcixn8u3y3ify36
parent: jelmer at samba.org-20071105014851-f5hfe4lagabj4ga5
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Mon 2007-11-05 03:40:01 +0100
message:
Introduce simple stacked repository - no duplicate revisions printed anymore, at the cost of speed.
added:
log.py log.py-20071105015514-0bmng0zxrpw9xbfw-1
stack.py stack.py-20071105021820-d024bz62abe2t3fv-1
tests/ tests-20071105015508-mc9yizu4q89zyryv-1
renamed:
db.py => cache.py db.py-20071105012118-v51dlgcjf12dagnc-1
modified:
__init__.py __init__.py-20071029004222-avdgq0mc7n1q6q8f-1
cache.py db.py-20071105012118-v51dlgcjf12dagnc-1
=== added file 'log.py'
--- a/log.py 1970-01-01 00:00:00 +0000
+++ b/log.py 2007-11-05 02:40:01 +0000
@@ -0,0 +1,22 @@
+# Copyright (C) 2007 Jelmer Vernooij <jelmer at samba.org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+from bzrlib.log import LogRevision
+
+def cmp_log_by_time(x, y):
+ return cmp(y.rev.timestamp, x.rev.timestamp)
+
+
=== added file 'stack.py'
--- a/stack.py 1970-01-01 00:00:00 +0000
+++ b/stack.py 2007-11-05 02:40:01 +0000
@@ -0,0 +1,45 @@
+# Copyright (C) 2007 Jelmer Vernooij <jelmer at samba.org>
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+from bzrlib.errors import NoSuchRevision
+from bzrlib.repository import Repository
+
+class SimpleStackingRepository(Repository):
+ """Very simple, readonly, stacking repository."""
+ def __init__(self):
+ self._subrepositories = set()
+
+ def add_repository(self, repos):
+ self._subrepositories.add(repos)
+
+ def _get_revisions(self, revids):
+ for revid in revids:
+ for repos in self._subrepositories:
+ try:
+ rev = repos.get_revision(revid)
+ except NoSuchRevision:
+ continue
+ yield rev
+ break
+
+ def lock_read(self):
+ pass
+
+ def unlock(self):
+ pass
+
+ def lock_write(self):
+ pass
=== added directory 'tests'
=== renamed file 'db.py' => 'cache.py'
--- a/db.py 2007-11-05 01:48:51 +0000
+++ b/cache.py 2007-11-05 02:40:01 +0000
@@ -14,29 +14,43 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from bzrlib.log import LogRevision
-
-class GlobalLogRevision(LogRevision):
-
- def __init__(self, rev=None, branch=None):
- super(GlobalLogRevision, self).__init__(rev=rev)
- self.branch = branch
-
- def __eq___(self, other):
- if not isinstance(other, GlobalLogRevision):
- return False
- return self.rev == other.rev
-
- def __cmp__(self, other):
- return cmp(other.rev.timestamp, self.rev.timestamp)
+import bzrlib
+from bzrlib.repository import Repository
+from bzrlib.trace import warning
+
+from stack import SimpleStackingRepository
+
+def check_pysqlite_version(sqlite3):
+ """Check that sqlite library is compatible.
+
+ """
+ if (sqlite3.sqlite_version_info[0] < 3 or
+ (sqlite3.sqlite_version_info[0] == 3 and
+ sqlite3.sqlite_version_info[1] < 3)):
+ warning('Needs at least sqlite 3.3.x')
+ raise bzrlib.errors.BzrError("incompatible sqlite library")
+
+try:
+ try:
+ import sqlite3
+ check_pysqlite_version(sqlite3)
+ except (ImportError, bzrlib.errors.BzrError), e:
+ from pysqlite2 import dbapi2 as sqlite3
+ check_pysqlite_version(sqlite3)
+except:
+ warning('Needs at least Python2.5 or Python2.4 with the pysqlite2 '
+ 'module')
+ raise bzrlib.errors.BzrError("missing sqlite library")
class RevisionCache:
- def __init__(self):
+ def __init__(self, location=":memory:"):
+ self.db = sqlite3.connect(location)
self.db.executescript("""
CREATE TABLE revision (revid text, author text, committer text,
- date date, message text);
+ timestamp integer, timezone integer,
+ message text);
CREATE TABLE revision_location (revid text, branch text);
CREATE TABLE revision_parent (child_revid text, parent_revid text);
CREATE TABLE revision_property (revid text, name text, value text);
@@ -56,3 +70,7 @@
def get_log_revision(self, rev):
raise NotImplementedError(self.get_log_revision)
+
+
+class RevisionCachingRepository(SimpleStackingRepository):
+ """Repository implementation that uses a revision cache if possible."""
=== modified file '__init__.py'
--- a/__init__.py 2007-11-05 01:48:51 +0000
+++ b/__init__.py 2007-11-05 02:40:01 +0000
@@ -17,39 +17,55 @@
from bzrlib import ui
from bzrlib.branch import Branch
from bzrlib.commands import Command, register_command
+from bzrlib.option import ListOption
from bzrlib.log import (log_formatter, log_formatter_registry, show_log,
- LineLogFormatter)
+ LineLogFormatter, LogRevision)
class cmd_global_log(Command):
"""Log global revisions."""
- takes_options = ['log-format']
+ takes_options = [
+ 'log-format',
+ ListOption('author', type=unicode,
+ help="Specified author only")
+ ]
takes_args = ["location*"]
- def run(self, location_list, log_format=None):
- from bzrlib.plugins.global_log.db import GlobalLogRevision
+ def run(self, location_list, log_format=None, author=None):
+ from bzrlib.plugins.global_log.log import cmp_log_by_time
+ from bzrlib.plugins.global_log.stack import SimpleStackingRepository
pb = ui.ui_factory.nested_progress_bar()
if location_list is None:
location_list = ["."]
+
+ repository = SimpleStackingRepository()
+
try:
- revs = set()
+ revids = set()
for location in location_list:
pb.update("discovering revisions",
location_list.index(location),
len(location_list))
branch = Branch.open(location)
- revs.update(GlobalLogRevision(branch=branch, rev=rev) for rev in branch.repository.get_revisions(filter(lambda x: x is not None, branch.repository.get_ancestry(branch.last_revision()))))
+ repository.add_repository(branch.repository)
+ revids.update(branch.repository.get_ancestry(branch.last_revision()))
finally:
pb.finished()
- revs = list(revs)
- revs.sort()
+ 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')
- for rev in revs:
+
+ if author is not None and author != []:
+ revs = filter(
+ lambda rev: rev.rev.committer in author,
+ revs)
+
+ for rev in sorted(revs, cmp=cmp_log_by_time):
lf.log_revision(rev)
More information about the bazaar-commits
mailing list