From d6a698bbff11af2312600afb708d23d69e75d8e3 Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sun, 21 Sep 2008 14:17:40 +0200 Subject: [PATCH] Log conflicts separately for all commands MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Organization: Straylight/Edgeware From: Karl Hasselström This takes care of the old-infrastructure commands as well. They'll all be converted to the new infrastructure eventually, but until then this patch is necessary to make all commands behave consistently. Signed-off-by: Karl Hasselström --- stgit/lib/log.py | 34 +++++++++++++++++++++++++++++++++- stgit/lib/stack.py | 7 +++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/stgit/lib/log.py b/stgit/lib/log.py index 124fbcf..f4e079e 100644 --- a/stgit/lib/log.py +++ b/stgit/lib/log.py @@ -307,6 +307,34 @@ def log_entry(stack, msg): new_log.write_commit() stack.repository.refs.set(ref, new_log.commit, msg) +class Fakestack(object): + """Imitates a real L{Stack}, but with the + topmost patch popped.""" + def __init__(self, stack): + appl = list(stack.patchorder.applied) + unappl = list(stack.patchorder.unapplied) + hidd = list(stack.patchorder.hidden) + class patchorder(object): + applied = appl[:-1] + unapplied = [appl[-1]] + unappl + hidden = hidd + all = appl + unappl + hidd + self.patchorder = patchorder + class patches(object): + @staticmethod + def get(pn): + if pn == appl[-1]: + class patch(object): + commit = stack.patches.get(pn).old_commit + return patch + else: + return stack.patches.get(pn) + self.patches = patches + self.head = stack.head.data.parent + self.top = stack.top.data.parent + self.base = stack.base + self.name = stack.name + self.repository = stack.repository def compat_log_entry(msg): """Write a new log entry. (Convenience function intended for use by code not yet converted to the new infrastructure.)""" @@ -316,7 +344,11 @@ def compat_log_entry(msg): except libstack.StackException, e: out.warn(str(e), 'Could not write to stack log') else: - log_entry(stack, msg) + if repo.default_index.conflicts() and stack.patchorder.applied: + log_entry(Fakestack(stack), msg) + log_entry(stack, msg + ' (CONFLICT)') + else: + log_entry(stack, msg) def delete_log(repo, branch): ref = log_ref(branch) diff --git a/stgit/lib/stack.py b/stgit/lib/stack.py index 31960e6..d5dbd48 100644 --- a/stgit/lib/stack.py +++ b/stgit/lib/stack.py @@ -25,6 +25,13 @@ class Patch(object): def commit(self): return self.__stack.repository.refs.get(self.__ref) @property + def old_commit(self): + """Return the previous commit for this patch.""" + fn = os.path.join(self.__compat_dir, 'top.old') + if not os.path.isfile(fn): + return None + return self.__stack.repository.get_commit(utils.read_string(fn)) + @property def __compat_dir(self): return os.path.join(self.__stack.directory, 'patches', self.__name) def __write_compat_files(self, new_commit, msg): -- [mdw]