From e61db11a618864330b2ae70f868c5fd6fa6f5bbc Mon Sep 17 00:00:00 2001 From: idl0r Date: Mon, 1 Feb 2010 19:15:14 +0000 Subject: [PATCH] echangelog: Improve vcs detection, might fix bug 302784 as well. svn path=/trunk/gentoolkit-dev/; revision=736 --- ChangeLog | 4 +++ src/echangelog/echangelog | 53 ++++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 58a2b45..b0b8c20 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2010-01-02: Christian Ruppert + src/echangelog/echangelog: Improve vcs detection, might fix bug 302784 as + well. + 2009-12-11: Christian Ruppert src/echangelog/test/test.sh, src/echangelog/Makefile: Fix bug 292932, thanks to Alexis Ballier . diff --git a/src/echangelog/echangelog b/src/echangelog/echangelog index 8767a19..9c3818f 100755 --- a/src/echangelog/echangelog +++ b/src/echangelog/echangelog @@ -33,6 +33,7 @@ my $opt_strict = 0; my %vcs = ( bzr => { + directory => ".bzr", diff => "bzr diff", status => "bzr status -S .", add => "bzr add", @@ -41,6 +42,7 @@ my %vcs = ( regex => qr/^=== \S+ file '\S+\/\S+\/((\S+)\.ebuild)/ }, cvs => { + directory => "CVS", diff => "cvs -f diff -U0", status => "cvs -fn up", add => "cvs -f add", @@ -48,6 +50,7 @@ my %vcs = ( regex => qr/^Index: (([^\/]*?)\.ebuild)\s*$/ }, git => { + directory => ".git", diff => "git diff", status => "git diff-index HEAD --name-status", add => "git add", @@ -57,6 +60,7 @@ my %vcs = ( regex => qr/^diff \-\-git \S*\/((\S*)\.ebuild)/ }, hg => { + directory => ".hg", diff => "hg diff", status => "hg status .", add => "hg add", @@ -66,6 +70,7 @@ my %vcs = ( regex => qr/diff \-r \S+ \S+\/\S+\/((\S+)\.ebuild)/ }, svn => { + directory => ".svn", diff => "svn diff -N", status => "svn status", add => "svn add", @@ -175,6 +180,21 @@ sub update_cat_pn { return $t; } +# Check partent dirs recursivevly/backward +sub check_vcs_dir { + my $type = shift; + + my $dir = getcwd(); + while($dir !~ /^\/$/) { + return 1 if -d "${dir}/${type}"; + $dir = dirname($dir); + } + # Check / as well + return 1 if -d "/${type}"; + + return 0; +} + # Just to ensure we don't get duplicate entries. sub mypush(\@@) { my $aref = shift; @@ -203,32 +223,13 @@ if($opt_strict) { # Respect $PATH while looking for the VCS if (getenv("PATH")) { foreach my $path ( split(":", getenv("PATH")) ) { - if ( -X "${path}/bzr" ) { - open(BZR, '-|', "${path}/bzr root 2>/dev/null"); - $vcs = "bzr" if defined(); - close(BZR); - last if $vcs; - } - if ( -X "${path}/cvs" ) { - $vcs = "cvs" if -d "CVS"; - last if $vcs; - } - if ( -X "${path}/git" ) { - open(GIT, '-|', "${path}/git rev-parse --git-dir 2>/dev/null"); - $vcs = "git" if defined(); - close(GIT); - last if $vcs; - } - if ( -X "${path}/hg" ) { - open(HG, '-|', "${path}/hg root 2>/dev/null"); - $vcs = "hg" if defined(); - close(HG); - last if $vcs; - } - if ( -X "${path}/svn" ) { - $vcs = "svn" if -d ".svn"; - last if $vcs; + foreach my $_vcs (keys(%vcs)) { + if ( -X "${path}/${_vcs}" ) { + $vcs = $_vcs if check_vcs_dir($vcs{$_vcs}{directory}); + last if $vcs; + } } + last if $vcs; } } @@ -305,7 +306,7 @@ while () { } } if (/^C\s+(\S+)/) { - # TODO: The git part here might be unused + # NOTE: The git part here might be unused if($vcs eq "git") { my $filename = $1; $filename =~ /\S*\/(\S*)/; -- 2.26.2