From 7a70b6d61ee5d05535d7559ca6e8452f57ff3336 Mon Sep 17 00:00:00 2001
From: Stan Hu <stanhu@gmail.com>
Date: Sun, 8 May 2016 18:20:53 -0700
Subject: [PATCH] Remove extraneous newlines in pre-receive hook

Found while investigating slow performance in gitlab-org/gitlab-ce#17225

We were adding a newline for every branch push because:

1. GitlabAccess calls changes.lines, which keeps the newline (e.g. ['00000000 12345678 refs/heads/master\n'])
2. GitlabNet calls changes.join("\n"), which adds another newline
---
 CHANGELOG                  | 1 +
 lib/gitlab_access.rb       | 2 +-
 spec/gitlab_access_spec.rb | 4 ++--
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 63b04cc..a15aefd 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,4 +1,5 @@
 v3.0.0
+  - Remove extraneous newlines in pre-receive hook
   - Remove rm-tag command (Robert Schilling)
   - Remove create-branch and rm-branch commands (Robert Schilling)
   - Update PostReceive worker so it logs a unique JID in Sidekiq
diff --git a/lib/gitlab_access.rb b/lib/gitlab_access.rb
index 5816969..bb6bc58 100644
--- a/lib/gitlab_access.rb
+++ b/lib/gitlab_access.rb
@@ -16,7 +16,7 @@ class GitlabAccess
     @repo_path = repo_path.strip
     @actor = actor
     @repo_name = extract_repo_name(@repo_path.dup, config.repos_path.to_s)
-    @changes = changes.lines
+    @changes = changes.split("\n")
   end
 
   def exec
diff --git a/spec/gitlab_access_spec.rb b/spec/gitlab_access_spec.rb
index 4768c71..58f654d 100644
--- a/spec/gitlab_access_spec.rb
+++ b/spec/gitlab_access_spec.rb
@@ -11,7 +11,7 @@ describe GitlabAccess do
     end
   end
   subject do
-    GitlabAccess.new(repo_path, 'key-123', 'wow').tap do |access|
+    GitlabAccess.new(repo_path, 'key-123', "first\nsecond\n").tap do |access|
       access.stub(exec_cmd: :exec_called)
       access.stub(api: api)
     end
@@ -24,7 +24,7 @@ describe GitlabAccess do
   describe :initialize do
     it { subject.repo_name.should == repo_name }
     it { subject.repo_path.should == repo_path }
-    it { subject.changes.should == ['wow'] }
+    it { subject.changes.should == ['first', 'second'] }
   end
 
   describe "#exec" do
-- 
GitLab