Rev 58: Fix remaining tests. in http://people.samba.org/bzr/jelmer/bzr-git/trunk
Jelmer Vernooij
jelmer at samba.org
Sat Jul 26 17:27:38 BST 2008
At http://people.samba.org/bzr/jelmer/bzr-git/trunk
------------------------------------------------------------
revno: 58
revision-id: jelmer at samba.org-20080726125912-52f3yj0dsqin5ugb
parent: jelmer at samba.org-20080726002424-tvazkvugrgtgyonh
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: trunk
timestamp: Sat 2008-07-26 14:59:12 +0200
message:
Fix remaining tests.
modified:
git_branch.py git_branch.py-20071108230535-su8dxk529f4uk9fx-2
git_dir.py git_dir.py-20071108234408-ygidvy5hviixghsd-1
git_repository.py git_repository.py-20071108234408-ygidvy5hviixghsd-2
tests/test_git_branch.py test_git_branch.py-20071108234408-ygidvy5hviixghsd-3
=== modified file 'git_branch.py'
--- a/git_branch.py 2008-07-26 00:24:24 +0000
+++ b/git_branch.py 2008-07-26 12:59:12 +0000
@@ -64,15 +64,18 @@
# perhaps should escape this ?
if self.head is None:
return revision.NULL_REVISION
- return ids.convert_revision_id_git_to_bzr(self.head.commit.id)
+ return ids.convert_revision_id_git_to_bzr(self.head)
def _gen_revision_history(self):
+ if self.head is None:
+ return []
skip = 0
+ cms = None
+ ret = []
max_count = 1000
- cms = []
- ret = []
while cms != []:
- cms = self.repository._git.commits(self.head.commit.id, max_count=1000, skip=skip)
+ cms = self.repository._git.commits(self.head, max_count=max_count, skip=skip)
+ skip += max_count
ret += [ids.convert_revision_id_git_to_bzr(cm.id) for cm in cms]
return ret
=== modified file 'git_dir.py'
--- a/git_dir.py 2008-07-26 00:24:24 +0000
+++ b/git_dir.py 2008-07-26 12:59:12 +0000
@@ -85,7 +85,7 @@
if repo._git.heads == []:
head = None
else:
- head = repo._git.heads[0]
+ head = repo._git.heads[0].commit.id
return git_branch.GitBranch(repo, head,
self.root_transport.base, self._lockfiles)
=== modified file 'git_repository.py'
--- a/git_repository.py 2008-07-26 00:24:24 +0000
+++ b/git_repository.py 2008-07-26 12:59:12 +0000
@@ -275,8 +275,12 @@
def __init__(self, repository, revision_id):
self._repository = repository
+ self.revision_id = revision_id
git_id = ids.convert_revision_id_bzr_to_git(revision_id)
self.tree = repository._git.commit(git_id).tree
+ self._inventory = inventory.Inventory(revision_id=revision_id)
+ self._inventory.root.revision = revision_id
+ self._build_inventory(self.tree, self._inventory.root, "")
def get_file_lines(self, file_id):
entry = self._inventory[file_id]
@@ -286,6 +290,38 @@
return self._inventory.git_file_data[git_id]
return self._repository._get_blob(git_id)
+ def _build_inventory(self, tree, ie, path):
+ assert isinstance(path, str)
+ for b in tree.contents:
+ basename = b.name.decode("utf-8")
+ if path == "":
+ child_path = b.name
+ else:
+ child_path = urlutils.join(path, b.name)
+ file_id = escape_file_id(child_path.encode('utf-8'))
+ if b.mode[0] == '0':
+ child_ie = inventory.InventoryDirectory(file_id, basename, ie.file_id)
+ elif b.mode[0] == '1':
+ if b.mode[1] == '0':
+ child_ie = inventory.InventoryFile(file_id, basename, ie.file_id)
+ child_ie.text_sha1 = osutils.sha_string(b.data)
+ elif b.mode[1] == '2':
+ child_ie = inventory.InventoryLink(file_id, basename, ie.file_id)
+ child_ie.text_sha1 = osutils.sha_string("")
+ else:
+ raise AssertionError(
+ "Unknown file kind, perms=%r." % (b.mode,))
+ child_ie.text_size = b.size
+ else:
+ raise AssertionError(
+ "Unknown blob kind, perms=%r." % (b.mode,))
+ child_ie.executable = bool(int(b.mode[3:], 8) & 0111)
+ child_ie.revision = self.revision_id
+ assert not basename in ie.children
+ ie.children[basename] = child_ie
+ if b.mode[0] == '0':
+ self._build_inventory(b, child_ie, child_path)
+
class GitFormat(object):
=== modified file 'tests/test_git_branch.py'
--- a/tests/test_git_branch.py 2007-12-26 20:13:49 +0000
+++ b/tests/test_git_branch.py 2008-07-26 12:59:12 +0000
@@ -55,3 +55,15 @@
thebranch = branch.Branch.open('.')
self.assertEqual(ids.convert_revision_id_git_to_bzr(head),
thebranch.last_revision())
+
+ def test_revision_history(self):
+ tests.run_git('init')
+ self.build_tree(['a'])
+ tests.run_git('add', 'a')
+ tests.run_git('commit', '-m', 'a')
+ head = tests.run_git('rev-parse', 'HEAD').strip()
+
+ thebranch = branch.Branch.open('.')
+ self.assertEqual([ids.convert_revision_id_git_to_bzr(head)],
+ thebranch.revision_history())
+
More information about the bazaar-commits
mailing list