Fix repo prune to work on git 1.6.1-rc3~5 and later

Prior to git 1.6.1-rc3~5 the output of 'git branch -d' matched:

  Deleted branch (.*)\.

where the subgroup grabbed the branch name. In v1.6.1-rc3~5 (aka
a126ed0a01e265d7f3b2972a34e85636e12e6d34) Brandon Casey changed
the output to include the SHA-1 of the branch name, now matching
the pattern:

  Deleted branch (.*) \([0-9a-f]*\)\.

Instead of parsing the output of git branch we now re-obtain the
list of branches after the deletion attempt and perform a set
difference in memory to determine which branches we were able to
successfully delete.

Bug: REPO-9
Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
Shawn O. Pearce 2009-03-02 12:30:50 -08:00
parent 993eedf9fa
commit 3778f9d47e

View File

@ -770,7 +770,8 @@ class Project(object):
""" """
cb = self.CurrentBranch cb = self.CurrentBranch
kill = [] kill = []
for name in self._allrefs.keys(): left = self._allrefs
for name in left.keys():
if name.startswith(R_HEADS): if name.startswith(R_HEADS):
name = name[len(R_HEADS):] name = name[len(R_HEADS):]
if cb is None or name != cb: if cb is None or name != cb:
@ -783,14 +784,12 @@ class Project(object):
self.work_git.DetachHead(HEAD) self.work_git.DetachHead(HEAD)
kill.append(cb) kill.append(cb)
deleted = set()
if kill: if kill:
try: try:
old = self.bare_git.GetHead() old = self.bare_git.GetHead()
except GitError: except GitError:
old = 'refs/heads/please_never_use_this_as_a_branch_name' old = 'refs/heads/please_never_use_this_as_a_branch_name'
rm_re = re.compile(r"^Deleted branch (.*)\.$")
try: try:
self.bare_git.DetachHead(rev) self.bare_git.DetachHead(rev)
@ -802,14 +801,12 @@ class Project(object):
b.Wait() b.Wait()
finally: finally:
self.bare_git.SetHead(old) self.bare_git.SetHead(old)
left = self._allrefs
for line in b.stdout.split("\n"): for branch in kill:
m = rm_re.match(line) if (R_HEADS + branch) not in left:
if m:
deleted.add(m.group(1))
if deleted:
self.CleanPublishedCache() self.CleanPublishedCache()
break
if cb and cb not in kill: if cb and cb not in kill:
kill.append(cb) kill.append(cb)
@ -817,7 +814,7 @@ class Project(object):
kept = [] kept = []
for branch in kill: for branch in kill:
if branch not in deleted: if (R_HEADS + branch) in left:
branch = self.GetBranch(branch) branch = self.GetBranch(branch)
base = branch.LocalMerge base = branch.LocalMerge
if not base: if not base: