Changeset 3199

Show
Ignore:
Timestamp:
02/08/08 15:02:16 (8 months ago)
Author:
hvr
Message:

GitPlugin: call popen3 with sequence instead of string as command, in order to avoid shell-overhead (addresses #746)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gitplugin/0.11/gitplugin/PyGIT.py

    r3197 r3199  
    109109            youngest = None 
    110110            ord_rev = 0 
    111             for revs in self._git_call_f("git-rev-parse --tags").readlines(): 
     111            for revs in self._git_call_f("rev-parse", ["--tags"]).readlines(): 
    112112                new_tags.add(revs.strip()) 
    113113 
    114             for revs in self._git_call_f("git-rev-list --parents --all").readlines(): 
     114            for revs in self._git_call_f("rev-list", ["--parents", "--all"]).readlines(): 
    115115                revs = revs.strip().split() 
    116116 
     
    152152 
    153153    def sync(self): 
    154         rev = self._git_call("git-rev-list -n1 --all").strip() 
     154        rev = self._git_call("rev-list", ["--max-count=1", "--all"]).strip() 
    155155        return self._invalidate_caches(rev) 
    156156 
     
    158158        self.get_commits() # trigger commit tree db build 
    159159        return self._commit_db[1] 
    160         #return self._git_call("git-rev-list --reverse --all | head -1").strip() 
    161160 
    162161    def youngest_rev(self): 
     
    191190        return self.history_relative_rev(sha, +1) 
    192191 
    193     def _git_call_f(self,cmd): 
     192    def _git_call_f(self, gitcmd, args=[]): 
    194193        #print "GIT: "+cmd 
    195194        if _profile_git_calls: 
     
    197196            pass 
    198197 
    199         (input, output, error) = os.popen3('GIT_DIR="%s" %s' % (self.repo,cmd)) 
     198        cmd = ["git", '--git-dir=%s' % self.repo, gitcmd] 
     199        cmd.extend(args) 
     200 
     201        (input, output, error) = os.popen3(cmd) 
    200202 
    201203        if _profile_git_calls: 
     
    206208        return output 
    207209 
    208     def _git_call(self,cmd): 
    209         return self._git_call_f(cmd).read() 
     210    def _git_call(self, cmd, args=[]): 
     211        return self._git_call_f(cmd, args).read() 
    210212 
    211213    def get_commit_encoding(self): 
    212214        if self.commit_encoding is None: 
    213             self.commit_encoding = self._git_call("git-repo-config --get i18n.commitEncoding").strip() 
     215            self.commit_encoding = self._git_call("repo-config", 
     216                                                  ["--get", "i18n.commitEncoding"]).strip() 
    214217            if ''==self.commit_encoding: 
    215218                self.commit_encoding = 'utf-8' 
     
    221224        return self.verifyrev("HEAD") 
    222225 
    223     def verifyrev(self,rev): 
     226    def verifyrev(self, rev): 
    224227        "verify/lookup given revision object and return a sha id or None if lookup failed" 
    225  
    226228        db = self.get_commits() 
    227229        tag_db = self._commit_db[2] 
     230 
     231        rev = str(rev) 
    228232 
    229233        if db.has_key(rev): 
    230234            return rev 
    231235 
    232         rc=self._git_call("git-rev-parse --verify '%s'" % rev).strip() 
     236        rc = self._git_call("rev-parse", ["--verify", rev]).strip() 
    233237        if len(rc)==0: 
    234238            return None 
     
    237241            return rc 
    238242        elif rc in tag_db: 
    239             sha=self._git_call("git-cat-file tag '%s'" % rc).split(None, 2)[:2] 
     243            sha=self._git_call("cat-file", ["tag", rc]).split(None, 2)[:2] 
    240244            if sha[0] != 'object': 
    241245                self.logger.debug("unexpected result from 'git-cat-file tag %s'" % rc) 
     
    245249        return None 
    246250 
    247     def shortrev(self,rev): 
     251    def shortrev(self, rev): 
    248252        "try to shorten sha id" 
    249         return self._git_call("git-rev-parse --short '%s'" % rev).strip() 
     253        return self._git_call("rev-parse", ["--short", str(rev)]).strip() 
    250254 
    251255    def get_branches(self): 
    252256        "returns list of branches, with active (= HEAD) one being the first item" 
    253257        result=[] 
    254         for e in self._git_call_f("git-branch -v --no-abbrev").readlines(): 
     258        for e in self._git_call_f("branch", ["-v", "--no-abbrev"]).readlines(): 
    255259            (bname,bsha)=e[1:].strip().split()[:2] 
    256260            if e[0]=='*': 
     
    262266    def get_tags(self): 
    263267        result=[] 
    264         for e in self._git_call_f("git-tag -l").readlines(): 
     268        for e in self._git_call_f("tag", ["-l"]).readlines(): 
    265269            result.append(e.strip()) 
    266270        return result 
    267271 
    268     def tree_ls(self,sha,path=""): 
    269         if len(path)>0 and path[0]=='/': 
    270             path=path[1:] 
    271         return [e[:-1].split(None, 3) for e in self._git_call_f("git-ls-tree %s '%s'" % (sha,path)).readlines()] 
     272    def tree_ls(self, rev, path=""): 
     273        rev = str(rev) # paranoia 
     274        if path.startswith('/'): 
     275            path = path[1:] 
     276        return [e.split(None, 3) for e in self._git_call("ls-tree", 
     277                                                         ["-z", rev, "--", 
     278                                                          path]).split('\0') if e] 
    272279 
    273280    def read_commit(self, sha): 
     
    280287            raise GitErrorSha 
    281288 
    282         raw = self._git_call("git-cat-file commit "+sha
     289        raw = self._git_call("cat-file", ["commit", str(sha)]
    283290        raw = unicode(raw, self.get_commit_encoding(), 'replace') 
    284291        lines = raw.splitlines() 
     
    299306 
    300307    def get_file(self, sha): 
    301         return self._git_call_f("git-cat-file blob "+sha
     308        return self._git_call_f("cat-file", ["blob", str(sha)]
    302309 
    303310    def get_obj_size(self, sha): 
    304         return int(self._git_call("git-cat-file -s "+sha).strip()) 
     311        return int(self._git_call("cat-file", ["-s", str(sha)]).strip()) 
    305312 
    306313    def children(self, sha): 
     
    342349 
    343350    def history(self, sha, path, limit=None, skip=0): 
    344         #print "history", sha, path, limit, skip 
    345351        if limit is None: 
    346352            limit = -1 
    347         for rev in self._git_call_f("git-rev-list -n%d %s -- '%s'" % (limit,sha,path)).readlines(): 
     353        for rev in self._git_call_f("rev-list",  
     354                                    ["--max-count=%d" % limit,  
     355                                     str(sha), "--", path]).readlines(): 
    348356            if(skip > 0): 
    349357                skip = skip - 1 
     
    355363 
    356364    def history_timerange(self, start, stop): 
    357         for rev in self._git_call_f("git-rev-list --reverse --max-age=%d --min-age=%d --all" \ 
    358                                         % (start,stop)).readlines(): 
     365        for rev in self._git_call_f("rev-list", ["--reverse", 
     366                                                 "--max-age=%d" % start, 
     367                                                 "--min-age=%d" % stop, 
     368                                                 "--all"]).readlines(): 
    359369            yield rev.strip() 
    360370 
     
    367377    def blame(self, commit_sha, path): 
    368378        in_metadata = False 
    369         for line in self._git_call_f("git-blame -p -- '%s' %s" \ 
    370                                          % (path, commit_sha)).readlines(): 
     379        args = ["-p", "--", path, str(commit_sha)] 
     380        for line in self._git_call_f("blame", args).readlines(): 
    371381            assert line 
    372382            if in_metadata: 
     
    386396 
    387397    def last_change(self, sha, path): 
    388         for rev in self._git_call_f("git-rev-list --max-count=1 %s -- '%s'" % (sha,path)).readlines(): 
    389             return rev.strip(
    390         return None 
     398        last_rev = self._git_call("rev-list", 
     399                                  ["--max-count=1", sha, "--", path]
     400        return last_rev.strip() 
    391401 
    392402    def diff_tree(self, tree1, tree2, path=""): 
    393403        if tree1 is None: 
    394404            tree1 = "--root" 
    395         cmd = "git-diff-tree -r %s %s -- '%s'" % (tree1, tree2, path) 
    396         for chg in self._git_call_f(cmd).readlines(): 
     405        for chg in self._git_call_f("diff-tree", ["-r", 
     406                                                  str(tree1), 
     407                                                  str(tree2), 
     408                                                  "--", path]).readlines(): 
    397409            if chg.startswith(tree2): 
    398410                continue