Skip to contentSkip to conversation

scripts/setlocalversion: remove mercurial, svn and git-svn supports

PATCH In review Masahiro Yamada 3 participants 8 messages May 23, 2021 – May 26, 2021 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 scripts/setlocalversion: remove mercurial, svn and git-svn supports

The mercurial, svn, git-svn supports were added by the following commits without explaining why they are useful for the kernel source tree.

- 3dce174cfcba ("kbuild: support mercurial in setlocalversion")

- ba3d05fb6369 ("kbuild: add svn revision information to setlocalversion")

- ff80aa97c9b4 ("setlocalversion: add git-svn support")

Let's revert all of them, and see if somebody will complain about it.

---

 scripts/setlocalversion | 41 -----------------------------------------
 1 file changed, 41 deletions(-)
scripts/setlocalversion +0 -41
index db941f6d9591..879cba956e60 100755
@@ -79,11 +79,6 @@ scm_version()
 			fi
 		fi
 
-		# 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
-
 		# Check for uncommitted changes.
 		# First, with git-status, but --no-optional-locks is only
 		# supported in git >= 2.14, so fall back to git-diff-index if
@@ -96,42 +91,6 @@ scm_version()
 		} | grep -qvE '^(.. )?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
-		# Do we have an tagged version?  If so, latesttagdistance == 1
-		if [ "$(hg log -r . --template '{latesttagdistance}')" = "1" ]; then
-			id=$(hg log -r . --template '{latesttag}')
-			printf '%s%s' -hg "$id"
-		else
-			tag=$(printf '%s' "$hgid" | cut -d' ' -f2)
-			if [ -z "$tag" -o "$tag" = tip ]; then
-				id=$(printf '%s' "$hgid" | sed 's/[+ ].*//')
-				printf '%s%s' -hg "$id"
-			fi
-		fi
-
-		# 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=$(LC_ALL=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
 }
 
Signature · 1 line
2.27.0
#2 lore raw

PATCH 3/5 scripts/setlocalversion: add more comments to -dirty flag detection

This script stumbled on the read-only source tree over again:

- a2bb90a08cb3 ("kbuild: fix delay in setlocalversion on readonly source")

- cdf2bc632ebc ("scripts/setlocalversion on write-protected source tree")

- 8ef14c2c41d9 ("Revert "scripts/setlocalversion: git: Make -dirty check more robust"")

- ff64dd485730 ("scripts/setlocalversion: Improve -dirty check with git-status --no-optional-locks")

Add comments to clarify that this script should never ever try to write to the source tree.

'git describe --dirty' might look as a simple solution for appending the -dirty string, but we cannot use it because it creates the .git/index.lock file.

---

 scripts/setlocalversion | 4 ++++
 1 file changed, 4 insertions(+)
scripts/setlocalversion +4 -0
index f3084d6bbb22..6865df6699c8 100755
@@ -80,6 +80,10 @@ scm_version()
 		fi
 
 		# Check for uncommitted changes.
+		# This script must avoid any write attempt to the source tree,
+		# which might be read-only.
+		# You cannot use 'git describe --dirty' because it tries to
+		# create .git/index.lock .
 		# First, with git-status, but --no-optional-locks is only
 		# supported in git >= 2.14, so fall back to git-diff-index if
 		# it fails. Note that git-diff-index does not refresh the
Signature · 1 line
2.27.0
#1 lore raw

PATCH 2/5 scripts/setlocalversion: remove workaround for old make-kpkg

In reply to Masahiro Yamada

This reverts commit b052ce4c840e ("kbuild: fix false positive -dirty tag caused by make-kpkg").

If I understand correctly, it occurred in very old versions of make-kpkg. When I tried a newer version, make-kpkg did not touch scripts/package/Makefile.

Anyway, Debian uses 'make deb-pkg' instead of make-kpkg these days.

Debian handbook [1] mentions it as "the good old days":
"CULTURE The good old days of kernel-package

Before the Linux build system gained the ability to build proper Debian packages, the recommended way to build such packages was to use make-kpkg from the kernel-package package."

[1]: https://debian-handbook.info/browse/stable/sect.kernel-compilation.html

---

 scripts/setlocalversion | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/setlocalversion +1 -1
index 879cba956e60..f3084d6bbb22 100755
@@ -88,7 +88,7 @@ scm_version()
 		if {
 			git --no-optional-locks status -uno --porcelain 2>/dev/null ||
 			git diff-index --name-only HEAD
-		} | grep -qvE '^(.. )?scripts/package'; then
+		} | read dummy; then
 			printf '%s' -dirty
 		fi
 	fi
Signature · 1 line
2.27.0
#5 lore raw

PATCH 5/5 scripts/setlocalversion: simplify the short version part

In reply to Masahiro Yamada

Reduce the indentation.

---

 scripts/setlocalversion | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
scripts/setlocalversion +3 -5
index 62c0bcce1575..151f04971faa 100755
@@ -131,15 +131,13 @@ res="${res}${CONFIG_LOCALVERSION}${LOCALVERSION}"
 if test "$CONFIG_LOCALVERSION_AUTO" = "y"; then
 	# full scm version string
 	res="$res$(scm_version)"
-else
+elif [ -z "${LOCALVERSION}" ]; then
 	# append a plus sign if the repository is not in a clean
 	# annotated or signed tagged state (as git describe only
 	# looks at signed or annotated tags - git tag -a/-s) and
 	# LOCALVERSION= is not specified
-	if test "${LOCALVERSION+set}" != "set"; then
-		scm=$(scm_version --short)
-		res="$res${scm:++}"
-	fi
+	scm=$(scm_version --short)
+	res="$res${scm:++}"
 fi
 
 echo "$res"
Signature · 1 line
2.27.0
#3 lore raw

PATCH 4/5 scripts/setlocalversion: factor out 12-chars hash construction

In reply to Masahiro Yamada

Both of if and else parts append exactly 12 hex chars, but in different ways.

Factor out the else part because we need to support it without relying on git-describe. Remove the --abbrev=12 option since we do not use the hash from git-describe anyway.

---

 scripts/setlocalversion | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)
scripts/setlocalversion +5 -17
index 6865df6699c8..62c0bcce1575 100755
@@ -59,24 +59,12 @@ scm_version()
 			fi
 			# If we are past a tagged commit (like
 			# "v2.6.30-rc5-302-g72357d5"), we pretty print it.
-			#
-			# Ensure the abbreviated sha1 has exactly 12
-			# hex characters, to make the output
-			# independent of git version, local
-			# core.abbrev settings and/or total number of
-			# objects in the current repository - passing
-			# --abbrev=12 ensures a minimum of 12, and the
-			# awk substr() then picks the 'g' and first 12
-			# hex chars.
-			if atag="$(git describe --abbrev=12 2>/dev/null)"; then
-				echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),substr($(NF),0,13))}'
-
-			# If we don't have a tag at all we print -g{commitish},
-			# again using exactly 12 hex chars.
-			else
-				head="$(echo $head | cut -c1-12)"
-				printf '%s%s' -g $head
+			if atag="$(git describe 2>/dev/null)"; then
+				echo "$atag" | awk -F- '{printf("-%05d", $(NF-1))}'
 			fi
+
+			# Add -g and exactly 12 hex chars.
+			printf '%s%s' -g "$(echo $head | cut -c1-12)"
 		fi
 
 		# Check for uncommitted changes.
Signature · 1 line
2.27.0
Reviewed-by on v1 1/5
#6 lore raw
In reply to Masahiro Yamada
Quoted 5 lines · Masahiro Yamada

The mercurial, svn, git-svn supports were added by the following commits without explaining why they are useful for the kernel source tree.

- 3dce174cfcba ("kbuild: support mercurial in setlocalversion")

Quoted 9 lines

- ba3d05fb6369 ("kbuild: add svn revision information to setlocalversion")

- ff80aa97c9b4 ("setlocalversion: add git-svn support")

Let's revert all of them, and see if somebody will complain about it.

---

For all 5 in this series:

Reviewed-by on v1 4/5
#4 lore raw

Re: [PATCH 4/5] scripts/setlocalversion: factor out 12-chars hash construction

In reply to Masahiro Yamada

Hey Masahiro,

Quoted 7 lines · Masahiro Yamada
scripts/setlocalversion +0 -7
-			if atag="$(git describe --abbrev=12 2>/dev/null)"; then
-				echo "$atag" | awk -F- '{printf("-%05d-%s", $(NF-1),substr($(NF),0,13))}'
-
-			# If we don't have a tag at all we print -g{commitish},
-			# again using exactly 12 hex chars.
-			else
-				head="$(echo $head | cut -c1-12)"

scripts/setlocalversion scm_version() · line 70

Quoted 10 lines
scripts/setlocalversion +5 -1
-				printf '%s%s' -g $head
+			if atag="$(git describe 2>/dev/null)"; then
+				echo "$atag" | awk -F- '{printf("-%05d", $(NF-1))}'
 			fi
+
+			# Add -g and exactly 12 hex chars.
+			printf '%s%s' -g "$(echo $head | cut -c1-12)"
 		fi
 
 		# Check for uncommitted changes.

That was quite fun reviewing and wrapping my head around ~20y old code.

I had a very long mail prepared looking at all the corner cases, just to see they are actually handled before the actual change.

Nicely simplified, for all 5 of them:

--
Sustainable and modern Infrastructures by ungleich.ch

#7 lore raw
In reply to Greg Kroah-Hartman
Quoted 13 lines · Greg Kroah-Hartman
Quoted 11 lines · Masahiro Yamada

The mercurial, svn, git-svn supports were added by the following commits without explaining why they are useful for the kernel source tree.

- 3dce174cfcba ("kbuild: support mercurial in setlocalversion")

- ba3d05fb6369 ("kbuild: add svn revision information to setlocalversion")

- ff80aa97c9b4 ("setlocalversion: add git-svn support")

Let's revert all of them, and see if somebody will complain about it.

Quoted 7 lines
Quoted 3 lines

---

For all 5 in this series:

Applied to linux-kbuild.

Signature · 2 lines
Best Regards
Masahiro Yamada