diff options
author | Shawn O. Pearce <sop@google.com> | 2009-03-02 12:30:50 -0800 |
---|---|---|
committer | Shawn O. Pearce <sop@google.com> | 2009-03-02 12:38:36 -0800 |
commit | 3778f9d47e876aa15d3fdcc84ef21ec07c63402e (patch) | |
tree | 50567255e8aff349763f0b5740c0a834870acbb8 /project.py | |
parent | 993eedf9fabfad3e929a9161d00db4ae7d9c551c (diff) | |
download | git-repo-3778f9d47e876aa15d3fdcc84ef21ec07c63402e.tar.gz |
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>
Diffstat (limited to 'project.py')
-rw-r--r-- | project.py | 19 |
1 files changed, 8 insertions, 11 deletions
@@ -770,7 +770,8 @@ class Project(object): | |||
770 | """ | 770 | """ |
771 | cb = self.CurrentBranch | 771 | cb = self.CurrentBranch |
772 | kill = [] | 772 | kill = [] |
773 | for name in self._allrefs.keys(): | 773 | left = self._allrefs |
774 | for name in left.keys(): | ||
774 | if name.startswith(R_HEADS): | 775 | if name.startswith(R_HEADS): |
775 | name = name[len(R_HEADS):] | 776 | name = name[len(R_HEADS):] |
776 | if cb is None or name != cb: | 777 | if cb is None or name != cb: |
@@ -783,14 +784,12 @@ class Project(object): | |||
783 | self.work_git.DetachHead(HEAD) | 784 | self.work_git.DetachHead(HEAD) |
784 | kill.append(cb) | 785 | kill.append(cb) |
785 | 786 | ||
786 | deleted = set() | ||
787 | if kill: | 787 | if kill: |
788 | try: | 788 | try: |
789 | old = self.bare_git.GetHead() | 789 | old = self.bare_git.GetHead() |
790 | except GitError: | 790 | except GitError: |
791 | old = 'refs/heads/please_never_use_this_as_a_branch_name' | 791 | old = 'refs/heads/please_never_use_this_as_a_branch_name' |
792 | 792 | ||
793 | rm_re = re.compile(r"^Deleted branch (.*)\.$") | ||
794 | try: | 793 | try: |
795 | self.bare_git.DetachHead(rev) | 794 | self.bare_git.DetachHead(rev) |
796 | 795 | ||
@@ -802,14 +801,12 @@ class Project(object): | |||
802 | b.Wait() | 801 | b.Wait() |
803 | finally: | 802 | finally: |
804 | self.bare_git.SetHead(old) | 803 | self.bare_git.SetHead(old) |
804 | left = self._allrefs | ||
805 | 805 | ||
806 | for line in b.stdout.split("\n"): | 806 | for branch in kill: |
807 | m = rm_re.match(line) | 807 | if (R_HEADS + branch) not in left: |
808 | if m: | 808 | self.CleanPublishedCache() |
809 | deleted.add(m.group(1)) | 809 | break |
810 | |||
811 | if deleted: | ||
812 | self.CleanPublishedCache() | ||
813 | 810 | ||
814 | if cb and cb not in kill: | 811 | if cb and cb not in kill: |
815 | kill.append(cb) | 812 | kill.append(cb) |
@@ -817,7 +814,7 @@ class Project(object): | |||
817 | 814 | ||
818 | kept = [] | 815 | kept = [] |
819 | for branch in kill: | 816 | for branch in kill: |
820 | if branch not in deleted: | 817 | if (R_HEADS + branch) in left: |
821 | branch = self.GetBranch(branch) | 818 | branch = self.GetBranch(branch) |
822 | base = branch.LocalMerge | 819 | base = branch.LocalMerge |
823 | if not base: | 820 | if not base: |