From 66c92acb3d5a0f60b3e6edd006161191dbd53f60 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sun, 30 Dec 2007 12:36:43 -0800 Subject: [PATCH] Make the commit browser properly handle merge commits The commit browser was not properly checking if a commit was a merge. In those cases, it would not display the entire contents of the commit. A new method was added to handle this case and hooked into the utilcontroller. Signed-off by: David Aguilar --- ugitlibs/git.py | 11 ++++++++--- ugitlibs/models.py | 11 +++++++++++ ugitlibs/utilcontroller.py | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ugitlibs/git.py b/ugitlibs/git.py index 0b8d571..19c501d 100644 --- a/ugitlibs/git.py +++ b/ugitlibs/git.py @@ -127,7 +127,7 @@ def current_branch(): def diff(commit=None,filename=None, color=False, cached=True, with_diff_header=False, - reverse=False): + suppress_header=True, reverse=False): "Invokes git diff on a filepath." argv = [ 'diff'] @@ -156,9 +156,14 @@ def diff(commit=None,filename=None, color=False, if not start and '@@ ' in line and ' @@' in line: start = True if start or(deleted and del_tag in line): - output.write(line + '\n') + output.write(line) + output.write(os.linesep) else: - headers.append(line) + if with_diff_header: + headers.append(line) + elif not suppress_header: + output.write(line) + output.write(os.linesep) result = output.getvalue() output.close() diff --git a/ugitlibs/models.py b/ugitlibs/models.py index 39536ee..fbc1c4b 100644 --- a/ugitlibs/models.py +++ b/ugitlibs/models.py @@ -247,6 +247,17 @@ class Model(model.Model): def get_revision_sha1(self, idx): return self.get_revisions()[idx] + def get_commit_diff(self, sha1): + commit = self.show(sha1) + first_newline = commit.index(os.linesep) + merge = commit[first_newline+1:].startswith('Merge:') + if merge: + return (commit + os.linesep*2 + + self.diff(commit=sha1, cached=False, + suppress_header=False)) + else: + return commit + def get_unstaged_item(self, idx): return self.get_all_unstaged()[idx] diff --git a/ugitlibs/utilcontroller.py b/ugitlibs/utilcontroller.py index fc8a1f9..71e2e29 100644 --- a/ugitlibs/utilcontroller.py +++ b/ugitlibs/utilcontroller.py @@ -62,7 +62,7 @@ class SelectCommitsController(QObserver): self.view.revisionLine.selectAll() # Lookup the sha1's commit - commit_diff = self.model.diff(commit=sha1,cached=False) + commit_diff = self.model.get_commit_diff(sha1) self.view.commitText.setText(commit_diff) # Copy the sha1 into the clipboard -- 2.11.4.GIT