The following commit has been merged in the master branch:
commit b08ea6174d0b057cae166fc8d020873aede6886a
Author: Evan Broder <e...@ebroder.net>
Date:   Thu Dec 8 11:21:43 2011 +0100

    Check git and debian/changelog before showing dummy version number
    
    This should ensure that lintian --version prints out something
    reasonable if it's run from a source tree.
    
    Based on the original patch with the following changes:
     * Do not load IPC::Run, Parse::DebianChangelog or File::Basename
       unless they are needed for guessing the version.
     * Moved the "version-guessing" code into a sub.
     * Guarded the guesses with eval - "just in case".
    
    Acked-by: Niels Thykier <ni...@thykier.net>

diff --git a/debian/changelog b/debian/changelog
index af96d13..1676f05 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -61,6 +61,9 @@ lintian (2.5.5) UNRELEASED; urgency=low
       status of some collections.
     + [NT] Keep auto-cleaned collections until all processables in
       the group has been checked.
+    + [NT] Attempt guess the version number when running in an git
+      checkout or unpacked source dir.  Based on patch from Evan
+      Broder.  (Closes: #650701)
   * frontend/lintian-info:
     + [NT] Support new lintian.log format.
     + [NT] Support new override file format with -a.
diff --git a/debian/rules b/debian/rules
index feaaf11..fb7159c 100755
--- a/debian/rules
+++ b/debian/rules
@@ -97,7 +97,7 @@ binary-indep: $(neededfiles) build
 
        dh_install
 # some manual work
-       sed -i 's/<VERSION>/$(VER)/' $(tmp)/usr/bin/lintian
+       sed -i 's/my $$LINTIAN_VERSION = "<VERSION>"/my $$LINTIAN_VERSION = 
"$(VER)"/' $(tmp)/usr/bin/lintian
        install -m 644 doc/lintianrc.example $(tmp)/etc/lintianrc
        dh_installdocs
        dh_installchangelogs
diff --git a/frontend/lintian b/frontend/lintian
index d9ab54c..e16c5ed 100755
--- a/frontend/lintian
+++ b/frontend/lintian
@@ -73,7 +73,15 @@ qw(
 ### "Normal" application variables
 
 # Version number - Is replaced during build with sed, see d/rules
-my $LINTIAN_VERSION = '<VERSION>';      #External Version number
+my $LINTIAN_VERSION = "<VERSION>";      #External Version number
+if ($LINTIAN_VERSION eq '<VERSION>') {
+    # For some reason the version above has not be substituted.
+    # Most likely this means we are a git clone or an unpacked
+    # source package.  If so, we will use a version that best
+    # describes our situation...
+    my $guess = _guess_version (__FILE__);
+    $LINTIAN_VERSION = $guess if $guess;
+}
 my $BANNER = "Lintian v$LINTIAN_VERSION"; #Version Banner - text form
 
 # Variables used to record commandline options
@@ -1723,6 +1731,37 @@ sub handle_lab_query {
     }
 }
 
+sub _guess_version {
+    require File::Basename;
+    require Cwd;
+    my ($frontend) = @_;
+    my $guess;
+    my $absfront = Cwd::abs_path ($frontend);
+    my $rootdir;
+    return '' unless $absfront;
+    $rootdir = File::Basename::dirname (File::Basename::dirname ($absfront));
+
+    if ( -d "$rootdir/.git" ) {
+        # Lets try git
+        eval {
+            require IPC::Run;
+            IPC::Run::run (['git', "--git-dir=$rootdir/.git", 'describe'], 
\undef, \$guess);
+            chomp $guess;
+        };
+        return $guess if $guess;
+    }
+    # git was not possible - maybe the changelog is available
+    if ( -f "$rootdir/debian/changelog" ) {
+        eval {
+            my $changelog = Parse::DebianChangelog->init({ infile => 
dirname(__FILE__) . "/../debian/changelog" });
+            $guess = $changelog->dpkg()->{'Version'} if $changelog;
+        };
+        return $guess if $guess;
+    }
+    # Out of guesses ...
+    return;
+}
+
 # }}}
 
 # {{{ Exit handler.

-- 
Debian package checker


-- 
To UNSUBSCRIBE, email to debian-lint-maint-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/e1ryahd-0000ma...@vasks.debian.org

Reply via email to