Skip to contentSkip to conversation

Try to use git commit id if hg changeset is unavailable

PATCH In review Marek Marczykowski 5 participants 16 messages May 8, 2013 – Jul 17, 2013

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Try to use git commit id if hg changeset is unavailable

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

Changes in v3:
- do not assume tools/scmversion started from the repository toplevel dir - it is actually called from xen/ subdir

---
 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..945197b 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")!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
#1 lore raw
Quoted 10 lines · Marek Marczykowski

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

Changes in v3:
- do not assume tools/scmversion started from the repository toplevel dir - it is actually called from xen/ subdir

I see you did this by removing various checks for .hg and .igt directories, but this seems a little fragile and doesn't cover the .scmversion case properly.

The scmversion script already takes an optional source dir, why not just pass $(XEN_ROOT) ?

Ian.

#2 lore raw
Quoted 12 lines · Ian Campbell
Quoted 10 lines · Marek Marczykowski

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

Changes in v3:
- do not assume tools/scmversion started from the repository toplevel dir - it is actually called from xen/ subdir

Quoted 6 lines

I see you did this by removing various checks for .hg and .igt directories, but this seems a little fragile and doesn't cover the .scmversion case properly.

The scmversion script already takes an optional source dir, why not just pass $(XEN_ROOT) ?

Indeed, good idea.

Signature · 3 lines
Best Regards,
Marek Marczykowski
Invisible Things Lab

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

#3 lore raw

PATCH v4 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

Changes in v3:
- do not assume tools/scmversion started from the repository toplevel dir - it is actually called from xen/ subdir

Changes in v4:
- restore checks for .git and .hg dirs, use $(XEN_ROOT)

---
 xen/Makefile         |   2 +-
 xen/tools/scmversion | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+), 1 deletion(-)
 create mode 100755 xen/tools/scmversion
xen/Makefile +1 -1
index 0fb3db7..201d9bc 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 $(XEN_ROOT) || echo "unavailable")!g' \
 	    < include/xen/compile.h.in > [email protected]
 	@grep \" .banner >> [email protected]
 	@grep -v \" .banner
xen/tools/scmversion new file +101 -0

101 lines not on this page · raw message

Signature · 1 line
1.8.1.4
Reviewed-by on v4 1/1
#4 lore raw

Re: [PATCH v4] Use {git, hg, svn} commit id if available for xen_changeset

Quoted 7 lines · Marek Marczykowski

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

Quoted 8 lines

Changes in v3:
- do not assume tools/scmversion started from the repository toplevel dir - it is actually called from xen/ subdir

Changes in v4:
- restore checks for .git and .hg dirs, use $(XEN_ROOT)

I tried this on git and hg and it appeared to do the right thing, thanks.

Quoted 126 lines
---
 xen/Makefile         |   2 +-
 xen/tools/scmversion | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+), 1 deletion(-)
 create mode 100755 xen/tools/scmversion
xen/Makefile +1 -1
index 0fb3db7..201d9bc 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 $(XEN_ROOT) || echo "unavailable")!g' \
 	    < include/xen/compile.h.in > [email protected]
 	@grep \" .banner >> [email protected]
 	@grep -v \" .banner
xen/tools/scmversion new file +101 -0
new file mode 100755
index 0000000..219d898
@@ -0,0 +1,101 @@
+#!/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
+}
+
+cd $srctree
+
+# full scm version string
+res="$(scm_version)"
+
+echo "$res"
#5 lore raw

Re: [PATCH v4] Use {git, hg, svn} commit id if available for xen_changeset

Quoted 12 lines · Ian Campbell
Quoted 11 lines · Marek Marczykowski

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

Changes in v3:
- do not assume tools/scmversion started from the repository toplevel dir - it is actually called from xen/ subdir

Quoted 8 lines
Quoted 4 lines

Changes in v4:
- restore checks for .git and .hg dirs, use $(XEN_ROOT)

I tried this on git and hg and it appeared to do the right thing, thanks.

As soon as this gets into staging, I will rebase my much older patch on top to allow XEN_CHANGESET to be overridden on the make invocation.

~Andrew

Quoted 133 lines
Quoted 117 lines
---
 xen/Makefile         |   2 +-
 xen/tools/scmversion | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+), 1 deletion(-)
 create mode 100755 xen/tools/scmversion
xen/Makefile +1 -1
index 0fb3db7..201d9bc 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 $(XEN_ROOT) || echo "unavailable")!g' \
 	    < include/xen/compile.h.in > [email protected]
 	@grep \" .banner >> [email protected]
 	@grep -v \" .banner
xen/tools/scmversion new file +91 -0
new file mode 100755
index 0000000..219d898
@@ -0,0 +1,101 @@
+#!/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

xen/tools/scmversion line 101

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

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

#6 lore raw

Re: [PATCH v4] Use {git, hg, svn} commit id if available for xen_changeset

Quoted 16 lines · Andrew Cooper
Quoted 15 lines · Ian Campbell
Quoted 14 lines · Marek Marczykowski

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

Changes in v3:
- do not assume tools/scmversion started from the repository toplevel dir - it is actually called from xen/ subdir

Changes in v4:
- restore checks for .git and .hg dirs, use $(XEN_ROOT)

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

I tried this on git and hg and it appeared to do the right thing, thanks.

As soon as this gets into staging, I will rebase my much older patch on top to allow XEN_CHANGESET to be overridden on the make invocation.

Thanks. It needs an Ack from a hypervisor maintainer first (Keir presumably).

Ian.

Acked-by
#7 lore raw

Re: [PATCH v4] Use {git, hg, svn} commit id if available for xen_changeset

Quoted 21 lines · Ian Campbell
Quoted 20 lines · Andrew Cooper
Quoted 19 lines · Ian Campbell
Quoted 7 lines · Marek Marczykowski

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

Quoted 8 lines

Changes in v3:
- do not assume tools/scmversion started from the repository toplevel dir - it is actually called from xen/ subdir

Changes in v4:
- restore checks for .git and .hg dirs, use $(XEN_ROOT)

I tried this on git and hg and it appeared to do the right thing, thanks.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

As soon as this gets into staging, I will rebase my much older patch on top to allow XEN_CHANGESET to be overridden on the make invocation.

Thanks. It needs an Ack from a hypervisor maintainer first (Keir presumably).

Okay, well it looked quite fine to me :)

Quoted 2 lines

Ian.

#8 lore raw

Re: [PATCH v4] Use {git, hg, svn} commit id if available for xen_changeset

Quoted 28 lines · Keir Fraser
Quoted 26 lines · Ian Campbell
Quoted 24 lines · Andrew Cooper
Quoted 12 lines · Ian Campbell
Quoted 11 lines · Marek Marczykowski

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

Changes in v3:
- do not assume tools/scmversion started from the repository toplevel dir - it is actually called from xen/ subdir

Quoted 8 lines
Quoted 4 lines

Changes in v4:
- restore checks for .git and .hg dirs, use $(XEN_ROOT)

I tried this on git and hg and it appeared to do the right thing, thanks.

As soon as this gets into staging, I will rebase my much older patch on top to allow XEN_CHANGESET to be overridden on the make invocation.

Quoted 6 lines
Quoted 2 lines

Thanks. It needs an Ack from a hypervisor maintainer first (Keir presumably).

Okay, well it looked quite fine to me :)

Thanks, I'll apply shortly.

Ian.

#9 lore raw

Re: [PATCH v4] Use {git, hg, svn} commit id if available for xen_changeset

Quoted 29 lines · Ian Campbell
Quoted 28 lines · Keir Fraser
Quoted 26 lines · Ian Campbell
Quoted 24 lines · Andrew Cooper
Quoted 12 lines · Ian Campbell
Quoted 11 lines · Marek Marczykowski

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

Changes in v3:
- do not assume tools/scmversion started from the repository toplevel dir - it is actually called from xen/ subdir

Quoted 8 lines
Quoted 4 lines

Changes in v4:
- restore checks for .git and .hg dirs, use $(XEN_ROOT)

I tried this on git and hg and it appeared to do the right thing, thanks.

As soon as this gets into staging, I will rebase my much older patch on top to allow XEN_CHANGESET to be overridden on the make invocation.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Thanks. It needs an Ack from a hypervisor maintainer first (Keir presumably).

Okay, well it looked quite fine to me :)

Thanks, I'll apply shortly.

Done, FSVO "shortly"...

#10 lore raw
In reply to Marek Marczykowski

xen/tools/scmversion line 35

Quoted 3 lines · Marek Marczykowski
xen/tools/scmversion new file +3 -0
+scm_version()
+{
+	local short

What is short supposed to do? Looks like a write-only variable.

Olaf

#11 lore raw
Quoted 7 lines · Olaf Hering

xen/tools/scmversion line 35

Quoted 3 lines · Marek Marczykowski
xen/tools/scmversion new file +3 -0
+scm_version()
+{
+	local short

What is short supposed to do? Looks like a write-only variable.

Some leftover from --short option of kernel script, not used here. But --save-scmversion option is broken. This should be equivalent for "xen/tools/scmversion > .scmversion". So either option should be fixed or removed completely. I vote for fix and do so in the patch (next email).

Signature · 3 lines
Best Regards,
Marek Marczykowski
Invisible Things Lab

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

#12 lore raw

PATCH 1/1 Cleanup scmversion script, fix --save-scmversion option

Remove unused variable, fix erroneously removed --save-scmversion code.

---
 xen/tools/scmversion | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
xen/tools/scmversion +6 -9
index 219d898..b0c3b95 100755
@@ -16,10 +16,10 @@ usage() {
 	exit 1
 }
 
-scm_only=false
+save_scm=false
 srctree=.
 if test "$1" = "--save-scmversion"; then
-	scm_only=true
+	save_scm=true
 	shift
 fi
 if test $# -gt 0; then
@@ -32,17 +32,10 @@ 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
@@ -98,4 +91,8 @@ cd $srctree
 # full scm version string
 res="$(scm_version)"
 
+if [ "$save_scm" = "true" ]; then
+    echo $res > .scmversion
+fi
+
 echo "$res"
Signature · 1 line
1.8.1.4
#14 lore raw

Re: [PATCH] Cleanup scmversion script, fix --save-scmversion option

Quoted 6 lines · Ian Campbell
Quoted 3 lines · Marek Marczykowski

Remove unused variable, fix erroneously removed --save-scmversion code.

Keir/Jan -- shall I apply to staging or will one of you?

Quoted 7 lines

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

#15 lore raw

Re: [PATCH] Cleanup scmversion script, fix --save-scmversion option

Quoted 9 lines · Ian Campbell
Quoted 6 lines · Ian Campbell
Quoted 3 lines · Marek Marczykowski

Remove unused variable, fix erroneously removed --save-scmversion code.

Keir/Jan -- shall I apply to staging or will one of you?

I took it that no one objected and applied. I forgot to edit in my ack though, oops.

Ian.