Skip to contentSkip to conversation

Fix detectition of kernel git repository in setlocalversion script

PATCH In review Franck Bui-Huu 2 participants 7 messages Dec 2, 2013 – Jan 3, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix detectition of kernel git repository in setlocalversion script

setlocalversion script was testing the presence of .git directory in order to find out if git is used as SCM to track the current kernel project. However in some cases, .git is not a directory but can be a file: when the kernel is a git submodule part of a git super project for example.

This patch just fixes this by using 'git rev-parse --show-cdup' to check that the current directory is the kernel git topdir. This has the advantage to not test and rely on git internal infrastructure directly.

---
 scripts/setlocalversion | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/setlocalversion +2 -1
index 0b5ccf3..c16e65d 100755
@@ -43,7 +43,8 @@ scm_version()
 	fi
 
 	# Check for git and a git repo.
-	if test -d .git && head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
+	if topdir=$(git rev-parse --show-cdup 2>/dev/null) && test -z "$topdir" &&
+	   head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
 
 		# If we are at a tagged commit (like "v2.6.30-rc6"), we ignore
 		# it, because this version is defined in the top level Makefile.
Signature · 1 line
1.8.4.2
#1 lore raw

scripts/setlocalversion scm_version() · line 47

Quoted 11 lines · Franck Bui-Huu
scripts/setlocalversion +2 -1
index 0b5ccf3..c16e65d 100755
@@ -43,7 +43,8 @@ scm_version()
 	fi
 
 	# Check for git and a git repo.
-	if test -d .git && head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
+	if topdir=$(git rev-parse --show-cdup 2>/dev/null) && test -z "$topdir" &&
+	   head=`git rev-parse --verify --short HEAD 2>/dev/null`; then

You can do test -z "$(git rev-parse --show-cdup 2>/dev/null)" without the $topdir variable.

Michal

#2 lore raw
Quoted 8 lines · Michal Marek
Quoted 7 lines · Franck Bui-Huu
scripts/setlocalversion +0 -0
index 0b5ccf3..c16e65d 100755
@@ -43,7 +43,8 @@ scm_version()
 	fi
 
Quoted 7 lines

scripts/setlocalversion scm_version() · line 47

Quoted 4 lines
scripts/setlocalversion +2 -1
 	# Check for git and a git repo.
-	if test -d .git && head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
+	if topdir=$(git rev-parse --show-cdup 2>/dev/null) && test -z "$topdir" &&
+	   head=`git rev-parse --verify --short HEAD 2>/dev/null`; then

You can do test -z "$(git rev-parse --show-cdup 2>/dev/null)" without the $topdir variable.

No, "$(git rev-parse --show-cdup 2>/dev/null)" would also give the empty string if the git command fails (ie not inside a git repository at all).

Thanks.

Signature · 1 line
            Franck
#3 lore raw
Quoted 17 lines · Franck Bui-Huu
Quoted 8 lines · Michal Marek
Quoted 7 lines · Franck Bui-Huu
scripts/setlocalversion +0 -0
index 0b5ccf3..c16e65d 100755
@@ -43,7 +43,8 @@ scm_version()
 	fi
 
Quoted 7 lines

scripts/setlocalversion scm_version() · line 47

Quoted 4 lines
scripts/setlocalversion +2 -1
 	# Check for git and a git repo.
-	if test -d .git && head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
+	if topdir=$(git rev-parse --show-cdup 2>/dev/null) && test -z "$topdir" &&
+	   head=`git rev-parse --verify --short HEAD 2>/dev/null`; then

You can do test -z "$(git rev-parse --show-cdup 2>/dev/null)" without the $topdir variable.

Quoted 2 lines

No, "$(git rev-parse --show-cdup 2>/dev/null)" would also give the empty string if the git command fails (ie not inside a git repository at all).

Then git rev-parse will also fail.

Michal

#4 lore raw
Quoted 18 lines · Michal Marek
Quoted 17 lines · Franck Bui-Huu
Quoted 15 lines · Michal Marek

scripts/setlocalversion scm_version() · line 47

Quoted 11 lines · Franck Bui-Huu
scripts/setlocalversion +2 -1
index 0b5ccf3..c16e65d 100755
@@ -43,7 +43,8 @@ scm_version()
 	fi
 
 	# Check for git and a git repo.
-	if test -d .git && head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
+	if topdir=$(git rev-parse --show-cdup 2>/dev/null) && test -z "$topdir" &&
+	   head=`git rev-parse --verify --short HEAD 2>/dev/null`; then

You can do test -z "$(git rev-parse --show-cdup 2>/dev/null)" without the $topdir variable.

Quoted 4 lines
Quoted 2 lines

No, "$(git rev-parse --show-cdup 2>/dev/null)" would also give the empty string if the git command fails (ie not inside a git repository at all).

Then git rev-parse will also fail.

Fair enough ;)

I'm resending a new patch.

Thanks.

Signature · 1 line
            Franck
#5 lore raw

PATCH 1/1 Fix detectition of kernel git repository in setlocalversion script [take #2]

setlocalversion script was testing the presence of .git directory in order to find out if git is used as SCM to track the current kernel project. However in some cases, .git is not a directory but can be a file: when the kernel is a git submodule part of a git super project for example.

This patch just fixes this by using 'git rev-parse --show-cdup' to check that the current directory is the kernel git topdir. This has the advantage to not test and rely on git internal infrastructure directly.

---
 scripts/setlocalversion | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
scripts/setlocalversion +2 -1
index 0b5ccf3..3d8af0e 100755
@@ -43,7 +43,8 @@ scm_version()
 	fi
 
 	# Check for git and a git repo.
-	if test -d .git && head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
+	if test -z "$(git rev-parse --show-cdup 2>/dev/null)" &&
+	   head=`git rev-parse --verify --short HEAD 2>/dev/null`; then
 
 		# If we are at a tagged commit (like "v2.6.30-rc6"), we ignore
 		# it, because this version is defined in the top level Makefile.
Signature · 1 line
1.8.4.2
#6 lore raw

Re: [PATCH] Fix detectition of kernel git repository in setlocalversion script [take #2]

Quoted 5 lines · Franck Bui-Huu

setlocalversion script was testing the presence of .git directory in order to find out if git is used as SCM to track the current kernel project. However in some cases, .git is not a directory but can be a file: when the kernel is a git submodule part of a git super project for example.

Quoted 8 lines

This patch just fixes this by using 'git rev-parse --show-cdup' to check that the current directory is the kernel git topdir. This has the advantage to not test and rely on git internal infrastructure directly.

---
 scripts/setlocalversion | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Applied to kbuild.git#kbuild.

Michal