Changeset 1536

Show
Ignore:
Timestamp:
11/11/06 03:04:33 (2 years ago)
Author:
hvr
Message:

GitPlugin:

some minor changes to allow for using branch names (and possibly also tag names) instead of revision numbers (e.g. in the View revision entry field);

see #789

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gitplugin/0.10/gitplugin/git_fs.py

    r1321 r1536  
    1616from trac.util import TracError, shorten_line, escape 
    1717from trac.versioncontrol import Changeset, Node, Repository, \ 
    18                                 IRepositoryConnector 
     18                                IRepositoryConnector, NoSuchChangeset, NoSuchNode 
    1919 
    2020import PyGIT 
     
    4444                if rev=='None' or rev == None or rev == '': 
    4545                        return self.get_youngest_rev() 
    46                 return rev 
     46                normrev=self.git.verifyrev(rev) 
     47                if normrev is None: 
     48                        raise NoSuchChangeset(rev) 
     49                return normrev 
     50 
     51        def short_rev(self, rev): 
     52                return self.git.shortrev(self.normalize_rev(rev)) 
    4753 
    4854        def get_oldest_rev(self): 
  • gitplugin/0.10/gitplugin/PyGIT.py

    r1380 r1536  
    1414 
    1515import os, re 
     16#from traceback import print_stack 
    1617 
    1718class GitError(Exception): 
     
    3940 
    4041    def head(self): 
    41         return self._git_call("git-rev-parse --verify HEAD").strip() 
     42        "get current HEAD commit id" 
     43        return self.verifyrev("HEAD") 
     44 
     45    def verifyrev(self,rev): 
     46        "verify/lookup given revision object and return a sha id or None if lookup failed" 
     47        rc=self._git_call("git-rev-parse --verify '%s'" % rev).strip() 
     48        if len(rc)==0: 
     49            return None 
     50        return rc 
     51 
     52    def shortrev(self,rev): 
     53        "try to shorten sha id" 
     54        return self._git_call("git-rev-parse --short '%s'" % rev).strip() 
     55 
     56    def get_branches(self): 
     57        "returns list of branches, with active (i.e. HEAD) one being the first item" 
     58        result=[] 
     59        for e in self._git_call_f("git-branch").readlines(): 
     60            bname=e[1:].strip() 
     61            if e[0]=='*': 
     62                result.insert(0,bname) 
     63            else: 
     64                result.append(bname) 
     65        return result 
    4266 
    4367    def tree_ls(self,sha,path=""): 
     
    118142    print "--------------" 
    119143    print g.get_commit_encoding() 
     144    print "--------------" 
     145    print g.get_branches()