ruby-changes:42394
From: nobu <ko1@a...>
Date: Fri, 1 Apr 2016 13:58:56 +0900 (JST)
Subject: [ruby-changes:42394] nobu:r54468 (trunk): improve git repository detection
nobu 2016-04-01 14:55:30 +0900 (Fri, 01 Apr 2016) New Revision: 54468 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54468 Log: improve git repository detection * configure.in (AC_CONFIG_FILES): $srcdir/.git can be a file pointing the real git_dir, such as when the git working tree is a "linked working tree" (a working tree created by git-worktree). So use git-rev-parse --git-dir to check if $srcdir is the top-level of a git repository, not just checking if the $srcdir/.git directory does exist or not. [ruby-core:74759] [Bug #12239] * tool/change_maker.rb: use tool/vcs.rb to detect VCS. This used to have its own VCS detection code, while we have tool/vcs.rb. * tool/vcs.rb (detect): remove code duplication Modified files: trunk/ChangeLog trunk/configure.in trunk/tool/change_maker.rb trunk/tool/vcs.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 54467) +++ ChangeLog (revision 54468) @@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Apr 1 14:55:28 2016 Kazuki Yamaguchi <k@r...> + + * configure.in (AC_CONFIG_FILES): $srcdir/.git can be a file pointing + the real git_dir, such as when the git working tree is a "linked + working tree" (a working tree created by git-worktree). So use + git-rev-parse --git-dir to check if $srcdir is the top-level of a git + repository, not just checking if the $srcdir/.git directory does exist + or not. [ruby-core:74759] [Bug #12239] + + * tool/change_maker.rb: use tool/vcs.rb to detect VCS. This used to have + its own VCS detection code, while we have tool/vcs.rb. + + * tool/vcs.rb (detect): remove code duplication + Fri Apr 1 04:50:44 2016 Eric Wong <e@8...> * ext/openssl/ossl_ssl.c (ossl_sslctx_s_alloc): Index: tool/vcs.rb =================================================================== --- tool/vcs.rb (revision 54467) +++ tool/vcs.rb (revision 54468) @@ -73,15 +73,11 @@ class VCS https://github.com/ruby/ruby/blob/trunk/tool/vcs.rb#L73 def self.detect(path) @@dirs.each do |dir, klass, pred| - if pred ? pred[path, dir] : File.directory?(File.join(path, dir)) - return klass.new(path) - end - prev = path + curr = path loop { - curr = File.realpath(File.join(prev, '..')) - break if curr == prev # stop at the root directory - return klass.new(path) if File.directory?(File.join(curr, dir)) - prev = curr + return klass.new(curr) if pred ? pred[curr, dir] : File.directory?(File.join(curr, dir)) + prev, curr = curr, File.realpath(File.join(curr, '..')) + break if curr == prev # stop at the root directory } end raise VCS::NotFoundError, "does not seem to be under a vcs: #{path}" Index: tool/change_maker.rb =================================================================== --- tool/change_maker.rb (revision 54467) +++ tool/change_maker.rb (revision 54468) @@ -1,5 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/tool/change_maker.rb#L1 #! ./miniruby +$:.unshift(File.expand_path("../../lib", __FILE__)) +require File.expand_path("../vcs", __FILE__) + def diff2index(cmd, *argv) lines = [] path = nil @@ -22,10 +25,17 @@ def diff2index(cmd, *argv) https://github.com/ruby/ruby/blob/trunk/tool/change_maker.rb#L25 lines.empty? ? nil : lines end -if `svnversion` =~ /^\d+/ +vcs = begin + VCS.detect(".") +rescue VCS::NotFoundError + nil +end + +case vcs +when VCS::SVN cmd = "svn diff --diff-cmd=diff -x-pU0" change = diff2index(cmd, ARGV) -elsif File.directory?(".git") +when VCS::GIT cmd = "git diff -U0" change = diff2index(cmd, ARGV) || diff2index(cmd, "--cached", ARGV) else Index: configure.in =================================================================== --- configure.in (revision 54467) +++ configure.in (revision 54468) @@ -4464,10 +4464,12 @@ AC_CONFIG_FILES(Makefile, [ https://github.com/ruby/ruby/blob/trunk/configure.in#L4464 : elif svn info "$srcdir" > /dev/null 2>&1; then VCS='svn' - elif test -d "$srcdir/.git/svn"; then - VCS='git svn' - elif test -d "$srcdir/.git"; then - VCS='git' + elif git_dir=`git --work-tree="$srcdir" --git-dir="$srcdir/.git" rev-parse --git-dir 2>/dev/null`; then + if test -d "$git_dir/svn"; then + VCS='git svn' + else + VCS='git' + fi else VCS='echo cannot' fi -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/