print_sha1_ellipsis: introduce helper

Introduce a helper print_sha1_ellipsis() that pays attention to the GIT_PRINT_SHA1_ELLIPSIS environment variable, and prepare the tests to unconditionally set it for the test pieces that will be broken once the code stops showing the extra dots by default. The removal of these dots is merely a plan at this step and has not happened yet but soon will. Document GIT_PRINT_SHA1_ELLIPSIS. Signed-off-by: Ann T Ropea <bedhanger@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ann T Ropea committed Dec 3, 2017 at 22:27 UTC a2cd709de314a7bfa038e14fd36f1d21077b4173
6 files changed +33 -3
Documentation/git.txt
+9
@@ -709,6 +709,15 @@ of clones and fetches.
709 the background which do not want to cause lock contention with
710 other operations on the repository. Defaults to `1`.
711
712 +`GIT_PRINT_SHA1_ELLIPSIS` (deprecated)::
713 + If set to `yes`, print an ellipsis following an
714 + (abbreviated) SHA-1 value. This affects indications of
715 + detached HEADs (linkgit:git-checkout[1]) and the raw
716 + diff output (linkgit:git-diff[1]). Printing an
717 + ellipsis in the cases mentioned is no longer considered
718 + adequate and support for it is likely to be removed in the
719 + foreseeable future (along with the variable).
720 +
721 Discussion[[Discussion]]
722 ------------------------
723
cache.h
+6
@@ -1942,4 +1942,10 @@ void sleep_millisec(int millisec);
1942 */
1943 void safe_create_dir(const char *dir, int share);
1944
1945 +/*
1946 + * Should we print an ellipsis after an abbreviated SHA-1 value
1947 + * when doing diff-raw output or indicating a detached HEAD?
1948 + */
1949 +extern int print_sha1_ellipsis(void);
1950 +
1951 #endif /* CACHE_H */
environment.c
+15
@@ -343,3 +343,18 @@ int use_optional_locks(void)
343 {
344 return git_env_bool(GIT_OPTIONAL_LOCKS_ENVIRONMENT, 1);
345 }
346 +
347 +int print_sha1_ellipsis(void)
348 +{
349 + /*
350 + * Determine if the calling environment contains the variable
351 + * GIT_PRINT_SHA1_ELLIPSIS set to "yes".
352 + */
353 + static int cached_result = -1; /* unknown */
354 +
355 + if (cached_result < 0) {
356 + const char *v = getenv("GIT_PRINT_SHA1_ELLIPSIS");
357 + cached_result = (v && !strcasecmp(v, "yes"));
358 + }
359 + return cached_result;
360 +}
t/t3040-subprojects-basic.sh
+1 -1
@@ -19,7 +19,7 @@ test_expect_success 'setup: create subprojects' '
19 git update-index --add sub1 &&
20 git add sub2 &&
21 git commit -q -m "subprojects added" &&
22 - git diff-tree --abbrev=5 HEAD^ HEAD |cut -d" " -f-3,5- >current &&
22 + GIT_PRINT_SHA1_ELLIPSIS="yes" git diff-tree --abbrev=5 HEAD^ HEAD |cut -d" " -f-3,5- >current &&
23 git branch save HEAD &&
24 cat >expected <<-\EOF &&
25 :000000 160000 00000... A sub1
t/t4013-diff-various.sh
+1 -1
@@ -131,7 +131,7 @@ do
131 test_expect_success "git $cmd" '
132 {
133 echo "\$ git $cmd"
134 - git $cmd |
134 + GIT_PRINT_SHA1_ELLIPSIS="yes" git $cmd |
135 sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
136 -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
137 echo "\$"
t/t9300-fast-import.sh
+1 -1
@@ -876,7 +876,7 @@ test_expect_success 'L: verify internal tree sorting' '
876 EXPECT_END
877
878 git fast-import <input &&
879 - git diff-tree --abbrev --raw L^ L >output &&
879 + GIT_PRINT_SHA1_ELLIPSIS="yes" git diff-tree --abbrev --raw L^ L >output &&
880 test_cmp expect output
881 '
882