]> git.proxmox.com Git - pve-manager.git/commitdiff
compute a repository ID
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 15 Sep 2011 12:54:42 +0000 (14:54 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 15 Sep 2011 12:54:42 +0000 (14:54 +0200)
And try to disable upload when there are local modifications.

Makefile
PVE/Makefile
repoid.pl [new file with mode: 0755]

index ce688a06f32bbce179f614e8e9ea92d3c4d8de07..f15cef12d448308df2d6dc95d202a8cfea3593be 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -44,6 +44,7 @@ ${DEB} deb:
 
 .PHONY: upload
 upload: ${DEB}
+       ./repoid.pl .git check
        umount /pve/${RELEASE}; mount /pve/${RELEASE} -o rw 
        mkdir -p /pve/${RELEASE}/extra
        rm -f /pve/${RELEASE}/extra/${PACKAGE}_*.deb
index 2df9573c5260ebcd0f67c9a8c8c7fefa0165db65..ccf4ca65e23d8f2a47464c813d5a585bd2a901d7 100644 (file)
@@ -11,8 +11,11 @@ PERLSOURCE =                         \
 
 all: pvecfg.pm ${SUBDIRS}
 
+REPOID=`../repoid.pl ../.git`
+
 pvecfg.pm: pvecfg.pm.in
-       sed -e s/@VERSION@/${VERSION}/ -e s/@PACKAGE@/${PACKAGE}/ $< >$@
+       sed -e s/@VERSION@/${VERSION}/ -e s/@PACKAGE@/${PACKAGE}/ -e s/@REPOID@/${REPOID}/ $< >$@.tmp
+       mv $@.tmp $@
 
 %:
        set -e && for i in ${SUBDIRS}; do ${MAKE} -C $$i $@; done
@@ -24,7 +27,7 @@ distclean: clean
 .PHONY: clean
 clean:
        set -e && for i in ${SUBDIRS}; do ${MAKE} -C $$i $@; done
-       rm -rf *~ pvecfg.pm
+       rm -rf *~ pvecfg.pm pvecfg.pm.tmp
 
 .PHONY: install 
 install: pvecfg.pm ${PERLSOURCE}
diff --git a/repoid.pl b/repoid.pl
new file mode 100755 (executable)
index 0000000..f431c84
--- /dev/null
+++ b/repoid.pl
@@ -0,0 +1,40 @@
+#!/usr/bin/perl -w
+
+# use use the first 8 characters from the master commit ID
+
+# git status --porcelain
+
+use strict;
+use lib qw(.);
+use PVE::Tools qw(run_command);
+
+my $gitdir = shift;
+die "no repository" if !$gitdir;
+
+my $path = "$gitdir/refs/heads/master";
+die "master branch does not exists" if ! -f $path;
+
+my $arg1 = shift;
+
+if ($arg1) {
+    die "unknown parameter '$arg1'" if $arg1 ne 'check';
+
+    my $testfunc = sub {
+       my $line = shift;
+       next if $line =~ m/^#/;
+       next if $line =~ m/^\?\?/;
+
+       die "detected modified content: $line\n";
+    };
+
+    my $cmd = ['git', '--git-dir', $gitdir ,'status', '--porcelain'];
+    run_command($cmd, outfunc => $testfunc);
+}
+
+my $repoid = `cat $path`;
+chomp $repoid;
+
+die "invalid commit format" if $repoid !~ m/^[0-9a-f]{40}$/;
+
+my $res = substr $repoid, 0, 8;
+print "$res\n";