Changeset 3202
- Timestamp:
- 02/09/08 05:15:03 (10 months ago)
- Files:
-
- gitplugin/0.11/gitplugin/git_fs.py (modified) (2 diffs)
- gitplugin/0.11/gitplugin/PyGIT.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gitplugin/0.11/gitplugin/git_fs.py
r3197 r3202 39 39 self._version = None 40 40 41 try: 42 self._version = PyGIT.git_version() 43 except PyGIT.GitError, e: 44 self.log.error("GitError: "+e.message) 45 46 if self._version: 47 self.log.info("detected GIT version %s" % self._version['v_str']) 48 self.env.systeminfo.append(('GIT', self._version['v_str'])) 49 if self._version['v_compatible']: 50 self.log.error("GIT version %s installed not compatible (need >= %s)" % 51 (self._version['v_str'], self._version['v_min_str'])) 52 41 53 def _format_sha_link(self, formatter, ns, sha, label, fullmatch=None): 42 54 try: … … 92 104 """GitRepository factory method""" 93 105 if not self._version: 94 self._version = PyGIT.git_version() 95 self.env.systeminfo.append(('GIT', self._version)) 106 raise TracError("GIT backend not available") 107 elif not self._version['v_compatible']: 108 raise TracError("GIT version %s installed not compatible (need >= %s)" % 109 (self._version['v_str'], self._version['v_min_str'])) 96 110 97 111 options = dict(self.config.options(type)) gitplugin/0.11/gitplugin/PyGIT.py
r3200 r3202 17 17 #from traceback import print_stack 18 18 19 _profile_git_calls = False20 21 19 class GitError(Exception): 22 20 pass … … 25 23 pass 26 24 25 GIT_CMD = "git" 26 GIT_VERSION_MIN_REQUIRED = (1,5,2) 27 GIT_PROFILE = False 28 29 def _git_execute(gitcmd, git_dir=None, *args): 30 if GIT_PROFILE: 31 t = time.time() 32 33 # construct command tuple 34 cmd = [GIT_CMD] 35 if git_dir: 36 cmd.append('--git-dir=%s' % git_dir) 37 cmd.append(gitcmd) 38 cmd.extend(args) 39 40 # fds = (input, output, error) 41 fds = os.popen3(cmd) 42 43 if GIT_PROFILE: 44 t = time.time() - t # doesn't work actually, as popen3 runs async 45 print >>sys.stderr, "GIT: took %6.2fs for '%s'" % (t, cmd) 46 pass 47 48 return fds 49 27 50 def git_version(): 28 51 try: 29 (input, output, error) = os.popen3('git --version')52 output = _git_execute("version")[1] 30 53 [v] = output.readlines() 31 [a,b,c] = v.strip().split() 32 return c 54 [a,b,version] = v.strip().split() 55 split_version = tuple(map(int, version.split('.'))) 56 57 result = {} 58 result['v_str'] = version 59 result['v_tuple'] = split_version 60 result['v_min_tuple'] = GIT_VERSION_MIN_REQUIRED 61 result['v_min_str'] = ".".join(map(str, GIT_VERSION_MIN_REQUIRED)) 62 result['v_compatible'] = split_version >= GIT_VERSION_MIN_REQUIRED 63 return result 33 64 except: 34 raise GitError 65 raise GitError("Could not retrieve GIT version") 35 66 36 67 class StorageFactory: … … 84 115 def __del__(self): 85 116 self.logger.debug("PyGIT.Storage instance %d destructed" % id(self)) 117 118 def _git_call_f(self, gitcmd, args=[]): 119 (input, output, error) = _git_execute(gitcmd, self.repo, *args) 120 return output 121 122 def _git_call(self, cmd, args=[]): 123 return self._git_call_f(cmd, args).read() 86 124 87 125 def _invalidate_caches(self,youngest_rev=None): … … 190 228 return self.history_relative_rev(sha, +1) 191 229 192 def _git_call_f(self, gitcmd, args=[]):193 #print "GIT: "+cmd194 if _profile_git_calls:195 t = time.time()196 pass197 198 cmd = ["git", '--git-dir=%s' % self.repo, gitcmd]199 cmd.extend(args)200 201 (input, output, error) = os.popen3(cmd)202 203 if _profile_git_calls:204 t = time.time() - t # doesn't work actually, as popen3 runs async205 print >>sys.stderr, "GIT: took %6.2fs for '%s'" % (t, cmd)206 pass207 208 return output209 210 def _git_call(self, cmd, args=[]):211 return self._git_call_f(cmd, args).read()212 213 230 def get_commit_encoding(self): 214 231 if self.commit_encoding is None: … … 258 275 for e in self._git_call_f("branch", ["-v", "--no-abbrev"]).readlines(): 259 276 (bname,bsha)=e[1:].strip().split()[:2] 260 if e [0]=='*':277 if e.startswith('*'): 261 278 result.insert(0,(bname,bsha)) 262 279 else: … … 381 398 assert line 382 399 if in_metadata: 383 in_metadata = line[0] != '\t'400 in_metadata = not line.startswith('\t') 384 401 else: 385 402 split_line = line.split() … … 430 447 if __name__ == '__main__': 431 448 import sys, logging 449 450 print "git version [%s]" % str(git_version()) 432 451 433 452 g = Storage(sys.argv[1], logging)
