Code Monkey home page Code Monkey logo

autorevision's Introduction

Autorevision

A shell script for extracting revision information useful in release/build scripting from repositories.

Supported repository types include git, hg, bzr, and svn. The record can be emitted in a ready-to-use form for C, C++, Java, bash, Python, Perl, lua, php, ini and others.

Emitted information includes the ID of the most recent commit, its branch, its date, and several other useful pieces of meta-information.

There is support for reading and writing a cache file so autorevision will remain useful during a build from an unpacked distribution tarball.

See the manual page, included in the distribution, for invocation details.

You can check out examples of the different output that autorevision can produce in examples.

autorevision's People

Contributors

allevo avatar amdmi3 avatar anight avatar chungy avatar dak180 avatar dbiringer avatar eric-s-raymond avatar hironytic avatar jcsalomon avatar jerome-pouiller avatar luqiuwen avatar pabs3 avatar rtiemann avatar soliton- avatar vladistan avatar yuanchuan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

autorevision's Issues

SVN repositories are mistaken for Git on French locale

You can guess why.

$ svn info 
Chemin : .
Chemin racine de la copie de travail : [DONNÉES EFFACÉES]
URL : svn://svn.code.sf.net/p/libmspack/code
Relative URL: ^/
Racine du dépôt : svn://svn.code.sf.net/p/libmspack/code
UUID du dépôt : 18a31f5d-9092-44d1-ac33-008f6764bcc6
Révision : 220
Type de nœud : répertoire
Tâche programmée : normale
Auteur de la dernière modification : kyz
Révision de la dernière modification : 220
Date de la dernière modification: 2015-02-26 12:18:55 +0100 (jeu 26 fév 2015)

Should have probably used --xml here…

got wrong VCS_BRANCH

What you are doing?

jp@jpws$ git clone https://github.com/jp-embedded/scxmlcc.git
Cloning into 'scxmlcc'...
remote: Counting objects: 2089, done.
remote: Compressing objects: 100% (70/70), done.
remote: Total 2089 (delta 53), reused 38 (delta 20), pack-reused 1998
Receiving objects: 100% (2089/2089), 1.49 MiB | 1.15 MiB/s, done.
Resolving deltas: 100% (1365/1365), done.
jp@jpws$ cd scxmlcc
jp@jpws (master=)$ git branch
* master
jp@jpws (master=)$ autorevision -tsh
# Generated by autorevision - do not hand-hack!

VCS_TYPE="git"
VCS_BASENAME="scxmlcc"
VCS_UUID="5bf20d2ccc46b148ed8c858ba16181a954adf7af"
VCS_NUM="447"
VCS_DATE="2018-02-22T21:29:27Z"
VCS_BRANCH="tags/0.8.6"
VCS_TAG="0.8.6"
VCS_TICK="0"
VCS_EXTRA=""

VCS_ACTION_STAMP="2018-02-22T21:29:[email protected]"
VCS_FULL_HASH="4f96b927cb1bc4bf993c621394b97ffe869bbc96"
VCS_SHORT_HASH="4f96b92"

VCS_WC_MODIFIED="0"

# end

What do you expect to happen?

I expected VCS_BRACH to be "master"

What is actually happening?

VCS_BRANCH is "tags/0.8.6"

What version is Autorevision?

jp@jpws (master=)$ autorevision -V
autorevision 1.20

Usage examples would be nice

It is not completely obvious how the tool is used. Examples would help. Repository organization is also rather messy - it is not clear what is sources, assets, docs and files needed for packaging.

Date is not calculated properly in Java output

Java output uses this code

    public static final Date VCS_DATE = new Date($(date -d ${VCS_DATE} +%s));

to presumably format date as a number of seconds since Epoch. There are several problems with that.

First problem, it doesn't work on (some) Linuxes

$ uname -a
Linux xxx 2.6.32.57-bitrix10 #1 SMP Sun Mar 4 00:11:10 MSK 2012 x86_64 Intel(R) Xeon(R) CPU E5530 @ 2.40GHz GenuineIntel GNU/Linux
$ ./autorevision -t java | grep DATE
date: invalid date `2013-01-18T17:46:24-0500'
    public static final Date VCS_DATE = new Date();
$ date -d 2013-01-18T17:46:24-0500 +%s
date: invalid date `2013-01-18T17:46:24-0500'
$ date -d 2013-01-18T17:46:24 +%s
1358505984
$ uname -a
Linux yyy 3.2.0-25-server #40-Ubuntu SMP Fri May 25 13:12:35 UTC 2012 x86_64 GNU/Linux
$ ./autorevision -t java | grep DATE
date: invalid date `2013-01-03T21:36:59-0500'
    public static final Date VCS_DATE = new Date();

but:

$ uname -a
Linux zzz 3.2.0-3-686-pae #1 SMP Mon Jul 23 03:50:34 UTC 2012 i686 GNU/Linux
$ ./autorevision -t java | grep DATE
    public static final Date VCS_DATE = new Date(1358549184);
$ date -d 2013-01-18T17:46:24-0500 +%s
1358549184

As you can see, date on some systems doesn't seem to understand timezone.

Second problem, it's not cross-platform. date is an external command and unfortunately it works differently on other systems. For example, on FreeBSD, the same thing is achieved with

% date -j -f %FT%T%z 2013-01-18T17:46:24-0500 +%s
1358549184

I'm not sure of how to fix Linux timezone problem, but to handle date(1) differences between systems, autorevision should either:

  • check uname and use system-dependent date invocation (still not very cross-platform)
  • provide java output with plain string, just like with other outputs
    • java may parse date string into Date object internally then, if possible

Man page should mention that mq extension is required for mercurial repos

This script doesn't work with mercurial repos unless mq extension is installed which is not default on several systems. ( MacOS when install with brew, Windows when installed with choco ).

The mq extension provides 'hq qtop' command used by the script to determine the tag tick of the repository.

The man page should mention this and maybe provide instructions how to enable this extension.

Here are good instructions how to enable the extension http://stackoverflow.com/questions/8360471/how-to-enable-mercurial-extensions-such-as-mq

Saving formatted to file (for Windows) instead of stdout

Hi there. Great work!

I'm trying to make automated system in Windows, using batch and sh.exe installed with git. But the following does not work as the redirect is already in use:

PATH=%PATH%;C:\Program Files (x86)\Git\bin;C:\Program Files\Git\bin
sh.exe autorevision.sh -t hpp > .\git_version.h
line 944: /dev/stdout: Device or resource busy

Line 944 refers to this line:
cat > "${TARGETFILE}" << EOF

The question is:

  1. Got any idea on solving this redirect issue?
  2. Better, if there's a way to write these formatted styles to file, as you do with the cache file.

Thank you very much in advance.

PHP shouldn't write global variables

Hi,
I have seen, in some languages, the variables are declared in public scope.
For example PHP autorevision writes into $GLOBALS array overwriting any pre-declared global variables.
Like c++ (in hpp), the variable should be declared in a namespace. This pattern saves us from the redeclaration.

For the compatibility for the old version (PHP < 5.3.0), in PHP you can return an array. For example

<?php

return array(
     'VCS_TYPE' => 'git',
    ....
);

It can be imported using

<?php

$autorevision = require 'autorevision.php';

Other languages support natively the namespace. If namespace is not supported, you can use a class declaration like java does.
If namespaces or classes are not supported like c, the better choice is to use the global constant definition (#define) because the inclusion fails at "compile time" without any side effect as already does.

NB: PHP before 4.0.0 doesn't support class. So the best way to isolate the constants is to return as array.

Use svn --xml and parse output as xml instead of plain text

svn has a --xml commandline option that will make it output in XML instead of text.

Using it instead of parsing the meant-to-be-human-readable text should allow autorevision to keep working if/when svn modifies the human-readable output.

Also, I think it will provide help in parsing when the user's locale uses different time or date formats.

autorevision fails on Solaris 11

I'm using the autorevision bundled with ntpsec.

VCS_EXTRA=`cat /export/home/worker/Buildbot/status/full_Solaris_4.8.2_GCC_4.8.2_crypto/build/VERSION` wafhelpers/autorevision.sh -o /export/home/worker/Buildbot/status/full_Solaris_4.8.2_GCC_4.8.2_crypto/build/wafhelpers/.autorevision-cache -e VERSION -t c >/export/home/worker/Buildbot/status/full_Solaris_4.8.2_GCC_4.8.2_crypto/build/ntpd/version.h '
wafhelpers/autorevision.sh[1137]: local: not found [No such file or directory]
wafhelpers/autorevision.sh[1105]: local: not found [No such file or directory]
wafhelpers/autorevision.sh[1106]: local: not found [No such file or directory]
wafhelpers/autorevision.sh[1138]: local: not found [No such file or directory]
wafhelpers/autorevision.sh[1152]: local: not found [No such file or directory]
wafhelpers/autorevision.sh[1161]: local: not found [No such file or directory]
wafhelpers/autorevision.sh[1179]: local: not found [No such file or directory]
error: No repo or cache detected.

/bin/sh is not bash, but instead the bourne shell, and per http://stackoverflow.com/questions/18597697/posix-compliant-way-to-scope-variables-to-a-function-in-a-shell-script "local" is not a keyword in the posix shell.

VCS_BASENAME in a git worktree should reflect basename of the main working tree

What you are doing?

Using autorevision in conjunction with multiple git worktrees.

/tmp$ mkdir repro
/tmp$ cd repro
/tmp/repro$ git init
Initialized empty Git repository in /private/tmp/repro/.git/
/tmp/repro$ git commit --allow-empty --message='Empty commit'
[master (root-commit) a665d16] Empty commit
/tmp/repro$ autorevision.sh -s VCS_BASENAME
repro
/tmp/repro$ git worktree add ../repro-new-worktree
Preparing ../repro-new-worktree (identifier repro-new-worktree)
HEAD is now at a665d16 Empty commit
/tmp/repro$ cd ../repro-new-worktree/
/tmp/repro-new-worktree$ autorevision.sh -s VCS_BASENAME
repro-new-worktree

What do you expect to happen?

I wanted the last output to be repro, the basename of the main working tree. Worktrees are used to organize local work. The main working tree's basename is more reflective of the intent of VCS_BASENAME.

What is actually happening?

I got repro-new-worktree, the basename of the current worktree.

What version is Autorevision?

1.19

Make fails on 1.16 release

I unpacked the autorevision-1.16 tarball and ran make:

$ make
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
warning: Counting the number of revisions may be slower due to an outdated git version less than 1.7.2.3. If something breaks, please update it.
fatal: Not a git repository (or any of the parent directories): .git
fatal: Not a git repository (or any of the parent directories): .git
warning: Action stamps require git version 2.7+.
fatal: Not a git repository (or any of the parent directories): .git
sed -e 's:&&ARVERSION&&::g' autorevision.sh > autorevision
chmod +x autorevision
a2x --attribute="revdate=" --attribute="revnumber=" -f manpage autorevision.asciidoc

I then compared autorevision.sh to autorevision

$ diff -u autorevision.sh  autorevision
--- autorevision.sh	2016-11-15 10:38:53.000000000 -0500
+++ autorevision	2016-11-15 23:50:06.000000000 -0500
@@ -67,7 +67,7 @@
 }
 
 # Config
-ARVERSION="&&ARVERSION&&"
+ARVERSION=""
 while getopts ":t:o:s:e:VfU" OPTION; do
 	case "${OPTION}" in
 		t)

New release soon?

This is more of a question than an issue :-)

I see some some useful features have been added since the 1.14 release. Any plans for a new release?

PHP parse error

Hi,
after running autorevision.sh script, the output is like your example (https://github.com/Autorevision/autorevision/blob/master/examples/autorevision.php)

On my project:

<?php

include 'autorevision.php';
// Other things
// ...

explode with this error:

PHP Parse error:  syntax error, unexpected '=' in <PATH>/autorevision.php on line 4
PHP Stack trace:
PHP   1. {main}() php shell code:0
PHP   2. {main}() php shell code:0

Probably at https://github.com/Autorevision/autorevision/blob/master/autorevision.sh#L568 $GLOBAL variable is interpolated by bash.

Feature request: write to file instead of stdout

Hi,

I think autorevision would be easier to use in build systems (I'm targeting cmake at the moment) if it knew how to write to a file, and only write when there is a change in the VCS.

Any thoughts on the interface? New option, "-O outputfile"?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.