提交 75280bdf 编写于 作者: M Masahiro Yamada

setlocalversion: make indentation shallower

Return earlier if we are not in the correct git repository. This makes
the code more readable.
Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
Reviewed-by: NNicolas Schier <nicolas@fjasle.eu>
上级 992ebfab
...@@ -34,46 +34,49 @@ scm_version() ...@@ -34,46 +34,49 @@ scm_version()
short=true short=true
fi fi
# Check for git and a git repo. if test -n "$(git rev-parse --show-cdup 2>/dev/null)"; then
if test -z "$(git rev-parse --show-cdup 2>/dev/null)" && return
head=$(git rev-parse --verify HEAD 2>/dev/null); then fi
# If we are at a tagged commit (like "v2.6.30-rc6"), we ignore if ! head=$(git rev-parse --verify HEAD 2>/dev/null); then
# it, because this version is defined in the top level Makefile. return
if [ -z "$(git describe --exact-match 2>/dev/null)" ]; then fi
# If only the short version is requested, don't bother # If we are at a tagged commit (like "v2.6.30-rc6"), we ignore it
# running further git commands # because this version is defined in the top level Makefile.
if $short; then if [ -z "$(git describe --exact-match 2>/dev/null)" ]; then
echo "+"
return
fi
# If we are past a tagged commit (like
# "v2.6.30-rc5-302-g72357d5"), we pretty print it.
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. # If only the short version is requested, don't bother
# This script must avoid any write attempt to the source tree, # running further git commands
# which might be read-only. if $short; then
# You cannot use 'git describe --dirty' because it tries to echo "+"
# create .git/index.lock . return
# 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
# index, so it may give misleading results. See
# git-update-index(1), git-diff-index(1), and git-status(1).
if {
git --no-optional-locks status -uno --porcelain 2>/dev/null ||
git diff-index --name-only HEAD
} | read dummy; then
printf '%s' -dirty
fi fi
# If we are past a tagged commit (like
# "v2.6.30-rc5-302-g72357d5"), we pretty print it.
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.
# 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 index, so it may give misleading
# results.
# See git-update-index(1), git-diff-index(1), and git-status(1).
if {
git --no-optional-locks status -uno --porcelain 2>/dev/null ||
git diff-index --name-only HEAD
} | read dummy; then
printf '%s' -dirty
fi fi
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册