From 1af564f2a013ddeb47a3ba64cd28a5133afe23c3 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Fri, 25 Oct 2013 02:52:10 -0700 Subject: [PATCH] models.main: manage 'head' from within set_mode() only Remove the set_head() method and simplify callers by making set_mode() manage the 'head' variable. This is simpler since its value is always tied to the mode (amend = 'HEAD^', all others = 'HEAD'). Signed-off-by: David Aguilar --- cola/cmds.py | 7 ------- cola/models/main.py | 12 ++++++------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/cola/cmds.py b/cola/cmds.py index f51694ad..8790f449 100644 --- a/cola/cmds.py +++ b/cola/cmds.py @@ -67,17 +67,14 @@ class Command(BaseCommand): self.old_diff_text = self.model.diff_text self.old_filename = self.model.filename self.old_mode = self.model.mode - self.old_head = self.model.head self.new_diff_text = self.old_diff_text self.new_filename = self.old_filename - self.new_head = self.old_head self.new_mode = self.old_mode def do(self): """Perform the operation.""" self.model.set_filename(self.new_filename) - self.model.set_head(self.new_head) self.model.set_mode(self.new_mode) self.model.set_diff_text(self.new_diff_text) @@ -85,7 +82,6 @@ class Command(BaseCommand): """Undo the operation.""" self.model.set_diff_text(self.old_diff_text) self.model.set_filename(self.old_filename) - self.model.set_head(self.old_head) self.model.set_mode(self.old_mode) @@ -110,13 +106,11 @@ class AmendMode(Command): if self.amending: self.new_mode = self.model.mode_amend - self.new_head = 'HEAD^' self.new_commitmsg = self.model.prev_commitmsg() AmendMode.LAST_MESSAGE = self.model.commitmsg return # else, amend unchecked, regular commit self.new_mode = self.model.mode_none - self.new_head = 'HEAD' self.new_diff_text = '' self.new_commitmsg = self.model.commitmsg # If we're going back into new-commit-mode then search the @@ -287,7 +281,6 @@ class ResetMode(Command): def __init__(self): Command.__init__(self) self.new_mode = self.model.mode_none - self.new_head = 'HEAD' self.new_diff_text = '' def do(self): diff --git a/cola/models/main.py b/cola/models/main.py index 693dee79..28064888 100644 --- a/cola/models/main.py +++ b/cola/models/main.py @@ -36,7 +36,6 @@ class MainModel(Observable): message_diff_text_changed = 'diff_text_changed' message_directory_changed = 'directory_changed' message_filename_changed = 'filename_changed' - message_head_changed = 'head_changed' message_mode_about_to_change = 'mode_about_to_change' message_mode_changed = 'mode_changed' message_updated = 'updated' @@ -138,17 +137,18 @@ class MainModel(Observable): self.filename = filename self.notify_observers(self.message_filename_changed, filename) - def set_head(self, head): - self.head = head - self.notify_observers(self.message_head_changed, head) - def set_mode(self, mode): - self.notify_observers(self.message_mode_about_to_change, mode) if self.amending(): if mode != self.mode_none: return if self.is_merging and mode == self.mode_amend: mode = self.mode + if mode == self.mode_amend: + head = 'HEAD^' + else: + head = 'HEAD' + self.notify_observers(self.message_mode_about_to_change, mode) + self.head = head self.mode = mode self.notify_observers(self.message_mode_changed, mode) -- 2.11.4.GIT