← Back to team overview

launchpad-reviewers team mailing list archive

Re: [Merge] lp:~cjwatson/launchpad/git-version-info into lp:launchpad

 

Review: Approve code



Diff comments:

> 
> === renamed file 'scripts/update-bzr-version-info.sh' => 'scripts/update-version-info.sh'
> --- scripts/update-bzr-version-info.sh	2009-10-16 01:54:41 +0000
> +++ scripts/update-version-info.sh	2016-09-14 11:56:46 +0000
> @@ -1,35 +1,57 @@
>  #!/bin/bash
>  #
> -# Copyright 2009 Canonical Ltd.  This software is licensed under the
> +# Copyright 2009-2016 Canonical Ltd.  This software is licensed under the
>  # GNU Affero General Public License version 3 (see the file LICENSE).
>  #
> -# Update bzr-version-info.py -- but only if the revision number has
> +# Update version-info.py -- but only if the revision number has
>  # changed
>  #
>  
> -if ! which bzr > /dev/null || !  test -x $(which bzr); then
> -    echo "No working 'bzr' executable found"
> +newfile=version-info-${RANDOM}.py
> +
> +if [ -d .git ]; then

There's no equivalent of the "which bzr" check below, but that may not be essential.

> +    branch_nick="$(git rev-parse --abbrev-ref HEAD)"
> +    revision_id="$(git rev-parse HEAD)"
> +    cat > $newfile <<EOF
> +#! /usr/bin/env python
> +
> +from __future__ import print_function
> +
> +version_info = {
> +    'branch_nick': u'$branch_nick',

Hopefully nobody uses an apostrophe in a ref name.

> +    'revision_id': u'$revision_id',
> +    }
> +
> +if __name__ == '__main__':
> +    print('revision id: %(revision_id)s' % version_info)
> +EOF
> +elif [ -d .bzr ]; then
> +    if ! which bzr > /dev/null || !  test -x $(which bzr); then
> +        echo "No working 'bzr' executable found" >&2
> +        exit 1
> +    fi
> +
> +    bzr version-info --format=python > $newfile 2>/dev/null
> +else
> +    echo "Not in a Git or Bazaar working tree" >&2
>      exit 1
>  fi
>  
> -newfile=bzr-version-info-${RANDOM}.py
> -bzr version-info --format=python > $newfile 2>/dev/null;
> -# There's a leading space here that I don't care to trim.. 
> -revno=$(python $newfile | grep revision: | cut -d: -f2)
> -if ! [ -f bzr-version-info.py ]; then
> -    echo "Creating bzr-version-info.py at revno$revno"
> -    mv ${newfile} bzr-version-info.py
> +revision_id=$(python $newfile | sed -n 's/^revision id: //p')
> +if ! [ -f version-info.py ]; then
> +    echo "Creating version-info.py at revision $revision_id"
> +    mv ${newfile} version-info.py
>  else
>      # Here we compare the actual output instead of the contents of the
>      # file because bzr includes a build-date that is actually updated
>      # every time you run bzr version-info.
>      newcontents=$(python $newfile)
> -    oldcontents=$(python bzr-version-info.py)
> +    oldcontents=$(python version-info.py)
>      if [ "$newcontents" != "$oldcontents" ]; then
> -        echo "Updating bzr-version-info.py to revno$revno"
> -        mv ${newfile} bzr-version-info.py
> +        echo "Updating version-info.py to revision $revision_id"
> +        mv ${newfile} version-info.py
>      else
> -        echo "Skipping bzr-version-info.py update; already at revno$revno"
> +        echo "Skipping version-info.py update; already at revision $revision_id"
>          rm ${newfile}
>      fi
>  fi


-- 
https://code.launchpad.net/~cjwatson/launchpad/git-version-info/+merge/305701
Your team Launchpad code reviewers is subscribed to branch lp:launchpad.


References