Ticket #261: buildbot_branch_deletions.diff

File buildbot_branch_deletions.diff, 5.0 KB (added by nhemingway, 4 years ago)

Patch to resolve #261

  • buildbot/changes/svnpoller.py

    Sat May  3 22:25:20 BST 2008  Neil Hemingway <neil.hemingway@greyhavens.org.uk>
      * #261: Recognise branch deletions
    diff -rN -u old-buildbot_pristine/buildbot/changes/svnpoller.py new-buildbot_pristine/buildbot/changes/svnpoller.py
    old new  
    402402            branches = {} 
    403403            pathlist = el.getElementsByTagName("paths")[0] 
    404404            for p in pathlist.getElementsByTagName("path"): 
     405                action = p.getAttribute("action") 
    405406                path = "".join([t.data for t in p.childNodes]) 
    406407                # the rest of buildbot is certaily not yet ready to handle 
    407408                # unicode filenames, because they get put in RemoteCommands 
     
    411412                if path.startswith("/"): 
    412413                    path = path[1:] 
    413414                where = self._transform_path(path) 
     415 
    414416                # if 'where' is None, the file was outside any project that 
    415417                # we care about and we should ignore it 
    416418                if where: 
    417419                    branch, filename = where 
    418420                    if not branch in branches: 
    419                         branches[branch] = [] 
    420                     branches[branch].append(filename) 
     421                        branches[branch] = { 'files': []} 
     422                    branches[branch]['files'].append(filename) 
     423 
     424                    if not branches[branch].has_key('action'): 
     425                        branches[branch]['action'] = action 
     426 
     427            for branch in branches.keys(): 
     428                action = branches[branch]['action'] 
     429                files  = branches[branch]['files'] 
     430                number_of_files_changed = len(files) 
    421431 
    422             for branch in branches: 
    423                 c = Change(who=author, 
    424                            files=branches[branch], 
    425                            comments=comments, 
    426                            revision=revision, 
    427                            branch=branch) 
    428                 changes.append(c) 
     432                if action == u'D' and number_of_files_changed == 1 and files[0] == '': 
     433                    log.msg("Ignoring deletion of branch '%s'" % branch) 
     434                else: 
     435                    c = Change(who=author, 
     436                               files=files, 
     437                               comments=comments, 
     438                               revision=revision, 
     439                               branch=branch) 
     440                    changes.append(c) 
    429441 
    430442        return changes 
    431443 
  • buildbot/test/test_svnpoller.py

    diff -rN -u old-buildbot_pristine/buildbot/test/test_svnpoller.py new-buildbot_pristine/buildbot/test/test_svnpoller.py
    old new  
    117117# output from svn log on .../SVN-Repository/sample 
    118118# (so it includes trunk and branches) 
    119119sample_base = "file:///usr/home/warner/stuff/Projects/BuildBot/trees/misc/_trial_temp/test_vc/repositories/SVN-Repository/sample" 
    120 sample_logentries = [None] * 4 
     120sample_logentries = [None] * 6 
     121 
     122sample_logentries[5] = """\ 
     123<logentry 
     124   revision="6"> 
     125<author>warner</author> 
     126<date>2006-10-01T19:35:16.165664Z</date> 
     127<paths> 
     128<path 
     129   action="D">/sample/branch/version.c</path> 
     130</paths> 
     131<msg>revised_to_2</msg> 
     132</logentry> 
     133""" 
     134 
     135sample_logentries[4] = """\ 
     136<logentry 
     137   revision="5"> 
     138<author>warner</author> 
     139<date>2006-10-01T19:35:16.165664Z</date> 
     140<paths> 
     141<path 
     142   action="D">/sample/branch</path> 
     143</paths> 
     144<msg>revised_to_2</msg> 
     145</logentry> 
     146""" 
    121147 
    122148sample_logentries[3] = """\ 
    123149<logentry 
     
    293319        self.failUnlessEqual(changes[0].revision, '4') 
    294320        self.failUnlessEqual(changes[0].files, ["version.c"]) 
    295321 
     322        # and now pull in r5 (should *not* create a change as it's a 
     323        # branch deletion 
     324        doc = s.parse_logs(make_changes_output(5)) 
     325        newlast, logentries = s._filter_new_logentries(doc, newlast) 
     326        self.failUnlessEqual(newlast, 5) 
     327        # so we see revision 5 as being new 
     328        changes = s.create_changes(logentries) 
     329        self.failUnlessEqual(len(changes), 0) 
     330 
     331        # and now pull in r6 (should create a change as it's not 
     332        # deleting an entire branch 
     333        doc = s.parse_logs(make_changes_output(6)) 
     334        newlast, logentries = s._filter_new_logentries(doc, newlast) 
     335        self.failUnlessEqual(newlast, 6) 
     336        # so we see revision 6 as being new 
     337        changes = s.create_changes(logentries) 
     338        self.failUnlessEqual(len(changes), 1) 
     339        self.failUnlessEqual(changes[0].branch, 'branch') 
     340        self.failUnlessEqual(changes[0].revision, '6') 
     341        self.failUnlessEqual(changes[0].files, ["version.c"]) 
     342 
    296343    def testFirstTime(self): 
    297344        base = "file:///home/warner/stuff/Projects/BuildBot/trees/svnpoller/_trial_temp/test_vc/repositories/SVN-Repository/sample" 
    298345        s = SVNPoller(base, split_file=split_file)