From 67b01c133fea32df4041ef68cb6d6f4d8fa1189e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Karl=20Hasselstr=C3=B6m?= Date: Sun, 21 Sep 2008 14:17:41 +0200 Subject: [PATCH] Don't write a log entry if there were no changes MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Some commands end up calling log_entry() without verifying that they did in fact change anything. (One example of this is a conflicting push, which will log two entries, everything else and the conflicting push, with the "everything else" part being empty if there was only one patch to push.) So before appending to the log, make sure that the entry we're appending isn't a no-op. Signed-off-by: Karl Hasselström --- stgit/commands/reset.py | 3 ++- stgit/lib/log.py | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/stgit/commands/reset.py b/stgit/commands/reset.py index 6db9559..593ed30 100644 --- a/stgit/commands/reset.py +++ b/stgit/commands/reset.py @@ -119,7 +119,8 @@ def func(parser, options, args): stack = directory.repository.current_stack if len(args) >= 1: ref, patches = args[0], args[1:] - state = log.get_log_entry(stack.repository, ref) + state = log.get_log_entry(stack.repository, ref, + stack.repository.rev_parse(ref)) else: raise common.CmdException('Wrong number of arguments') return reset_stack(stack, stack.repository.default_iw, state, patches, diff --git a/stgit/lib/log.py b/stgit/lib/log.py index f4e079e..9568e8f 100644 --- a/stgit/lib/log.py +++ b/stgit/lib/log.py @@ -286,24 +286,36 @@ class LogEntry(object): tree = tree, message = self.message, parents = [self.simplified] + parents)) -def get_log_entry(repo, ref): +def get_log_entry(repo, ref, commit): try: - return LogEntry.from_commit(repo, repo.rev_parse(ref)) + return LogEntry.from_commit(repo, commit) except LogException, e: raise LogException('While reading log from %s: %s' % (ref, e)) +def same_state(log1, log2): + """Check whether two log entries describe the same current state.""" + s = [[lg.head, lg.applied, lg.unapplied, lg.hidden, lg.patches] + for lg in [log1, log2]] + return s[0] == s[1] + def log_entry(stack, msg): """Write a new log entry for the stack.""" ref = log_ref(stack.name) try: - last_log = stack.repository.refs.get(ref) + last_log_commit = stack.repository.refs.get(ref) except KeyError: - last_log = None + last_log_commit = None try: + if last_log_commit: + last_log = get_log_entry(stack.repository, ref, last_log_commit) + else: + last_log = None new_log = LogEntry.from_stack(last_log, stack, msg) except LogException, e: out.warn(str(e), 'No log entry written.') return + if last_log and same_state(last_log, new_log): + return new_log.write_commit() stack.repository.refs.set(ref, new_log.commit, msg) -- 2.11.0