shlib.sh: make has_forks_with_alternates smarter
commit2b148c131fdcdc2c7678342e8aaef606dc31a8ba
authorKyle J. McKay <mackyle@gmail.com>
Fri, 22 Nov 2019 18:35:50 +0000 (22 11:35 -0700)
committerKyle J. McKay <mackyle@gmail.com>
Fri, 22 Nov 2019 18:35:50 +0000 (22 11:35 -0700)
tree695f1a5ea8dff4da1c77ce458fe7d2909ac9d643
parenta22861528f2eb70a6ebd1dff4dcd60da93b5c587
shlib.sh: make has_forks_with_alternates smarter

Previously, when determining whether or not a project has any
alternates, if a non-zero length <proj>/objects/info/alternates
file exists it's considered to have alternates.

But that can result in false positives since Git actually disregards
any comment lines (first character of the line is a '#') or blank
lines (no whitespace allowed) in the alternates file.

This check is important because it gates:

 1) an extra step during the gc process that will be skipped if
    there are no forks with alternates

 2) creation of a bundle which will be skipped if the project
    itself has any alternates

Add an extra check in the case of a non-zero length alternates
file just to make sure that it's not actually empty after all
(i.e. contains only blank lines and comments).

Make this check available as the new is_empty_alternates_file
shell function rather than hiding it inside has_forks_with_alternates.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
shlib.sh