[ARVADOS] created: 4e85a19e6746eec88885926b87495e729f631d3a

Git user git at public.curoverse.com
Tue Sep 19 10:54:51 EDT 2017


        at  4e85a19e6746eec88885926b87495e729f631d3a (commit)


commit 4e85a19e6746eec88885926b87495e729f631d3a
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Tue Sep 19 10:02:47 2017 -0400

    12107: Fix test suite dependence on outer git config.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/services/api/test/unit/commit_test.rb b/services/api/test/unit/commit_test.rb
index 6a8a5b4..af365b1 100644
--- a/services/api/test/unit/commit_test.rb
+++ b/services/api/test/unit/commit_test.rb
@@ -101,10 +101,10 @@ class CommitTest < ActiveSupport::TestCase
       must_pipe("git checkout -b branch-#{rand(10**10)} 2>&1")
       must_pipe("echo -n #{tag.shellescape} >bar")
       must_pipe("git add bar")
-      must_pipe("git commit -m -")
+      must_pipe("git -c user.email=x at x -c user.name=X commit -m -")
       sha1 = must_pipe("git log -n1 --format=%H").strip
       must_pipe("git rm bar")
-      must_pipe("git commit -m -")
+      must_pipe("git -c user.email=x at x -c user.name=X commit -m -")
     end
     Commit.tag_in_internal_repository 'active/foo', sha1, tag
     gitint = "git --git-dir #{Rails.configuration.git_internal_dir.shellescape}"
@@ -118,7 +118,7 @@ class CommitTest < ActiveSupport::TestCase
     with_foo_repository do
       must_pipe("echo -n #{tag.shellescape} >bar")
       must_pipe("git add bar")
-      must_pipe("git commit -m -")
+      must_pipe("git -c user.email=x at x -c user.name=X commit -m -")
       sha1 = must_pipe("git log -n1 --format=%H").strip
       must_pipe("git reset --hard HEAD^")
     end

commit b7b42350dec7aba073df13c9cd82bafe19a9f594
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Tue Sep 19 09:56:29 2017 -0400

    12107: Fix broken commit-exists-in-internal-repo check.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/services/api/app/models/commit.rb b/services/api/app/models/commit.rb
index 32125a2..959a9f2 100644
--- a/services/api/app/models/commit.rb
+++ b/services/api/app/models/commit.rb
@@ -149,7 +149,7 @@ class Commit < ActiveRecord::Base
     dst_gitdir = Rails.configuration.git_internal_dir
 
     begin
-      commit_in_dst = must_git(dst_gitdir, "rev-parse --verify #{sha1.shellescape}^{commit}").strip
+      commit_in_dst = must_git(dst_gitdir, "log -n1 --format=%H #{sha1.shellescape}^{commit}").strip
     rescue GitError
       commit_in_dst = false
     end

commit ae931becad1e90bcecd47c6d51dc04eee632d1f5
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Tue Sep 19 09:52:02 2017 -0400

    12107: Fix broken "git branch --contains" check.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/services/api/app/models/commit.rb b/services/api/app/models/commit.rb
index aa38462..32125a2 100644
--- a/services/api/app/models/commit.rb
+++ b/services/api/app/models/commit.rb
@@ -164,7 +164,8 @@ class Commit < ActiveRecord::Base
       # is no such branch, or the branch we choose changes under us in
       # race), we fall back to pack|unpack.
       begin
-        branches = must_git("branch --contains #{sha1.shellescape}^{commit}")
+        branches = must_git(src_gitdir,
+                            "branch --contains #{sha1.shellescape}")
         m = branches.match(/^. (\w+)\n/)
         if !m
           raise GitError.new "commit is not on any branch"

commit b1b8942ee0190343dd815b895f49d3894d7f2702
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Mon Sep 18 16:46:13 2017 -0400

    12107: Test fetch-and-tag on unreferenced and non-tip commits.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/services/api/test/unit/commit_test.rb b/services/api/test/unit/commit_test.rb
index ec7a0b9..6a8a5b4 100644
--- a/services/api/test/unit/commit_test.rb
+++ b/services/api/test/unit/commit_test.rb
@@ -26,6 +26,14 @@ class CommitTest < ActiveSupport::TestCase
     end
   end
 
+  def must_pipe(cmd)
+    begin
+      return IO.read("|#{cmd}")
+    ensure
+      assert $?.success?
+    end
+  end
+
   [
    'https://github.com/curoverse/arvados.git',
    'http://github.com/curoverse/arvados.git',
@@ -79,6 +87,47 @@ class CommitTest < ActiveSupport::TestCase
     assert $?.success?
   end
 
+  def with_foo_repository
+    Dir.chdir("#{Rails.configuration.git_repositories_dir}/#{repositories(:foo).uuid}") do
+      must_pipe("git checkout master 2>&1")
+      yield
+    end
+  end
+
+  test 'tag_in_internal_repository, new non-tip sha1 in local repo' do
+    tag = "tag#{rand(10**10)}"
+    sha1 = nil
+    with_foo_repository do
+      must_pipe("git checkout -b branch-#{rand(10**10)} 2>&1")
+      must_pipe("echo -n #{tag.shellescape} >bar")
+      must_pipe("git add bar")
+      must_pipe("git commit -m -")
+      sha1 = must_pipe("git log -n1 --format=%H").strip
+      must_pipe("git rm bar")
+      must_pipe("git commit -m -")
+    end
+    Commit.tag_in_internal_repository 'active/foo', sha1, tag
+    gitint = "git --git-dir #{Rails.configuration.git_internal_dir.shellescape}"
+    assert_match(/^commit /, IO.read("|#{gitint} show #{tag.shellescape}"))
+    assert $?.success?
+  end
+
+  test 'tag_in_internal_repository, new unreferenced sha1 in local repo' do
+    tag = "tag#{rand(10**10)}"
+    sha1 = nil
+    with_foo_repository do
+      must_pipe("echo -n #{tag.shellescape} >bar")
+      must_pipe("git add bar")
+      must_pipe("git commit -m -")
+      sha1 = must_pipe("git log -n1 --format=%H").strip
+      must_pipe("git reset --hard HEAD^")
+    end
+    Commit.tag_in_internal_repository 'active/foo', sha1, tag
+    gitint = "git --git-dir #{Rails.configuration.git_internal_dir.shellescape}"
+    assert_match(/^commit /, IO.read("|#{gitint} show #{tag.shellescape}"))
+    assert $?.success?
+  end
+
   # In active/shabranchnames, "7387838c69a21827834586cc42b467ff6c63293b" is
   # both a commit hash, and the name of a branch that begins from that same
   # commit.

commit 71ad589048fec9da45253ac4480085ac5b8f5048
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Mon Sep 18 16:41:31 2017 -0400

    12107: Use a fresh internal.git repo for each test run.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/services/api/test/helpers/git_test_helper.rb b/services/api/test/helpers/git_test_helper.rb
index 19639b3..673e0e2 100644
--- a/services/api/test/helpers/git_test_helper.rb
+++ b/services/api/test/helpers/git_test_helper.rb
@@ -27,12 +27,13 @@ module GitTestHelper
       system("tar", "-xC", @tmpdir.to_s, "-f", "test/test.git.tar")
       Rails.configuration.git_repositories_dir = "#{@tmpdir}/test"
 
-      intdir = Rails.configuration.git_internal_dir
-      if not File.exist? intdir
-        FileUtils.mkdir_p intdir
-        IO.read("|git --git-dir #{intdir.to_s.shellescape} init")
-        assert $?.success?
-      end
+      # Initialize an empty internal git repo.
+      intdir =
+        Rails.configuration.git_internal_dir =
+        Rails.root.join(@tmpdir, 'internal.git').to_s
+      FileUtils.mkdir_p intdir
+      IO.read("|git --git-dir #{intdir.shellescape} init")
+      assert $?.success?
     end
 
     base.teardown do

commit 3854e6bfcd5344bce5ee0388248cb115e3c5e902
Merge: bd5a371 a6d5c9b
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Mon Sep 18 14:33:36 2017 -0400

    Merge branch 'master' into 12107-faster-git
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>


commit bd5a371cc0f57aea20c0954f532db5890dae5c59
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Wed Sep 13 09:32:46 2017 -0400

    12107: Fix unreliable use of git-fetch.
    
    Git-fetch does not fetch by sha1. If we can't find and fetch a branch
    containing the desired commit, we still need to fall back on
    pack-objects|unpack-objects.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/services/api/app/models/commit.rb b/services/api/app/models/commit.rb
index 2baf1d6..aa38462 100644
--- a/services/api/app/models/commit.rb
+++ b/services/api/app/models/commit.rb
@@ -154,11 +154,31 @@ class Commit < ActiveRecord::Base
       commit_in_dst = false
     end
 
+    tag_cmd = "tag --force #{tag.shellescape} #{sha1.shellescape}^{commit}"
     if commit_in_dst == sha1
-      must_git(dst_gitdir, "tag --force #{tag.shellescape} #{sha1.shellescape}")
+      must_git(dst_gitdir, tag_cmd)
     else
-      refspec = "#{sha1}:refs/tags/#{tag}"
-      must_git(dst_gitdir, "fetch --no-tags file://#{src_gitdir.shellescape} #{refspec.shellescape}")
+      # git-fetch is faster than pack-objects|unpack-objects, but
+      # git-fetch can't fetch by sha1. So we first try to fetch a
+      # branch that has the desired commit, and if that fails (there
+      # is no such branch, or the branch we choose changes under us in
+      # race), we fall back to pack|unpack.
+      begin
+        branches = must_git("branch --contains #{sha1.shellescape}^{commit}")
+        m = branches.match(/^. (\w+)\n/)
+        if !m
+          raise GitError.new "commit is not on any branch"
+        end
+        branch = m[1]
+        must_git(dst_gitdir,
+                 "fetch file://#{src_gitdir.shellescape} #{branch.shellescape}")
+        must_git(dst_gitdir, tag_cmd)
+      rescue GitError
+        must_pipe("echo #{sha1.shellescape}",
+                  "git --git-dir #{src_gitdir.shellescape} pack-objects -q --revs --stdout",
+                  "git --git-dir #{dst_gitdir.shellescape} unpack-objects -q")
+        must_git(dst_gitdir, tag_cmd)
+      end
     end
   end
 

commit 32341a4777692a28358f2af5afa0d9e975e2da73
Author: Tom Clegg <tclegg at veritasgenetics.com>
Date:   Thu Sep 7 22:12:12 2017 -0400

    12107: Use git-fetch instead of pack|unpack, and only when needed.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg at veritasgenetics.com>

diff --git a/services/api/app/models/commit.rb b/services/api/app/models/commit.rb
index 1d9a821..2baf1d6 100644
--- a/services/api/app/models/commit.rb
+++ b/services/api/app/models/commit.rb
@@ -129,8 +129,8 @@ class Commit < ActiveRecord::Base
   end
 
   # Given a repository (url, or name of hosted repo) and commit sha1,
-  # copy the commit into the internal git repo and tag it with the
-  # given tag (typically a job UUID).
+  # copy the commit into the internal git repo (if necessary), and tag
+  # it with the given tag (typically a job UUID).
   #
   # The repo can be a remote url, but in this case sha1 must already
   # be present in our local cache for that repo: e.g., sha1 was just
@@ -147,11 +147,19 @@ class Commit < ActiveRecord::Base
       raise ArgumentError.new "no local repository for #{repo_name}"
     end
     dst_gitdir = Rails.configuration.git_internal_dir
-    must_pipe("echo #{sha1.shellescape}",
-              "git --git-dir #{src_gitdir.shellescape} pack-objects -q --revs --stdout",
-              "git --git-dir #{dst_gitdir.shellescape} unpack-objects -q")
-    must_git(dst_gitdir,
-             "tag --force #{tag.shellescape} #{sha1.shellescape}")
+
+    begin
+      commit_in_dst = must_git(dst_gitdir, "rev-parse --verify #{sha1.shellescape}^{commit}").strip
+    rescue GitError
+      commit_in_dst = false
+    end
+
+    if commit_in_dst == sha1
+      must_git(dst_gitdir, "tag --force #{tag.shellescape} #{sha1.shellescape}")
+    else
+      refspec = "#{sha1}:refs/tags/#{tag}"
+      must_git(dst_gitdir, "fetch --no-tags file://#{src_gitdir.shellescape} #{refspec.shellescape}")
+    end
   end
 
   protected
@@ -213,14 +221,16 @@ class Commit < ActiveRecord::Base
     # Clear token in case a git helper tries to use it as a password.
     orig_token = ENV['ARVADOS_API_TOKEN']
     ENV['ARVADOS_API_TOKEN'] = ''
+    last_output = ''
     begin
       git = "git --git-dir #{gitdir.shellescape}"
       cmds.each do |cmd|
-        must_pipe git+" "+cmd
+        last_output = must_pipe git+" "+cmd
       end
     ensure
       ENV['ARVADOS_API_TOKEN'] = orig_token
     end
+    return last_output
   end
 
   def self.must_pipe *cmds
@@ -229,5 +239,6 @@ class Commit < ActiveRecord::Base
     if not $?.success?
       raise GitError.new "#{cmd}: #{$?}: #{out}"
     end
+    return out
   end
 end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list