From 0a460383bc4ee6894c000aba22ed5de1cef1ba9f Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sat, 30 Dec 2017 06:12:26 -0800 Subject: [PATCH] gc.sh: avoid unlikely ref name repack duplication When repacking during gc, a substitute packed-refs file gets created to make sure that everything that needs to, ends up getting packed properly. However, in order to avoid breaking internal symbolic refs the original heads, notes and remotes refs namespace gets duplicated exactly in the substitute packed-refs file with one exception. A special additional heads ref gets added just to make sure there's always at least one "heads" ref present. While it's very unlikely that the name used for the additional heads ref would be used in practice, it could happen and that would result in two lines for the same ref name but with different values for the hash. Git might perhaps object strongly to that. Let's not find out. Instead suppress the duplicate (from the original ref space) just in case such a scenario ever occurs. The actual original ref value appears elsewhere under a separate partition of the substitute packed-refs refs namespace so there's no danger of losing any objects. As for it being the target of an internal symbolic ref, only the presence of the target is important to avoid breakage, not the actual value, which works out quite well in this case. Signed-off-by: Kyle J. McKay --- jobd/gc.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/jobd/gc.sh b/jobd/gc.sh index a214d40..7e1e0be 100755 --- a/jobd/gc.sh +++ b/jobd/gc.sh @@ -424,17 +424,19 @@ make_repack_dir() { fi # Note: Git v1.5.0 introduced the "# pack-refs with:" header line for the packed-refs file sed '/^# pack-refs/d; s, refs/, refs/!/,' repack/packed-refs + nohead= headref="$(git rev-parse --verify --quiet HEAD)" || : if [ -n "$headref" ]; then echo "$headref refs/!=/HEAD" >>repack/packed-refs echo "$headref refs/heads/!" >>repack/packed-refs + nohead='\, refs/heads/!$,d; ' _lines=$(( $_lines + 2 )) fi if [ $(( $(LC_ALL=C wc -l &2 "[$proj] error: make_repack_dir failed packed-refs initial line count sanity check" exit 1 fi - sed -n '\, refs/heads/,p; \, refs/notes/,p; \, refs/remotes/,p' >repack/packed-refs + sed -n "$nohead"'\, refs/heads/,p; \, refs/notes/,p; \, refs/remotes/,p' >repack/packed-refs _newlines="$(( $(LC_ALL=C wc -l &2 "[$proj] error: make_repack_dir failed packed-refs extra line count sanity check" -- 2.11.4.GIT