Project

General

Profile

Bug #12239 ยป 0001-improve-git-repository-detection.patch

rhenium (Kazuki Yamaguchi), 03/31/2016 05:38 PM

View differences:

configure.in
4464 4464
	    :
4465 4465
	elif svn info "$srcdir" > /dev/null 2>&1; then
4466 4466
	    VCS='svn'
4467
	elif test -d "$srcdir/.git/svn"; then
4468
	    VCS='git svn'
4469
	elif test -d "$srcdir/.git"; then
4470
	    VCS='git'
4467
	elif git_dir=`git --work-tree="$srcdir" --git-dir="$srcdir/.git" rev-parse --git-dir 2>/dev/null`; then
4468
	    if test -d "$git_dir/svn"; then
4469
		VCS='git svn'
4470
	    else
4471
		VCS='git'
4472
	    fi
4471 4473
	else
4472 4474
	    VCS='echo cannot'
4473 4475
	fi
tool/change_maker.rb
1 1
#! ./miniruby
2 2

  
3
$:.unshift(File.expand_path("../../lib", __FILE__))
4
require File.expand_path("../vcs", __FILE__)
5

  
3 6
def diff2index(cmd, *argv)
4 7
  lines = []
5 8
  path = nil
......
22 25
  lines.empty? ? nil : lines
23 26
end
24 27

  
25
if `svnversion` =~ /^\d+/
28
vcs = begin
29
  VCS.detect(".")
30
rescue VCS::NotFoundError
31
  nil
32
end
33

  
34
case vcs
35
when VCS::SVN
26 36
  cmd = "svn diff --diff-cmd=diff -x-pU0"
27 37
  change = diff2index(cmd, ARGV)
28
elsif File.directory?(".git")
38
when VCS::GIT
29 39
  cmd = "git diff -U0"
30 40
  change = diff2index(cmd, ARGV) || diff2index(cmd, "--cached", ARGV)
31 41
else
tool/vcs.rb
73 73

  
74 74
  def self.detect(path)
75 75
    @@dirs.each do |dir, klass, pred|
76
      if pred ? pred[path, dir] : File.directory?(File.join(path, dir))
77
        return klass.new(path)
78
      end
79
      prev = path
76
      curr = path
80 77
      loop {
81
        curr = File.realpath(File.join(prev, '..'))
82
        break if curr == prev	# stop at the root directory
83
        return klass.new(path) if File.directory?(File.join(curr, dir))
84
        prev = curr
78
        return klass.new(curr) if pred ? pred[curr, dir] : File.directory?(File.join(curr, dir))
79
        prev, curr = curr, File.realpath(File.join(curr, '..'))
80
        break if curr == prev # stop at the root directory
85 81
      }
86 82
    end
87 83
    raise VCS::NotFoundError, "does not seem to be under a vcs: #{path}"