Re: Wrong -dirty suffix set by setlocalversion (was: BUG in git diff-index)

From: Marc Herbert
Date: Fri May 25 2018 - 07:59:26 EST


On 24/05/2018 16:03, Mike Mason wrote:

> diff --git a/scripts/setlocalversion b/scripts/setlocalversion
> index 71f39410691b..9da4c5e83285 100755
> --- a/scripts/setlocalversion
> +++ b/scripts/setlocalversion
> @@ -73,8 +73,10 @@ scm_version()
> printf -- '-svn%s' "`git svn find-rev $head`"
> fi
>
> - # Check for uncommitted changes
> - if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
> + # Check for uncommitted changes. Only check mtime and size.
> + # Ignore insequential ctime, uid, gid and inode differences.
> + if git -c "core.checkstat=minimal" diff-index --name-only HEAD | \
> + grep -qv "^scripts/package"; then
> printf '%s' -dirty
> fi

FWIW:

Reported-by: Marc.Herbert@xxxxxxxxx
Reviewed-by: Marc.Herbert@xxxxxxxxx (assuming a future and decent commit message)
Tested-by: Marc.Herbert@xxxxxxxxx


So the real use case is making a copy of a whole tree before building.
Typical in automated builds, old example:
https://groups.google.com/a/chromium.org/d/msg/chromium-os-dev/zxOa0OLWFkw/N_Sb7EZOBwAJ

Here's a more complex but faster and more transparent way to test Mike's fix
than copying an entire tree:

# Make sure you start from a clean state
git describe --dirty # must not -dirty

make prepare

# Simulate a copy of the tree but with just one file
rsync --perms --times README README.mtime_backup
rm README
rsync --perms --times README.mtime_backup README
stat README README.mtime_backup

# Demo the BUG fixed by Mike
./scripts/setlocalversion # -dirty BUG! because spurious inode ctime difference
git diff-index HEAD
git describe --dirty # not -dirty
./scripts/setlocalversion # not -dirty any more cause describe refreshed index

# Make sure mtime still causes -dirty with AND without Mike's fix
touch README
./scripts/setlocalversion # -dirty