All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scripts/setlocalversion: git: Make -dirty check more robust
@ 2018-08-29  3:26 Genki Sky
  2018-08-31 16:21 ` Masahiro Yamada
  0 siblings, 1 reply; 2+ messages in thread
From: Genki Sky @ 2018-08-29  3:26 UTC (permalink / raw)
  To: linux-kbuild
  Cc: Christian Kujau, Elazar Leibovich, Junio C Hamano,
	Masahiro Yamada, Michal Marek, Nico Schottelius

$(git diff-index) relies on the index being refreshed. This refreshing
of the index used to happen, but was removed in cdf2bc632ebc
("scripts/setlocalversion on write-protected source tree", 2013-06-14)
due to issues with a read-only filesystem.

If the index is not refreshed, one runs into problems. E.g. as
described in [0], git stores the uid in its index, so even if just the
uid has changed (or git is tricked into thinking so), then we will
think the tree is dirty. So as in [1], if you package linux-git with a
system that uses fakeroot(1), you get a "-dirty" version. Unless you
manually $(git update-index --refresh) themselves.

The simplest solution seems to be $(git status --porcelain), with an
additional flag saying "ignore untracked files". It seems clearer
about what it does, and avoids issues regarding cached indexes and
writable filesystems, but still has stable output for scripting.

[0]: https://public-inbox.org/git/0190ae30-b6c8-2a8b-b1fb-fd9d84e6dfdf@oracle.com/
[1]: https://bbs.archlinux.org/viewtopic.php?id=236702

Signed-off-by: Genki Sky <sky@genki.is>
---

Notes:

   Testing: I ran $(git status -uno .... && echo dirty) after each of
   the following commands, checking sanity:

     % > Makefile
     % git checkout Makefile
     % chmod -w .git
     % > scripts/package/Makefile
     % chmod +w .git
     % git checkout scripts/package/Makefile
     % touch new_file
     % touch scripts/package/new_file
     % rm new_file scripts/package/new_file
     % mv Makefile .clang-format
     % git checkout Makefile .clang-format

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

diff --git a/scripts/setlocalversion b/scripts/setlocalversion
index 71f39410691b..79f7dd57d571 100755
--- a/scripts/setlocalversion
+++ b/scripts/setlocalversion
@@ -74,7 +74,7 @@ scm_version()
 		fi

 		# Check for uncommitted changes
-		if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
+		if git status -uno --porcelain | grep -qv '^.. scripts/package'; then
 			printf '%s' -dirty
 		fi

--
2.18.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] scripts/setlocalversion: git: Make -dirty check more robust
  2018-08-29  3:26 [PATCH] scripts/setlocalversion: git: Make -dirty check more robust Genki Sky
@ 2018-08-31 16:21 ` Masahiro Yamada
  0 siblings, 0 replies; 2+ messages in thread
From: Masahiro Yamada @ 2018-08-31 16:21 UTC (permalink / raw)
  To: Genki Sky
  Cc: Linux Kbuild mailing list, Christian Kujau, Elazar Leibovich,
	Junio C Hamano, Michal Marek, Nico Schottelius

2018-08-29 12:26 GMT+09:00 Genki Sky <sky@genki.is>:
> $(git diff-index) relies on the index being refreshed. This refreshing
> of the index used to happen, but was removed in cdf2bc632ebc
> ("scripts/setlocalversion on write-protected source tree", 2013-06-14)
> due to issues with a read-only filesystem.
>
> If the index is not refreshed, one runs into problems. E.g. as
> described in [0], git stores the uid in its index, so even if just the
> uid has changed (or git is tricked into thinking so), then we will
> think the tree is dirty. So as in [1], if you package linux-git with a
> system that uses fakeroot(1), you get a "-dirty" version. Unless you
> manually $(git update-index --refresh) themselves.
>
> The simplest solution seems to be $(git status --porcelain), with an
> additional flag saying "ignore untracked files". It seems clearer
> about what it does, and avoids issues regarding cached indexes and
> writable filesystems, but still has stable output for scripting.
>
> [0]: https://public-inbox.org/git/0190ae30-b6c8-2a8b-b1fb-fd9d84e6dfdf@oracle.com/
> [1]: https://bbs.archlinux.org/viewtopic.php?id=236702
>
> Signed-off-by: Genki Sky <sky@genki.is>
> ---

Applied to linux-kbuild/fixes. Thanks!


> Notes:
>
>    Testing: I ran $(git status -uno .... && echo dirty) after each of
>    the following commands, checking sanity:
>
>      % > Makefile
>      % git checkout Makefile
>      % chmod -w .git
>      % > scripts/package/Makefile
>      % chmod +w .git
>      % git checkout scripts/package/Makefile
>      % touch new_file
>      % touch scripts/package/new_file
>      % rm new_file scripts/package/new_file
>      % mv Makefile .clang-format
>      % git checkout Makefile .clang-format
>
>  scripts/setlocalversion | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/setlocalversion b/scripts/setlocalversion
> index 71f39410691b..79f7dd57d571 100755
> --- a/scripts/setlocalversion
> +++ b/scripts/setlocalversion
> @@ -74,7 +74,7 @@ scm_version()
>                 fi
>
>                 # Check for uncommitted changes
> -               if git diff-index --name-only HEAD | grep -qv "^scripts/package"; then
> +               if git status -uno --porcelain | grep -qv '^.. scripts/package'; then
>                         printf '%s' -dirty
>                 fi
>
> --
> 2.18.0
>



-- 
Best Regards
Masahiro Yamada

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-08-31 20:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-29  3:26 [PATCH] scripts/setlocalversion: git: Make -dirty check more robust Genki Sky
2018-08-31 16:21 ` Masahiro Yamada

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.