summaryrefslogtreecommitdiff
path: root/app/models/commit.rb
diff options
context:
space:
mode:
authorRiyad Preukschas <riyad@informatik.uni-bremen.de>2012-11-22 20:49:01 +0100
committerRiyad Preukschas <riyad@informatik.uni-bremen.de>2012-11-22 20:49:01 +0100
commit246faa3d7a60ea2296a24d0c5de1a71a7a48854b (patch)
treec07f9228974a6d43d67eb944b6aa54e9476139da /app/models/commit.rb
parent8b4010397caf09a9db6759dd7be989d4dc4cfdcd (diff)
downloadgitlab-ce-246faa3d7a60ea2296a24d0c5de1a71a7a48854b.tar.gz
Add Commit#to_diff for raw diff
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r--app/models/commit.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 5efb20cea3b..200c915a335 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -150,4 +150,19 @@ class Commit
def parents_count
parents && parents.count || 0
end
+
+ # Shows the diff between the commit's parent and the commit.
+ #
+ # Cuts out the header and stats from #to_patch and returns only the diff.
+ def to_diff
+ # see Grit::Commit#show
+ patch = to_patch
+
+ # discard lines before the diff
+ lines = patch.split("\n")
+ while !lines.first.start_with?("diff --git") do
+ lines.shift
+ end
+ lines.join("\n")
+ end
end