Bug 229230 - newvers falsely appends "-dirty" to hash when building in a git tree with no content changes
Summary: newvers falsely appends "-dirty" to hash when building in a git tree with no ...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: misc (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-06-22 14:24 UTC by Ed Maste
Modified: 2022-09-06 19:09 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Maste freebsd_committer freebsd_triage 2018-06-22 14:24:07 UTC
For git trees newvers.sh attempts to report that the sources used to build do not exactly match a commit hash (and append -dirty to the hash) via:

        if $git_cmd --work-tree=${VCSDIR}/.. diff-index \
            --name-only HEAD | read dummy; then
                git="${git}-dirty"
                modified=true
        fi

However this falsely reports that the tree is modified if metadata on a file does not match git's expectation - for example, I have no changes in a tree:

% git diff-index --name-only HEAD
% git diff
% 

Touch a file:

% touch sys/sys/param.h
%

Now diff-index --name-only HEAD returns the touched file:

% git diff-index --name-only HEAD
sys/sys/param.h
% 

But there are actually no changes:

% git diff
%

And running 'git diff' clears the "metadata changed" status:

% git diff-index --name-only HEAD
%
Comment 1 Ed Maste freebsd_committer freebsd_triage 2018-06-22 15:45:21 UTC
The full git diff-index output (i.e., without --name-only) reports:

:100644 100644 728b9afe3828cfe7916731637677afddd0ad1fb1 0000000000000000000000000000000000000000 M      sys/conf/newvers.sh

The all-zeros SHA hash means that the working tree file must be checked.
Comment 2 commit-hook freebsd_committer freebsd_triage 2018-11-02 21:21:24 UTC
A commit references this bug:

Author: emaste
Date: Fri Nov  2 21:20:46 UTC 2018
New revision: 340083
URL: https://svnweb.freebsd.org/changeset/base/340083

Log:
  newvers.sh: fix git false positive -dirty tag

  Assuming that any output from `git diff-index --name-only` implies
  changes in the working tree results in false positives: files with
  metadata, but not content, changes are also listed.

  Check that content differences exist before adding the -dirty tag to
  the git hash.

  PR:		229230
  Reviewed by:	markj
  Sponsored by:	The FreeBSD Foundation
  Differential Revision:	https://reviews.freebsd.org/D15968

Changes:
  head/sys/conf/newvers.sh
Comment 3 commit-hook freebsd_committer freebsd_triage 2022-09-06 19:09:24 UTC
A commit in branch stable/12 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=b67bd2859d7d757ee9ceb8269a5790f4f1091be5

commit b67bd2859d7d757ee9ceb8269a5790f4f1091be5
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2018-11-02 21:20:46 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2022-09-06 17:15:05 +0000

    newvers.sh: fix git false positive -dirty tag

    Assuming that any output from `git diff-index --name-only` implies
    changes in the working tree results in false positives: files with
    metadata, but not content, changes are also listed.

    Check that content differences exist before adding the -dirty tag to
    the git hash.

    PR:             229230
    Reviewed by:    markj
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D15968

    (cherry picked from commit 50b53a8dc35f38ab6920dd83409541e875d01551)
    (cherry picked from commit 5186028dc4a2a74d007fa65857667efb2742eaea)

 sys/conf/newvers.sh | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)