Permalink
Browse files

GitPlugin: added new option `git_bin` for providing a custom `git`

binary; made `git version` parsing more tolerant; minor fixes
  • Loading branch information...
1 parent 495f90e commit 2d904cfc37d527cadaea9ade1319866f0edf59b9 @hvr committed Feb 26, 2008
Showing with 35 additions and 16 deletions.
  1. +24 −10 tracext/git/PyGIT.py
  2. +11 −6 tracext/git/git_fs.py
View
@@ -92,14 +92,14 @@ class StorageFactory:
__dict_nonweak = dict()
__dict_lock = Lock()
- def __init__(self, repo, log, weak=True):
+ def __init__(self, repo, log, weak=True, git_bin='git'):
self.logger = log
with StorageFactory.__dict_lock:
try:
i = StorageFactory.__dict[repo]
except KeyError:
- i = Storage(repo, log)
+ i = Storage(repo, log, git_bin)
StorageFactory.__dict[repo] = i
# create or remove additional reference depending on 'weak' argument
@@ -132,14 +132,25 @@ def __rev_key(rev):
return srev_key
@staticmethod
- def git_version():
+ def git_version(git_bin="git"):
GIT_VERSION_MIN_REQUIRED = (1,5,2)
try:
- g = GitCore()
+ g = GitCore(git_bin=git_bin)
output = g.version()
[v] = output.readlines()
- [a,b,version] = v.strip().split()
- split_version = tuple(map(int, version.split('.')))
+ _,_,version = v.strip().split()
+ # 'version' has usually at least 3 numeric version components, e.g.::
+ # 1.5.4.2
+ # 1.5.4.3.230.g2db511
+ # 1.5.4.GIT
+
+ def try_int(s):
+ try:
+ return int(s)
+ except ValueError:
+ return s
+
+ split_version = tuple(map(try_int, version.split('.')))
result = {}
result['v_str'] = version
@@ -151,7 +162,7 @@ def git_version():
except:
raise GitError("Could not retrieve GIT version")
- def __init__(self, git_dir, log):
+ def __init__(self, git_dir, log, git_bin='git'):
self.logger = log
# simple sanity checking
@@ -167,7 +178,7 @@ def __init__(self, git_dir, log):
self.logger.debug("PyGIT.Storage instance %d constructed" % id(self))
- self.repo = GitCore(git_dir)
+ self.repo = GitCore(git_dir, git_bin=git_bin)
self.commit_encoding = None
@@ -226,7 +237,7 @@ def __rev_reuse(rev):
rev = str(rev)
return __rev_seen.setdefault(rev, rev)
- ord_rev = 0
+ rev = ord_rev = 0
for revs in self.repo.rev_list("--parents", "--all").readlines():
revs = revs.strip().split()
@@ -429,7 +440,10 @@ def fullrev(self, srev):
if not GitCore.is_sha(srev):
return None
- srevs = sdb[self.__rev_key(srev)]
+ try:
+ srevs = sdb[self.__rev_key(srev)]
+ except KeyError:
+ return None
srevs = filter(lambda s: s.startswith(srev), srevs)
if len(srevs) == 1:
View
@@ -20,7 +20,7 @@
from trac.wiki import IWikiSyntaxProvider
from trac.versioncontrol.cache import CachedRepository
from trac.versioncontrol.web_ui import IPropertyRenderer
-from trac.config import BoolOption, IntOption
+from trac.config import BoolOption, IntOption, PathOption, Option
# for some reason CachedRepository doesn't pass-through short_rev()s
class CachedRepository2(CachedRepository):
@@ -63,7 +63,7 @@ def __init__(self):
self._version = None
try:
- self._version = PyGIT.Storage.git_version()
+ self._version = PyGIT.Storage.git_version(git_bin=self._git_bin)
except PyGIT.GitError, e:
self.log.error("GitError: "+e.message)
@@ -134,9 +134,12 @@ def get_link_resolvers(self):
"wrap `GitRepository` in `CachedRepository`")
_shortrev_len = IntOption('git', 'shortrev_len', 7,
- "length rev sha sums should be tried to abbreviated to"
+ "length rev sha sums should be tried to be abbreviated to"
" (must be >= 4 and <= 40)")
+ _git_bin = PathOption('git', 'git_bin', 'git', "file name of git executable")
+
+
def get_supported_types(self):
yield ("git", 8)
@@ -152,6 +155,7 @@ def get_repository(self, type, dir, authname):
repos = GitRepository(dir, self.log,
persistent_cache=self._persistent_cache,
+ git_bin=self._git_bin,
shortrev_len=self._shortrev_len)
if self._cached_repository:
@@ -163,12 +167,13 @@ def get_repository(self, type, dir, authname):
return repos
class GitRepository(Repository):
- def __init__(self, path, log, persistent_cache=False, shortrev_len=7):
+ def __init__(self, path, log, persistent_cache=False, git_bin='git', shortrev_len=7):
self.logger = log
self.gitrepo = path
self._shortrev_len = max(4, min(shortrev_len, 40))
- self.git = PyGIT.StorageFactory(path, log, not persistent_cache).getInstance()
+ self.git = PyGIT.StorageFactory(path, log, not persistent_cache,
+ git_bin=git_bin).getInstance()
Repository.__init__(self, "git:"+path, None, log)
def close(self):
@@ -190,7 +195,7 @@ def normalize_path(self, path):
return path and path.strip('/') or ''
def normalize_rev(self, rev):
- if not rev or rev=='None':
+ if not rev:
return self.get_youngest_rev()
normrev=self.git.verifyrev(rev)
if normrev is None:

0 comments on commit 2d904cf

Please sign in to comment.