Rev 56: Switch to using GitPython rather than our own in-house stuff. in http://people.samba.org/bzr/jelmer/bzr-git/trunk

Jelmer Vernooij jelmer at samba.org
Sat Jul 26 17:27:36 BST 2008


At http://people.samba.org/bzr/jelmer/bzr-git/trunk

------------------------------------------------------------
revno: 56
revision-id: jelmer at samba.org-20080725225643-o8adohxgoruo3goj
parent: jelmer at samba.org-20080725224552-tz7jwhm9oi4vrb6x
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Sat 2008-07-26 00:56:43 +0200
message:
  Switch to using GitPython rather than our own in-house stuff.
removed:
  model.py                       model.py-20071109031625-vi84303d1n5gnha1-1
  tests/test_model.py            test_model.py-20071109031625-vi84303d1n5gnha1-2
modified:
  README                         README-20060715122516-k72e9yjw2qxzjphc-3
  git_repository.py              git_repository.py-20071108234408-ygidvy5hviixghsd-2
  tests/__init__.py              __init__.py-20070202180350-njrb42t7fnv35d1k-2
  tests/test_git_repository.py   test_git_repository.-20071108234408-ygidvy5hviixghsd-5
=== modified file 'README'
--- a/README	2006-07-15 12:25:27 +0000
+++ b/README	2008-07-25 22:56:43 +0000
@@ -1,7 +1,7 @@
 bzr-git, a plugin for bzr that adds git support.
 
-This is (c) 2006 Canonical Limited, and licenced under the GNU GPL Version 2.
-Please see COPYING for the full text of the licence.
+This is (c) 2006 Canonical Limited, and licenced under the GNU GPL Version 2 
+or later.  Please see COPYING for the full text of the licence.
 
 This was originally written as a proof of concept at Europython 2006, using
 stgit's convenience methods for accessing gits head and parsing git output.

=== modified file 'git_repository.py'
--- a/git_repository.py	2008-03-13 18:38:34 +0000
+++ b/git_repository.py	2008-07-25 22:56:43 +0000
@@ -16,6 +16,7 @@
 
 """An adapter between a Git Repository and a Bazaar Branch"""
 
+import git
 import os
 
 import bzrlib
@@ -34,7 +35,6 @@
 from bzrlib.plugins.git import (
     cache,
     ids,
-    model,
     )
 
 
@@ -49,7 +49,7 @@
     def __init__(self, gitdir, lockfiles):
         self.bzrdir = gitdir
         self.control_files = lockfiles
-        self._git = self._make_model(gitdir.transport)
+        self._git = git.repo.Repo(gitdir.root_transport.local_abspath("."))
         self._revision_cache = {}
         self._blob_cache = {}
         self._blob_info_cache = {}
@@ -60,6 +60,9 @@
             cachedbs[cache_file] = cache.sqlite3.connect(cache_file)
         self.cachedb = cachedbs[cache_file]
         self._init_cachedb()
+        self.texts = None
+        self.signatures = None
+        self.revisions = None
         self._format = GitFormat()
 
     def _init_cachedb(self):
@@ -79,13 +82,6 @@
         """)
         self.cachedb.commit()
 
-
-    @classmethod
-    def _make_model(klass, transport):
-        gitdirectory = transport.local_abspath('.')
-        return model.GitModel(gitdirectory)
-
-
     def _ancestor_revisions(self, revision_ids):
         if revision_ids is not None:
             git_revisions = [gitrevid_from_bzr(r) for r in revision_ids]

=== removed file 'model.py'
--- a/model.py	2007-12-29 22:02:30 +0000
+++ b/model.py	1970-01-01 00:00:00 +0000
@@ -1,126 +0,0 @@
-# Copyright (C) 2007 Canonical Ltd
-#
-# 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
-
-"""The model for interacting with the git process, etc."""
-
-import os
-import subprocess
-
-from bzrlib.plugins.git import errors
-
-
-class GitModel(object):
-    """API that follows GIT model closely"""
-
-    def __init__(self, git_dir):
-        self.git_dir = git_dir
-
-    def git_command(self, command, args):
-        return ['git', command] + args
-
-    def git_lines(self, command, args):
-        cmd = self.git_command(command, args)
-        env = os.environ.copy()
-        env['GIT_DIR'] = self.git_dir
-        p = subprocess.Popen(cmd,
-                             stdout=subprocess.PIPE,
-                             stderr=subprocess.PIPE,
-                             env=env)
-        lines = p.stdout.readlines()
-        if p.wait() != 0:
-            raise errors.GitCommandError(cmd, p.returncode,
-                                         p.stderr.read().strip())
-        return lines
-
-    def git_line(self, command, args):
-        lines = self.git_lines(command, args)
-        return lines[0]
-
-    def cat_file(self, type, object_id, pretty=False):
-        args = []
-        if pretty:
-            args.append('-p')
-        else:
-            args.append(type)
-        args.append(object_id)
-        return self.git_lines('cat-file', args)
-
-    def rev_list(self, heads, max_count=None, header=False, parents=False,
-                 topo_order=False, paths=None):
-        args = []
-        if max_count is not None:
-            args.append('--max-count=%d' % max_count)
-        if header:
-            args.append('--header')
-        if parents:
-            args.append('--parents')
-        if topo_order:
-            args.append('--topo-order')
-        if heads is None:
-            args.append('--all')
-        else:
-            args.extend(heads)
-        if paths is not None:
-            args.append('--')
-            args.extend(paths)
-        return self.git_lines('rev-list', args)
-
-    def rev_parse(self, git_id):
-        args = ['--verify', git_id]
-        return self.git_line('rev-parse', args).strip()
-
-    def get_head(self):
-        try:
-            return self.rev_parse('HEAD')
-        except errors.GitCommandError, e:
-            # Most likely, this is a null branch, so treat it as such
-            if e.stderr == 'fatal: Needed a single revision':
-                return None
-            raise
-
-    def get_revision_graph(self, revisions):
-        ancestors = {}
-        for line in self.rev_list(revisions, parents=True):
-            entries = line.split()
-            ancestors[entries[0]] = entries[1:]
-        return ancestors
-
-    def get_ancestry(self, revisions):
-        args = ['--topo-order', '--reverse'] + revisions
-        return [line[:-1] for line in self.git_lines('rev-list', args)]
-
-    def ancestor_lines(self, revisions):
-        revision_lines = []
-        for line in self.rev_list(revisions, header=True):
-            if line.startswith('\x00'):
-                yield revision_lines
-                revision_lines = [line[1:].decode('latin-1')]
-            else:
-                revision_lines.append(line.decode('latin-1'))
-        assert revision_lines == ['']
-
-    def get_inventory(self, tree_id):
-        for line in self.git_lines('ls-tree', ['-r', '-t', tree_id]):
-            # Ideally, we would use -z so we would not have to handle escaped
-            # file names. But then we could not use readlines() to split the
-            # data as it is read.
-            permissions, type, hash_and_path = line.split(' ', 2)
-            hash, name = hash_and_path.split('\t', 1)
-            name = name[:-1] # strip trailing newline
-            if name.startswith('"'):
-                name = name[1:-1].decode('string_escape')
-            name = name.decode('utf-8')
-            yield permissions, type, hash, name

=== modified file 'tests/__init__.py'
--- a/tests/__init__.py	2007-12-30 01:11:44 +0000
+++ b/tests/__init__.py	2008-07-25 22:56:43 +0000
@@ -231,7 +231,6 @@
         'test_git_branch',
         'test_git_dir',
         'test_git_repository',
-        'test_model',
         'test_ids',
         'test_blackbox',
         ]

=== modified file 'tests/test_git_repository.py'
--- a/tests/test_git_repository.py	2008-03-13 18:37:47 +0000
+++ b/tests/test_git_repository.py	2008-07-25 22:56:43 +0000
@@ -16,7 +16,7 @@
 
 """Tests for interfacing with a Git Repository"""
 
-import subprocess
+import git
 
 from bzrlib import (
     inventory,
@@ -29,7 +29,6 @@
     git_dir,
     git_repository,
     ids,
-    model,
     )
 
 
@@ -44,11 +43,11 @@
         repo = repository.Repository.open('.')
         self.assertIsInstance(repo, git_repository.GitRepository)
 
-    def test_has_git_model(self):
+    def test_has_git_repo(self):
         tests.run_git('init')
 
         repo = repository.Repository.open('.')
-        self.assertIsInstance(repo._git, model.GitModel)
+        self.assertIsInstance(repo._git, git.repo.Repo)
 
     def test_revision_graph(self):
         tests.run_git('init')

=== removed file 'tests/test_model.py'
--- a/tests/test_model.py	2007-12-28 21:33:53 +0000
+++ b/tests/test_model.py	1970-01-01 00:00:00 +0000
@@ -1,104 +0,0 @@
-# Copyright (C) 2007 Canonical Ltd
-#
-# 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
-
-"""Test the model for interacting with the git process, etc."""
-
-from bzrlib.plugins.git import tests
-from bzrlib.plugins.git import (
-    errors,
-    model,
-    )
-
-
-class TestModel(tests.TestCaseInTempDir):
-
-    def test_no_head(self):
-        tests.run_git('init')
-        themodel = model.GitModel('.git')
-        self.assertIs(None, themodel.get_head())
-
-    def test_no_repository(self):
-        themodel = model.GitModel('.git')
-        self.assertRaises(errors.GitCommandError, themodel.get_head)
-
-    def test_get_revision_graph(self):
-        tests.run_git('init')
-        builder = tests.GitBranchBuilder()
-        file_handle = builder.set_file('a', 'text for a\n', False)
-        commit1_handle = builder.commit('Joe Foo <joe at foo.com>', u'message')
-        file2_handle = builder.set_file('a', 'new a\n', False)
-        commit2_handle = builder.commit('Joe Foo <joe at foo.com>', u'new a')
-        file3_handle = builder.set_file('b', 'text for b\n', False)
-        commit3_handle = builder.commit('Jerry Bar <jerry at foo.com>', u'b',
-                                        base=commit1_handle)
-        commit4_handle = builder.commit('Jerry Bar <jerry at foo.com>', u'merge',
-                                        base=commit3_handle,
-                                        merge=[commit2_handle],)
-
-        mapping = builder.finish()
-        commit1_id = mapping[commit1_handle]
-        commit2_id = mapping[commit2_handle]
-        commit3_id = mapping[commit3_handle]
-        commit4_id = mapping[commit4_handle]
-
-        revisions = tests.run_git('rev-list', '--topo-order',
-                                  commit4_id)
-        revisions = revisions.splitlines()
-        self.assertEqual([commit4_id, commit2_id, commit3_id, commit1_id],
-                         revisions)
-
-        graph = {revisions[0]:[revisions[2], revisions[1]],
-                 revisions[1]:[revisions[3]],
-                 revisions[2]:[revisions[3]],
-                 revisions[3]:[],
-                }
-
-        themodel = model.GitModel('.git')
-        self.assertEqual(revisions[0], themodel.get_head())
-        self.assertEqual(graph, themodel.get_revision_graph([revisions[0]]))
-
-    def test_get_inventory(self):
-        # Create a git repository with some interesting files in a revision.
-        tests.run_git('init')
-        builder = tests.GitBranchBuilder()
-        builder.set_file('data', 'text\n', False)
-        builder.set_file('data-multi\nline', 'text\n', False)
-        builder.set_file(u'data-unic\xb5de', 'text\n', False)
-        builder.set_file('executable', 'content', True)
-        builder.set_link('link', 'broken')
-        builder.set_file('subdir/subfile', 'subdir text\n', False)
-        commit_handle = builder.commit('Joe Foo <joe at foo.com>', u'message')
-        mapping = builder.finish()
-        commit_id = mapping[commit_handle]
-
-        # Get the corresponding git inventory.
-        themodel = model.GitModel('.git')
-        git_inventory = list(themodel.get_inventory(commit_id))
-        self.assertEqual(git_inventory,
-            [('100644', 'blob', '8e27be7d6154a1f68ea9160ef0e18691d20560dc',
-              u'data'),
-             ('100644', 'blob', '8e27be7d6154a1f68ea9160ef0e18691d20560dc',
-              u'data-multi\nline'),
-             ('100644', 'blob', '8e27be7d6154a1f68ea9160ef0e18691d20560dc',
-              u'data-unic\xb5de'),
-             ('100755', 'blob', '6b584e8ece562ebffc15d38808cd6b98fc3d97ea',
-              u'executable'),
-             ('120000', 'blob', '86a410dd1d337c4f9f59e2aa35bc188f18ad08e4',
-              u'link'),
-             ('040000', 'tree', 'ccf7f8fa4e6eee68d761f36556d9896938b32e7f',
-              u'subdir'),
-             ('100644', 'blob', '0ddb53cbe2dd209f550dd8d7f1287a5ed9b1ee8b',
-              u'subdir/subfile')])




More information about the bazaar-commits mailing list