From: Han-Wen Nienhuys <hanwen@xs4all.nl>
Date: Sun, 5 Nov 2006 23:15:15 +0000 (+0000)
Subject: check whether removals from a diff actually apply.
X-Git-Tag: release/2.10.0-2~26^2~7
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=b8abac1a954c71271a713fdfbd9a11d63e1b1d25;p=lilypond.git

check whether removals from a diff actually apply.
update todo/done after rejection due to removal analysis.
---

diff --git a/ChangeLog b/ChangeLog
index cfac4b5bf1..f5d4ec0ea1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-11-05  Han-Wen Nienhuys  <hanwen@lilypond.org>
+
+	* buildscripts/git-update-changelog.py: 
+	update todo/done after rejection due to removal analysis.
+
+	* buildscripts/git-update-changelog.py: 
+	check whether removals from a diff actually apply.
+
 2006-11-05  Joe Neeman  <joeneeman@gmail.com>
 
 	* lily/include/page-turn-page-breaking.hh: remove unused
diff --git a/buildscripts/git-update-changelog.py b/buildscripts/git-update-changelog.py
index 4b98c6c199..35dd2e6c75 100644
--- a/buildscripts/git-update-changelog.py
+++ b/buildscripts/git-update-changelog.py
@@ -43,6 +43,41 @@ class Commit:
         self.diff = read_pipe ('git show %s' % self.committish)
     def compare (self, other):
         return sign (time.mktime (self.date) - time.mktime (other.date))
+
+    def check_diff_chunk (self, filename, chunk):
+        removals = []
+        def note_removal (m):
+            removals.append (m.group (1))
+            
+        re.sub ('\n-([^\n]+)', note_removal, chunk)
+
+        if removals == []:
+            return True
+        
+        contents = open (filename).read ()
+        for r in removals:
+            if r not in contents:
+                return False
+
+        return True
+
+    def check_diff (self):
+        chunks = re.split ('\ndiff --git ', self.diff)
+
+        ok = True
+        for c in chunks:
+            m = re.search ('^a/([^ ]+)', c)
+            if not m:
+                continue
+            
+            file = m.group (1)
+            
+            c = re.sub('\n--- [^\n]+', '', c)
+            ok = ok and self.check_diff_chunk (file, c)
+            if not ok:
+                break
+
+        return ok
         
     def touched_files (self):
         files = []
@@ -189,6 +224,7 @@ Run this file from the CVS directory, with commits from the repository in --git-
     except OSError:
         previously_done = {}
 
+    commits = [c for c in commits if not previously_done.has_key (c.committish)]
     commits = [c for c in commits if not previously_done.has_key (c.committish)]
     commits = sorted (commits, cmp=Commit.compare)
 
@@ -196,18 +232,27 @@ Run this file from the CVS directory, with commits from the repository in --git-
     file_adddel = []
     collated_log = ''
     collated_message = ''
-
     commits_done = []
     while commits:
         c = commits[0]
-        commits = commits[1:]
         
-        commits_done.append (c) 
-
         if not c.has_patch ():
             print 'patchless commit (merge?)'
             continue
-        
+
+        ok = c.check_diff ()
+
+        if not ok:
+            print "Patch doesn't seem to apply"
+            print 'skipping', c.committish
+            print 'message:', c.message
+
+            break
+
+
+        commits = commits[1:]
+        commits_done.append (c) 
+            
         print 'patch ', c.committish
         try:
             c.apply (file_adddel)