From 9ee861ae7a7b36a811aa4b5cc8172c5cbd6a945b Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 5 Nov 2009 17:59:30 +0100 Subject: Added utilities helping to create proper paths either with slashes or backslashes depending on the operating system fixed test_refs and test_trees Many more issues remain though, this is just a first backup commit --- lib/git/objects/base.py | 8 +++++--- lib/git/objects/tree.py | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'lib/git/objects') diff --git a/lib/git/objects/base.py b/lib/git/objects/base.py index b0989a43..c66263c0 100644 --- a/lib/git/objects/base.py +++ b/lib/git/objects/base.py @@ -4,7 +4,7 @@ # This module is part of GitPython and is released under # the BSD License: http://www.opensource.org/licenses/bsd-license.php import os -from git.utils import LazyMixin +from git.utils import LazyMixin, join_path_native import utils _assertion_msg_format = "Created object %r whose python type %r disagrees with the acutal git object type %r" @@ -209,7 +209,9 @@ class IndexObject(Object): """ Returns Absolute path to this index object in the file system ( as opposed to the - .path field which is a path relative to the git repository ) + .path field which is a path relative to the git repository ). + + The returned path will be native to the system and contains '\' on windows. """ - return os.path.join(self.repo.git.git_dir, self.path) + return join_path_native(self.repo.git.git_dir, self.path) diff --git a/lib/git/objects/tree.py b/lib/git/objects/tree.py index 27bd84d0..f88096b3 100644 --- a/lib/git/objects/tree.py +++ b/lib/git/objects/tree.py @@ -9,6 +9,7 @@ import blob import base import binascii import git.diff as diff +from git.utils import join_path def sha_to_hex(sha): """Takes a string and returns the hex of the sha within""" @@ -110,7 +111,7 @@ class Tree(base.IndexObject, diff.Diffable): i += 1 # END while not reached NULL name = data[ns:i] - path = os.path.join(self.path, name) + path = join_path(self.path, name) # byte is NULL, get next 20 i += 1 -- cgit v1.2.1 From 4114d19e2c02f3ffca9feb07b40d9475f36604cc Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Fri, 6 Nov 2009 11:09:14 +0100 Subject: Fixed commit.count method which now handles the paths case properly. It appears git-rev-list uses empty paths in some way, which is quite hard to specify on a shell, but easy if the process is spawned directly --- lib/git/objects/commit.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/git/objects') diff --git a/lib/git/objects/commit.py b/lib/git/objects/commit.py index 80b3ad23..4ec806fb 100644 --- a/lib/git/objects/commit.py +++ b/lib/git/objects/commit.py @@ -116,7 +116,13 @@ class Commit(base.Object, Iterable, diff.Diffable): Returns int """ - return len(self.repo.git.rev_list(self.sha, '--', paths, **kwargs).strip().splitlines()) + # yes, it makes a difference whether empty paths are given or not in our case + # as the empty paths version will ignore merge commits for some reason. + if paths: + return len(self.repo.git.rev_list(self.sha, '--', paths, **kwargs).splitlines()) + else: + return len(self.repo.git.rev_list(self.sha, **kwargs).splitlines()) + @property def name_rev(self): -- cgit v1.2.1