echangelog: Improve vcs detection, might fix bug 302784 as well.
authoridl0r <idl0r@gentoo.org>
Mon, 1 Feb 2010 19:15:14 +0000 (19:15 -0000)
committeridl0r <idl0r@gentoo.org>
Mon, 1 Feb 2010 19:15:14 +0000 (19:15 -0000)
svn path=/trunk/gentoolkit-dev/; revision=736

ChangeLog
src/echangelog/echangelog

index 58a2b4571ec39d2f37f0041c508208a377c3d4f8..b0b8c20f089e1a71434299fed87f6950f3840836 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-01-02: Christian Ruppert <idl0r@gentoo.org>
+       src/echangelog/echangelog: Improve vcs detection, might fix bug 302784 as
+       well.
+
 2009-12-11: Christian Ruppert <idl0r@gentoo.org>
        src/echangelog/test/test.sh, src/echangelog/Makefile:
                Fix bug 292932, thanks to Alexis Ballier <aballier@gentoo.org>.
index 8767a1910f4ad263ac1af81c93f217334d903280..9c3818fc2411421db096bc9af7c594260a4b40a1 100755 (executable)
@@ -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(<BZR>);
-                       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(<GIT>);
-                       close(GIT);
-                       last if $vcs;
-               }
-               if ( -X "${path}/hg" ) {
-                       open(HG, '-|', "${path}/hg root 2>/dev/null");
-                       $vcs = "hg" if defined(<HG>);
-                       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 (<C>) {
                }
        }
        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*)/;