X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=buildscripts%2Fgit-update-changelog.py;h=09f0d16b7afebad8214b9463cef4076fdc5f1301;hb=43a6adb6e391c5269c26565f406dbc86395b29ee;hp=95c45592c901b62d15645cdd6def475043f6db5d;hpb=233b4e7d0c05222c5b596a51334553e25a9864b7;p=lilypond.git diff --git a/buildscripts/git-update-changelog.py b/buildscripts/git-update-changelog.py index 95c45592c9..09f0d16b7a 100644 --- a/buildscripts/git-update-changelog.py +++ b/buildscripts/git-update-changelog.py @@ -17,6 +17,15 @@ def system (x): class PatchFailed(Exception): pass +def sign (x): + if x < 0: + return -1 + if x > 0: + return 1 + + return 0 + + class Commit: def __init__ (self, dict): for v in ('message', @@ -32,6 +41,46 @@ class Commit: self.email = m.group (2).strip () self.name = m.group (1).strip () 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 + if not os.path.exists (filename): + return False + + 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 = [] @@ -127,16 +176,13 @@ Apply GIT patches and update change log. Run this file from the CVS directory, with commits from the repository in --git-dir. - - - """) p.add_option ("--start", action='store', default='', - metavar="FIRST" + metavar="FIRST", dest="start", - help="all commits starting with FIRST.") + help="all commits starting with FIRST (exclusive).") p.add_option ("--git-dir", action='store', @@ -173,21 +219,40 @@ Run this file from the CVS directory, with commits from the repository in --git- if first == log[:len (first)]: log = log[len (first):] - file_adddel = [] + try: + previously_done = dict((c, 1) for c in open ('.git-commits-done').read ().split ('\n')) + except IOError: + previously_done = {} + + commits = [c for c in commits if not previously_done.has_key (c.committish)] + commits = sorted (commits, cmp=Commit.compare) + + system ('cvs up') + 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) @@ -232,7 +297,8 @@ Run this file from the CVS directory, with commits from the repository in --git- open ('.msg','w').write (collated_message) print '\nCommit message\n**\n%s\n**\n' % collated_message print '\nRun:\n\n\tcvs commit -F .msg\n\n' - print '\n\techo %s >> .git-commits-done\n\n' % ' '.join (commits_done) + print '\n\techo %s >> .git-commits-done\n\n' % ' '.join ([c.committish + for c in commits_done]) if commits: