scripts/setlocalversion

Source file repositories/reference/linux-study-clean/scripts/setlocalversion

File Facts

System
Linux kernel
Corpus path
scripts/setlocalversion
Extension
[no extension]
Size
5322 bytes
Lines
213
Domain
Support Tooling And Documentation
Bucket
scripts
Inferred role
Support Tooling And Documentation: scripts
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
#
# This scripts adds local version information from the version
# control system git.
#
# If something goes wrong, send a mail the kernel build mailinglist
# (see MAINTAINERS) and CC Nico Schottelius
# <nico-linuxsetlocalversion -at- schottelius.org>.
#
#

set -e

usage() {
	echo "Usage: $0 [--no-local] [srctree]" >&2
	exit 1
}

no_local=false
if test "$1" = "--no-local"; then
	no_local=true
	shift
fi

srctree=.
if test $# -gt 0; then
	srctree=$1
	shift
fi
if test $# -gt 0 -o ! -d "$srctree"; then
	usage
fi

try_tag() {
	tag="$1"

	# Is $tag an annotated tag?
	if [ "$(git cat-file -t "$tag" 2> /dev/null)" != tag ]; then
		 return
	fi

	# Is it an ancestor of HEAD, and if so, how many commits are in $tag..HEAD?
	# shellcheck disable=SC2046 # word splitting is the point here
	set -- $(git rev-list --count --left-right "$tag"...HEAD 2> /dev/null)

	# $1 is 0 if and only if $tag is an ancestor of HEAD. Use
	# string comparison, because $1 is empty if the 'git rev-list'
	# command somehow failed.
	if [ "$1" != 0 ]; then
		return
	fi

	# $2 is the number of commits in the range $tag..HEAD, possibly 0.
	count="$2"
}

scm_version()
{
	local short=false
	local no_dirty=false
	local tag

	while [ $# -gt 0 ];
	do
		case "$1" in
		--short)
			short=true;;
		--no-dirty)
			no_dirty=true;;

Annotation

Implementation Notes