From: Catalin Marinas Date: Wed, 2 Sep 2009 08:48:38 +0000 (+0100) Subject: Merge commit 'kha/safe' X-Git-Tag: v0.15-rc3~5 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/stgit/commitdiff_plain/5ab0897e67b0203470690a11885b61ca1cb4ab8a?hp=8338f884c48a54c6b3c6be2c760d6b85f15f8206 Merge commit 'kha/safe' --- diff --git a/stgit/commands/squash.py b/stgit/commands/squash.py index d0be466..96b8da2 100644 --- a/stgit/commands/squash.py +++ b/stgit/commands/squash.py @@ -68,14 +68,17 @@ def _squash_patches(trans, patches, msg, save_template): return None cd = cd.set_tree(tree) if msg == None: - msg = '\n\n'.join('%s\n\n%s' % (pn.ljust(70, '-'), - trans.patches[pn].data.message) - for pn in patches) + msg = utils.append_comment( + trans.patches[patches[0]].data.message, + '\n\n'.join('%s\n\n%s' % (pn.ljust(70, '-'), + trans.patches[pn].data.message) + for pn in patches[1:])) if save_template: save_template(msg) raise SaveTemplateDone() else: - msg = utils.edit_string(msg, '.stgit-squash.txt').strip() + msg = utils.edit_string(msg, '.stgit-squash.txt') + msg = utils.strip_comment(msg).strip() cd = cd.set_message(msg) return cd diff --git a/stgit/config.py b/stgit/config.py index 6f84b10..bfb117d 100644 --- a/stgit/config.py +++ b/stgit/config.py @@ -57,7 +57,7 @@ class GitConfig: self.load() if name not in self.__cache: self.__cache[name] = [self.__defaults.get(name, None)] - return self.__cache[name][0] + return self.__cache[name][-1] def getall(self, name): self.load() diff --git a/stgit/utils.py b/stgit/utils.py index 1fa96c2..5c0e159 100644 --- a/stgit/utils.py +++ b/stgit/utils.py @@ -200,6 +200,16 @@ def edit_string(s, filename): os.remove(filename) return s +def append_comment(s, comment, separator = '---'): + return ('%s\n\n%s\nEverything following the line with "%s" will be' + ' ignored\n\n%s' % (s, separator, separator, comment)) + +def strip_comment(s, separator = '---'): + try: + return s[:s.index('\n%s\n' % separator)] + except ValueError: + return s + def find_patch_name(patchname, unacceptable): """Find a patch name which is acceptable.""" if unacceptable(patchname):