Changeset 3199
- Timestamp:
- 02/08/08 15:02:16 (8 months ago)
- Files:
-
- gitplugin/0.11/gitplugin/PyGIT.py (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gitplugin/0.11/gitplugin/PyGIT.py
r3197 r3199 109 109 youngest = None 110 110 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(): 112 112 new_tags.add(revs.strip()) 113 113 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(): 115 115 revs = revs.strip().split() 116 116 … … 152 152 153 153 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() 155 155 return self._invalidate_caches(rev) 156 156 … … 158 158 self.get_commits() # trigger commit tree db build 159 159 return self._commit_db[1] 160 #return self._git_call("git-rev-list --reverse --all | head -1").strip()161 160 162 161 def youngest_rev(self): … … 191 190 return self.history_relative_rev(sha, +1) 192 191 193 def _git_call_f(self, cmd):192 def _git_call_f(self, gitcmd, args=[]): 194 193 #print "GIT: "+cmd 195 194 if _profile_git_calls: … … 197 196 pass 198 197 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) 200 202 201 203 if _profile_git_calls: … … 206 208 return output 207 209 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() 210 212 211 213 def get_commit_encoding(self): 212 214 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() 214 217 if ''==self.commit_encoding: 215 218 self.commit_encoding = 'utf-8' … … 221 224 return self.verifyrev("HEAD") 222 225 223 def verifyrev(self, rev):226 def verifyrev(self, rev): 224 227 "verify/lookup given revision object and return a sha id or None if lookup failed" 225 226 228 db = self.get_commits() 227 229 tag_db = self._commit_db[2] 230 231 rev = str(rev) 228 232 229 233 if db.has_key(rev): 230 234 return rev 231 235 232 rc =self._git_call("git-rev-parse --verify '%s'" % rev).strip()236 rc = self._git_call("rev-parse", ["--verify", rev]).strip() 233 237 if len(rc)==0: 234 238 return None … … 237 241 return rc 238 242 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] 240 244 if sha[0] != 'object': 241 245 self.logger.debug("unexpected result from 'git-cat-file tag %s'" % rc) … … 245 249 return None 246 250 247 def shortrev(self, rev):251 def shortrev(self, rev): 248 252 "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() 250 254 251 255 def get_branches(self): 252 256 "returns list of branches, with active (= HEAD) one being the first item" 253 257 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(): 255 259 (bname,bsha)=e[1:].strip().split()[:2] 256 260 if e[0]=='*': … … 262 266 def get_tags(self): 263 267 result=[] 264 for e in self._git_call_f(" git-tag -l").readlines():268 for e in self._git_call_f("tag", ["-l"]).readlines(): 265 269 result.append(e.strip()) 266 270 return result 267 271 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] 272 279 273 280 def read_commit(self, sha): … … 280 287 raise GitErrorSha 281 288 282 raw = self._git_call(" git-cat-file commit "+sha)289 raw = self._git_call("cat-file", ["commit", str(sha)]) 283 290 raw = unicode(raw, self.get_commit_encoding(), 'replace') 284 291 lines = raw.splitlines() … … 299 306 300 307 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)]) 302 309 303 310 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()) 305 312 306 313 def children(self, sha): … … 342 349 343 350 def history(self, sha, path, limit=None, skip=0): 344 #print "history", sha, path, limit, skip345 351 if limit is None: 346 352 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(): 348 356 if(skip > 0): 349 357 skip = skip - 1 … … 355 363 356 364 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(): 359 369 yield rev.strip() 360 370 … … 367 377 def blame(self, commit_sha, path): 368 378 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(): 371 381 assert line 372 382 if in_metadata: … … 386 396 387 397 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 None398 last_rev = self._git_call("rev-list", 399 ["--max-count=1", sha, "--", path]) 400 return last_rev.strip() 391 401 392 402 def diff_tree(self, tree1, tree2, path=""): 393 403 if tree1 is None: 394 404 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(): 397 409 if chg.startswith(tree2): 398 410 continue
