Skip to contentSkip to conversation

Use {git, hg, svn} commit id if available for xen_changeset

PATCH Applied Marek Marczykowski 3 participants 6 messages May 8, 2013

v2 of 4 Applied Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Use {git, hg, svn} commit id if available for xen_changeset

As Xen uses git as primary repository, get git commit id for xen_changeset info.

Changes in v2:
- split scm calls into separate script - based on Linux kernel one, with tags handling removed
- update title

---
 xen/Makefile         |  2 +-
 xen/tools/scmversion | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 100 insertions(+), 1 deletion(-)
 create mode 100755 xen/tools/scmversion
xen/Makefile +1 -1
index 0fb3db7..6f1f13d 100644
@@ -126,7 +126,7 @@ include/xen/compile.h: include/xen/compile.h.in .banner
 	    -e 's/@@version@@/$(XEN_VERSION)/g' \
 	    -e 's/@@subversion@@/$(XEN_SUBVERSION)/g' \
 	    -e 's/@@extraversion@@/$(XEN_EXTRAVERSION)/g' \
-	    -e 's!@@changeset@@!$(shell ((hg parents --template "{date|date} {rev}:{node|short}" >/dev/null && hg parents --template "{date|date} {rev}:{node|short}") || echo "unavailable") 2>/dev/null)!g' \
+	    -e 's!@@changeset@@!$(shell tools/scmversion || echo "unavailable") 2>/dev/null | tr -d '\n')!g' \
 	    < include/xen/compile.h.in > [email protected]
 	@grep \" .banner >> [email protected]
 	@grep -v \" .banner
xen/tools/scmversion new file +99 -0

99 lines not on this page · raw message

Signature · 1 line
1.8.1.4
Applied
#1 lore raw
Quoted 2 lines · Marek Marczykowski

As Xen uses git as primary repository, get git commit id for xen_changeset info.

I applied this to an hg repo and:

$ chmod +x xen/tools/scmversion 
$ rm xen/include/xen/compile.h
$ make -C xen include/xen/compile.h
make: Entering directory `/local/scratch/ianc/devel/xen-unstable.hg/xen'
 __  __            _  _    _____                    _        _     _      
 \ \/ /___ _ __   | || |  |___ /    _   _ _ __  ___| |_ __ _| |__ | | ___ 
  \  // _ \ '_ \  | || |_   |_ \ __| | | | '_ \/ __| __/ _` | '_ \| |/ _ \
  /  \  __/ | | | |__   _| ___) |__| |_| | | | \__ \ || (_| | |_) | |  __/
 /_/\_\___|_| |_|    |_|(_)____/    \__,_|_| |_|___/\__\__,_|_.__/|_|\___|

make: Leaving directory `/local/scratch/ianc/devel/xen-unstable.hg/xen'

$ grep CHANGESET xen/include/xen/compile.h
#define XEN_CHANGESET		" 2>/dev/null | tr -d n)"

Same seems to happen for a git repo too so its not VCS specific.

It also happens if I do an actual build rather than forcing things as above.

Running scmversion by hand appears to produce good output.

Indentation in svmversion seems a bit off though, e.g.
+ printf '%s %s%s' "$date" git: $head
+
+ # Is this git on svn?
+ if git config --get svn-remote.svn.url >/dev/null; then
+ printf -- 'svn:%s' "git svn find-rev $head"
+ fi

Seems to be tab vs space related, the printf is space indented and the rest is tab indented.

Ian.

Quoted 131 lines

Changes in v2:
- split scm calls into separate script - based on Linux kernel one, with tags handling removed
- update title

---
 xen/Makefile         |  2 +-
 xen/tools/scmversion | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 100 insertions(+), 1 deletion(-)
 create mode 100755 xen/tools/scmversion
xen/Makefile +1 -1
index 0fb3db7..6f1f13d 100644
@@ -126,7 +126,7 @@ include/xen/compile.h: include/xen/compile.h.in .banner
 	    -e 's/@@version@@/$(XEN_VERSION)/g' \
 	    -e 's/@@subversion@@/$(XEN_SUBVERSION)/g' \
 	    -e 's/@@extraversion@@/$(XEN_EXTRAVERSION)/g' \
-	    -e 's!@@changeset@@!$(shell ((hg parents --template "{date|date} {rev}:{node|short}" >/dev/null && hg parents --template "{date|date} {rev}:{node|short}") || echo "unavailable") 2>/dev/null)!g' \
+	    -e 's!@@changeset@@!$(shell tools/scmversion || echo "unavailable") 2>/dev/null | tr -d '\n')!g' \
 	    < include/xen/compile.h.in > [email protected]
 	@grep \" .banner >> [email protected]
 	@grep -v \" .banner
xen/tools/scmversion new file +99 -0
new file mode 100755
index 0000000..19d4137
@@ -0,0 +1,99 @@
+#!/bin/sh
+#
+# This scripts adds local version information from the version
+# control systems git, mercurial (hg) and subversion (svn).
+#
+# If something goes wrong, send a mail the kernel build mailinglist
+# (see MAINTAINERS) and CC Nico Schottelius
+# <nico-linuxsetlocalversion -at- schottelius.org>.
+#
+# Based on setlocalversion from Linux kernel
+#
+#
+
+usage() {
+	echo "Usage: $0 [--save-scmversion] [srctree]" >&2
+	exit 1
+}
+
+scm_only=false
+srctree=.
+if test "$1" = "--save-scmversion"; then
+	scm_only=true
+	shift
+fi
+if test $# -gt 0; then
+	srctree=$1
+	shift
+fi
+if test $# -gt 0 -o ! -d "$srctree"; then
+	usage
+fi
+
+scm_version()
+{
+	local short
+	short=false
+
+	cd "$srctree"
+	if test -e .scmversion; then
+		cat .scmversion
+		return
+	fi
+	if test "$1" = "--short"; then
+		short=true
+	fi
+
+	# Check for git and a git repo.
+	if test -d .git && head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
+		date=`git show -s --pretty="%ad" HEAD`
+
+        printf '%s %s%s' "$date" git: $head
+
+		# Is this git on svn?
+		if git config --get svn-remote.svn.url >/dev/null; then
+			printf -- 'svn:%s' "`git svn find-rev $head`"
+		fi
+
+		# Update index only on r/w media
+		[ -w . ] && git update-index --refresh --unmerged > /dev/null
+
+		# Check for uncommitted changes
+		if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
+			printf '%s' -dirty
+		fi
+
+		# All done with git
+		return
+	fi
+
+	# Check for mercurial and a mercurial repo.
+	if test -d .hg && hgid=`hg id 2>/dev/null`; then
+		id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
+		date=`hg parents --template "{date|date}"`
+		printf '%s %s%s' "$date" hg: "$id"
+
+		# Are there uncommitted changes?
+		# These are represented by + after the changeset id.
+		case "$hgid" in
+			*+|*+\ *) printf '%s' -dirty ;;
+		esac
+
+		# All done with mercurial
+		return
+	fi
+
+	# Check for svn and a svn repo.
+	if rev=`LANG= LC_ALL= LC_MESSAGES=C svn info 2>/dev/null | grep '^Last Changed Rev'`; then
+		rev=`echo $rev | awk '{print $NF}'`
+		printf -- 'svn:%s' "$rev"
+
+		# All done with svn
+		return
+	fi
+}
+
+# full scm version string
+res="$(scm_version)"
+
+echo "$res"
#2 lore raw
Quoted 33 lines · Ian Campbell
Quoted 2 lines · Marek Marczykowski

As Xen uses git as primary repository, get git commit id for xen_changeset info.

I applied this to an hg repo and:

$ chmod +x xen/tools/scmversion 
$ rm xen/include/xen/compile.h
$ make -C xen include/xen/compile.h
make: Entering directory `/local/scratch/ianc/devel/xen-unstable.hg/xen'
 __  __            _  _    _____                    _        _     _      
 \ \/ /___ _ __   | || |  |___ /    _   _ _ __  ___| |_ __ _| |__ | | ___ 
  \  // _ \ '_ \  | || |_   |_ \ __| | | | '_ \/ __| __/ _` | '_ \| |/ _ \
  /  \  __/ | | | |__   _| ___) |__| |_| | | | \__ \ || (_| | |_) | |  __/
 /_/\_\___|_| |_|    |_|(_)____/    \__,_|_| |_|___/\__\__,_|_.__/|_|\___|

make: Leaving directory `/local/scratch/ianc/devel/xen-unstable.hg/xen'

$ grep CHANGESET xen/include/xen/compile.h
#define XEN_CHANGESET		" 2>/dev/null | tr -d n)"

Same seems to happen for a git repo too so its not VCS specific.

It also happens if I do an actual build rather than forcing things as above.

Running scmversion by hand appears to produce good output.

Indentation in svmversion seems a bit off though, e.g.

xen/tools/scmversion new file +6 -0
+        printf '%s %s%s' "$date" git: $head
+
+               # Is this git on svn?
+               if git config --get svn-remote.svn.url >/dev/null; then
+                       printf -- 'svn:%s' "`git svn find-rev $head`"
+               fi
Quoted 4 lines

Seems to be tab vs space related, the printf is space indented and the rest is tab indented.

Ian.

Can I please re-request a merge of this change (which in itself is good and fine) with

http://lists.xen.org/archives/html/xen-devel/2012-07/msg01886.html

The reason is that the changeset information is *still broken* for an out-of-scm builds such as RPMs and DEBs.

I will happily rebase the above path on top of this one, if it is accepted.

~Andrew

Quoted 137 lines
Quoted 121 lines

Changes in v2:
- split scm calls into separate script - based on Linux kernel one, with tags handling removed
- update title

---
 xen/Makefile         |  2 +-
 xen/tools/scmversion | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 100 insertions(+), 1 deletion(-)
 create mode 100755 xen/tools/scmversion
xen/Makefile +1 -1
index 0fb3db7..6f1f13d 100644
@@ -126,7 +126,7 @@ include/xen/compile.h: include/xen/compile.h.in .banner
 	    -e 's/@@version@@/$(XEN_VERSION)/g' \
 	    -e 's/@@subversion@@/$(XEN_SUBVERSION)/g' \
 	    -e 's/@@extraversion@@/$(XEN_EXTRAVERSION)/g' \
-	    -e 's!@@changeset@@!$(shell ((hg parents --template "{date|date} {rev}:{node|short}" >/dev/null && hg parents --template "{date|date} {rev}:{node|short}") || echo "unavailable") 2>/dev/null)!g' \
+	    -e 's!@@changeset@@!$(shell tools/scmversion || echo "unavailable") 2>/dev/null | tr -d '\n')!g' \
 	    < include/xen/compile.h.in > [email protected]
 	@grep \" .banner >> [email protected]
 	@grep -v \" .banner
xen/tools/scmversion new file +89 -0
new file mode 100755
index 0000000..19d4137
@@ -0,0 +1,99 @@
+#!/bin/sh
+#
+# This scripts adds local version information from the version
+# control systems git, mercurial (hg) and subversion (svn).
+#
+# If something goes wrong, send a mail the kernel build mailinglist
+# (see MAINTAINERS) and CC Nico Schottelius
+# <nico-linuxsetlocalversion -at- schottelius.org>.
+#
+# Based on setlocalversion from Linux kernel
+#
+#
+
+usage() {
+	echo "Usage: $0 [--save-scmversion] [srctree]" >&2
+	exit 1
+}
+
+scm_only=false
+srctree=.
+if test "$1" = "--save-scmversion"; then
+	scm_only=true
+	shift
+fi
+if test $# -gt 0; then
+	srctree=$1
+	shift
+fi
+if test $# -gt 0 -o ! -d "$srctree"; then
+	usage
+fi
+
+scm_version()
+{
+	local short
+	short=false
+
+	cd "$srctree"
+	if test -e .scmversion; then
+		cat .scmversion
+		return
+	fi
+	if test "$1" = "--short"; then
+		short=true
+	fi
+
+	# Check for git and a git repo.
+	if test -d .git && head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
+		date=`git show -s --pretty="%ad" HEAD`
+
+        printf '%s %s%s' "$date" git: $head
+
+		# Is this git on svn?
+		if git config --get svn-remote.svn.url >/dev/null; then
+			printf -- 'svn:%s' "`git svn find-rev $head`"
+		fi
+
+		# Update index only on r/w media
+		[ -w . ] && git update-index --refresh --unmerged > /dev/null
+
+		# Check for uncommitted changes
+		if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
+			printf '%s' -dirty
+		fi
+
+		# All done with git
+		return
+	fi
+
+	# Check for mercurial and a mercurial repo.
+	if test -d .hg && hgid=`hg id 2>/dev/null`; then
+		id=`printf '%s' "$hgid" | sed 's/[+ ].*//'`
+		date=`hg parents --template "{date|date}"`
+		printf '%s %s%s' "$date" hg: "$id"
+
+		# Are there uncommitted changes?
+		# These are represented by + after the changeset id.
+		case "$hgid" in
+			*+|*+\ *) printf '%s' -dirty ;;
+		esac
+
+		# All done with mercurial
+		return
+	fi
+
+	# Check for svn and a svn repo.
+	if rev=`LANG= LC_ALL= LC_MESSAGES=C svn info 2>/dev/null | grep '^Last Changed Rev'`; then
+		rev=`echo $rev | awk '{print $NF}'`
+		printf -- 'svn:%s' "$rev"

xen/tools/scmversion line 99

Quoted 10 lines
xen/tools/scmversion new file +10 -0
+
+		# All done with svn
+		return
+	fi
+}
+
+# full scm version string
+res="$(scm_version)"
+
+echo "$res"

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw
Quoted 37 lines · Andrew Cooper
Quoted 36 lines · Ian Campbell
Quoted 2 lines · Marek Marczykowski

As Xen uses git as primary repository, get git commit id for xen_changeset info.

I applied this to an hg repo and:

$ chmod +x xen/tools/scmversion 
$ rm xen/include/xen/compile.h
$ make -C xen include/xen/compile.h
make: Entering directory `/local/scratch/ianc/devel/xen-unstable.hg/xen'
 __  __            _  _    _____                    _        _     _      
 \ \/ /___ _ __   | || |  |___ /    _   _ _ __  ___| |_ __ _| |__ | | ___ 
  \  // _ \ '_ \  | || |_   |_ \ __| | | | '_ \/ __| __/ _` | '_ \| |/ _ \
  /  \  __/ | | | |__   _| ___) |__| |_| | | | \__ \ || (_| | |_) | |  __/
 /_/\_\___|_| |_|    |_|(_)____/    \__,_|_| |_|___/\__\__,_|_.__/|_|\___|

make: Leaving directory `/local/scratch/ianc/devel/xen-unstable.hg/xen'

$ grep CHANGESET xen/include/xen/compile.h
#define XEN_CHANGESET		" 2>/dev/null | tr -d n)"

Same seems to happen for a git repo too so its not VCS specific.

It also happens if I do an actual build rather than forcing things as above.

Running scmversion by hand appears to produce good output.

Indentation in svmversion seems a bit off though, e.g.

xen/tools/scmversion new file +6 -0
+        printf '%s %s%s' "$date" git: $head
+
+               # Is this git on svn?
+               if git config --get svn-remote.svn.url >/dev/null; then
+                       printf -- 'svn:%s' "`git svn find-rev $head`"
+               fi

Seems to be tab vs space related, the printf is space indented and the rest is tab indented.

Quoted 6 lines
Quoted 1 line

Ian.

Can I please re-request a merge of this change (which in itself is good and fine) with

http://lists.xen.org/archives/html/xen-devel/2012-07/msg01886.html

I see that Ian J had a comment, was that addressed?

Quoted 4 lines

The reason is that the changeset information is *still broken* for an out-of-scm builds such as RPMs and DEBs.

I will happily rebase the above path on top of this one, if it is accepted.

This patch includes handling of a ".scmversion" file in the tarball. I've no idea how to make git archive generate that but perhaps it would be possible for it to be created as part of our tarball generation process (Ian J CCd) and/or by RPM/DEB packaging.

I did think git archive automatically added a .gitarchive file to the output, but my version doesn't seem to do that.

If you want to address Ian's concern and rebase that may still be worthwhile.

Ian.

#4 lore raw
Quoted 38 lines · Ian Campbell
Quoted 37 lines · Andrew Cooper
Quoted 36 lines · Ian Campbell
Quoted 2 lines · Marek Marczykowski

As Xen uses git as primary repository, get git commit id for xen_changeset info.

I applied this to an hg repo and:

$ chmod +x xen/tools/scmversion 
$ rm xen/include/xen/compile.h
$ make -C xen include/xen/compile.h
make: Entering directory `/local/scratch/ianc/devel/xen-unstable.hg/xen'
 __  __            _  _    _____                    _        _     _      
 \ \/ /___ _ __   | || |  |___ /    _   _ _ __  ___| |_ __ _| |__ | | ___ 
  \  // _ \ '_ \  | || |_   |_ \ __| | | | '_ \/ __| __/ _` | '_ \| |/ _ \
  /  \  __/ | | | |__   _| ___) |__| |_| | | | \__ \ || (_| | |_) | |  __/
 /_/\_\___|_| |_|    |_|(_)____/    \__,_|_| |_|___/\__\__,_|_.__/|_|\___|

make: Leaving directory `/local/scratch/ianc/devel/xen-unstable.hg/xen'

$ grep CHANGESET xen/include/xen/compile.h
#define XEN_CHANGESET		" 2>/dev/null | tr -d n)"

Same seems to happen for a git repo too so its not VCS specific.

It also happens if I do an actual build rather than forcing things as above.

Running scmversion by hand appears to produce good output.

Indentation in svmversion seems a bit off though, e.g.

xen/tools/scmversion new file +6 -0
+        printf '%s %s%s' "$date" git: $head
+
+               # Is this git on svn?
+               if git config --get svn-remote.svn.url >/dev/null; then
+                       printf -- 'svn:%s' "`git svn find-rev $head`"
+               fi

Seems to be tab vs space related, the printf is space indented and the rest is tab indented.

Quoted 6 lines
Quoted 5 lines
Quoted 1 line

Ian.

Can I please re-request a merge of this change (which in itself is good and fine) with

http://lists.xen.org/archives/html/xen-devel/2012-07/msg01886.html

I see that Ian J had a comment, was that addressed?

It was addressed in so far as I stated that it didn't get executed multiple times. The archives seem to have broken the thread of conversation, which had an extra back-and-forth on it.

Quoted 10 lines
Quoted 5 lines

The reason is that the changeset information is *still broken* for an out-of-scm builds such as RPMs and DEBs.

I will happily rebase the above path on top of this one, if it is accepted.

This patch includes handling of a ".scmversion" file in the tarball. I've no idea how to make git archive generate that but perhaps it would be possible for it to be created as part of our tarball generation process (Ian J CCd) and/or by RPM/DEB packaging.

Quoted 8 lines

I did think git archive automatically added a .gitarchive file to the output, but my version doesn't seem to do that.

If you want to address Ian's concern and rebase that may still be worthwhile.

Ian.

A sample .hg_archival.txt is:

repo: 6ed20573be52baab95207f52a8d28084f3a1967c
node: 3a180a46d747dddf77e9bc987f216aaeb84adea7
branch: default
latesttag: v2.3.0
latesttagdistance: 45

Which is sadly not enough to recreate the <rev>:<shorthash> changeset string for HG.

For the background of this patch, XenServer uses a patchqueue. I have specifically listed the base and pq versions separately, as the changeset information for an hg archive of a base repo with a pushed queue is functionally useless after either of the base or patch queue gets changed.

~Andrew

#5 lore raw
Quoted 43 lines · Andrew Cooper
Quoted 42 lines · Ian Campbell
Quoted 41 lines · Andrew Cooper
Quoted 33 lines · Ian Campbell
Quoted 2 lines · Marek Marczykowski

As Xen uses git as primary repository, get git commit id for xen_changeset info.

I applied this to an hg repo and:

$ chmod +x xen/tools/scmversion 
$ rm xen/include/xen/compile.h
$ make -C xen include/xen/compile.h
make: Entering directory `/local/scratch/ianc/devel/xen-unstable.hg/xen'
 __  __            _  _    _____                    _        _     _      
 \ \/ /___ _ __   | || |  |___ /    _   _ _ __  ___| |_ __ _| |__ | | ___ 
  \  // _ \ '_ \  | || |_   |_ \ __| | | | '_ \/ __| __/ _` | '_ \| |/ _ \
  /  \  __/ | | | |__   _| ___) |__| |_| | | | \__ \ || (_| | |_) | |  __/
 /_/\_\___|_| |_|    |_|(_)____/    \__,_|_| |_|___/\__\__,_|_.__/|_|\___|

make: Leaving directory `/local/scratch/ianc/devel/xen-unstable.hg/xen'

$ grep CHANGESET xen/include/xen/compile.h
#define XEN_CHANGESET		" 2>/dev/null | tr -d n)"

Same seems to happen for a git repo too so its not VCS specific.

It also happens if I do an actual build rather than forcing things as above.

Running scmversion by hand appears to produce good output.

Indentation in svmversion seems a bit off though, e.g.

xen/tools/scmversion new file +6 -0
+        printf '%s %s%s' "$date" git: $head
+
+               # Is this git on svn?
+               if git config --get svn-remote.svn.url >/dev/null; then
+                       printf -- 'svn:%s' "`git svn find-rev $head`"
+               fi
Quoted 4 lines

Seems to be tab vs space related, the printf is space indented and the rest is tab indented.

Ian.

Can I please re-request a merge of this change (which in itself is good and fine) with

Quoted 6 lines
Quoted 2 lines
Quoted 1 line

http://lists.xen.org/archives/html/xen-devel/2012-07/msg01886.html

I see that Ian J had a comment, was that addressed?

It was addressed in so far as I stated that it didn't get executed multiple times. The archives seem to have broken the thread of conversation, which had an extra back-and-forth on it.

I see it now, the archives break threads over month boundaries :-(

Quoted 31 lines
Quoted 10 lines
Quoted 5 lines

The reason is that the changeset information is *still broken* for an out-of-scm builds such as RPMs and DEBs.

I will happily rebase the above path on top of this one, if it is accepted.

This patch includes handling of a ".scmversion" file in the tarball. I've no idea how to make git archive generate that but perhaps it would be possible for it to be created as part of our tarball generation process (Ian J CCd) and/or by RPM/DEB packaging.

Quoted 8 lines

I did think git archive automatically added a .gitarchive file to the output, but my version doesn't seem to do that.

If you want to address Ian's concern and rebase that may still be worthwhile.

Ian.

A sample .hg_archival.txt is:

repo: 6ed20573be52baab95207f52a8d28084f3a1967c
node: 3a180a46d747dddf77e9bc987f216aaeb84adea7
branch: default
latesttag: v2.3.0
latesttagdistance: 45

Which is sadly not enough to recreate the <rev>:<shorthash> changeset string for HG.

Quoted 5 lines

For the background of this patch, XenServer uses a patchqueue. I have specifically listed the base and pq versions separately, as the changeset information for an hg archive of a base repo with a pushed queue is functionally useless after either of the base or patch queue gets changed.

With Marek's patch you could write .scmversion into the build tree at whichever point you would normally override the XEN_CHANGESET variable.

Not that I object to also being able to override the variable.

Ian.