Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
GitDownloadStrategy optimization
Browse files Browse the repository at this point in the history
The current series of fetch invocations in GitDownloadStrategy has the
unfortunate behavior of fetching full history even in shallow clones
that only need the history between the clone point and the remote HEAD.
It should be possible to determine if it is actually necessary to fetch
the full history, including all tags, and if it is not to avoid this
overhead.

Fixes #11958, and several other recurring problems.

Signed-off-by: Jack Nagel <[email protected]>
  • Loading branch information
jacknagel committed May 2, 2012
1 parent 853a8de commit 7718c93
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
4 changes: 2 additions & 2 deletions Library/Formula/git-multipush.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ class GitMultipush < Formula
url 'http://git-multipush.googlecode.com/files/git-multipush-2.3.tar.bz2'
sha1 'a53f171af5e794afe9b1de6ccd9bd0661db6fd91'

head 'https://github.com/gavinbeatty/git-multipush.git', :sha => 'HEAD'
head 'https://github.com/gavinbeatty/git-multipush.git', :revision => 'HEAD'

depends_on 'asciidoc' => :build if ARGV.build_head?

def install
if ARGV.build_head?
ENV['GIT_DIR'] = cached_location/'.git'
ENV['GIT_DIR'] = cached_download/'.git'
inreplace 'make/gen-version.mk', '.git', '$(GIT_DIR)'
system "make"
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Formula/reattach-to-user-namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class ReattachToUserNamespace < Formula
head 'https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard.git'
homepage 'https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard'
url 'https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard.git', :tag => 'dadea0aa48259c704d0b412b9588de2f5623e323'
url 'https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard.git', :revision => 'dadea0aa48259c704d0b412b9588de2f5623e323'
version 'dadea0'

def options
Expand Down
2 changes: 1 addition & 1 deletion Library/Formula/topgit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Topgit < Formula
homepage 'http://repo.or.cz/w/topgit.git'
url 'git://repo.or.cz/topgit.git', :tag => '1744aca50f3d7b6b4863523207e5010e112dfb85'
url 'git://repo.or.cz/topgit.git', :revision => '1744aca50f3d7b6b4863523207e5010e112dfb85'
version '0.8'

def install
Expand Down
43 changes: 27 additions & 16 deletions Library/Homebrew/download_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,10 @@ def cached_location
end

def support_depth?
!commit_history_required? and depth_supported_host?
@spec != :revision and host_supports_depth?
end

def commit_history_required?
@spec == :sha
end

def depth_supported_host?
def host_supports_depth?
@url =~ %r(git://) or @url =~ %r(https://github.com/)
end

Expand All @@ -352,16 +348,31 @@ def fetch

unless @clone.exist?
# Note: first-time checkouts are always done verbosely
git_args = %w(git clone)
git_args << "--depth" << "1" if support_depth?
git_args << @url << @clone
safe_system(*git_args)
clone_args = %w[git clone]
clone_args << '--single-branch'
clone_args << '--depth' << '1' if support_depth?

case @spec
when :branch, :tag
clone_args << '--branch' << @ref
end

clone_args << @url << @clone
safe_system(*clone_args)
else
puts "Updating #{@clone}"
Dir.chdir(@clone) do
safe_system 'git', 'remote', 'set-url', 'origin', @url
quiet_safe_system 'git', 'fetch', 'origin'
quiet_safe_system 'git', 'fetch', '--tags' if @spec == :tag
safe_system 'git', 'config', 'remote.origin.url', @url

safe_system 'git', 'config', 'remote.origin.fetch', case @spec
when :branch then "+refs/heads/#{@ref}:refs/remotes/origin/#{@ref}"
when :tag then "+refs/tags/#{@ref}:refs/tags/#{@ref}"
else '+refs/heads/master:refs/remotes/origin/master'
end

git_args = %w[git fetch origin]
git_args << '--depth' << '1' if support_depth?
quiet_safe_system(*git_args)
end
end
end
Expand All @@ -373,9 +384,9 @@ def stage
ohai "Checking out #{@spec} #{@ref}"
case @spec
when :branch
nostdout { quiet_safe_system 'git', 'checkout', "origin/#{@ref}" }
when :tag, :sha
nostdout { quiet_safe_system 'git', 'checkout', @ref }
nostdout { quiet_safe_system 'git', 'checkout', "origin/#{@ref}", '--' }
when :tag, :revision
nostdout { quiet_safe_system 'git', 'checkout', @ref, '--' }
end
else
# otherwise the checkout-index won't checkout HEAD
Expand Down

0 comments on commit 7718c93

Please sign in to comment.