]> git.ipfire.org Git - thirdparty/git.git/commitdiff
print_sha1_ellipsis: introduce helper
authorAnn T Ropea <bedhanger@gmx.de>
Sun, 3 Dec 2017 21:27:39 +0000 (22:27 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 4 Dec 2017 16:25:35 +0000 (08:25 -0800)
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>
Documentation/git.txt
cache.h
environment.c
t/t3040-subprojects-basic.sh
t/t4013-diff-various.sh
t/t9300-fast-import.sh

index 7a1d629ca068059d274da66728eb7f886b43081d..6ec871b91057869801f48e9a07c3f027b9383db2 100644 (file)
@@ -709,6 +709,15 @@ of clones and fetches.
        the background which do not want to cause lock contention with
        other operations on the repository.  Defaults to `1`.
 
+`GIT_PRINT_SHA1_ELLIPSIS` (deprecated)::
+       If set to `yes`, print an ellipsis following an
+       (abbreviated) SHA-1 value.  This affects indications of
+       detached HEADs (linkgit:git-checkout[1]) and the raw
+       diff output (linkgit:git-diff[1]).  Printing an
+       ellipsis in the cases mentioned is no longer considered
+       adequate and support for it is likely to be removed in the
+       foreseeable future (along with the variable).
+
 Discussion[[Discussion]]
 ------------------------
 
diff --git a/cache.h b/cache.h
index d74f00d8db2035c5109e2bf00a1ea25c14c7f24c..100317823e03b517db8c809f85cbd58dcb90f06c 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1942,4 +1942,10 @@ void sleep_millisec(int millisec);
  */
 void safe_create_dir(const char *dir, int share);
 
+/*
+ * Should we print an ellipsis after an abbreviated SHA-1 value
+ * when doing diff-raw output or indicating a detached HEAD?
+ */
+extern int print_sha1_ellipsis(void);
+
 #endif /* CACHE_H */
index 8289c25b44d74a0f054f9fe3eaf44c5fdcf0b3d2..a3abdd3c586da99f0d48711a52fd0014f2699e85 100644 (file)
@@ -343,3 +343,18 @@ int use_optional_locks(void)
 {
        return git_env_bool(GIT_OPTIONAL_LOCKS_ENVIRONMENT, 1);
 }
+
+int print_sha1_ellipsis(void)
+{
+       /*
+        * Determine if the calling environment contains the variable
+        * GIT_PRINT_SHA1_ELLIPSIS set to "yes".
+        */
+       static int cached_result = -1; /* unknown */
+
+       if (cached_result < 0) {
+               const char *v = getenv("GIT_PRINT_SHA1_ELLIPSIS");
+               cached_result = (v && !strcasecmp(v, "yes"));
+       }
+       return cached_result;
+}
index 0a4ff6d824a0a3bf44ba8d93c2a8dffdb9c1af65..b81eb5fd6ffaf02d2a404bcbbf71e674494fd6cb 100755 (executable)
@@ -19,7 +19,7 @@ test_expect_success 'setup: create subprojects' '
        git update-index --add sub1 &&
        git add sub2 &&
        git commit -q -m "subprojects added" &&
-       git diff-tree --abbrev=5 HEAD^ HEAD |cut -d" " -f-3,5- >current &&
+       GIT_PRINT_SHA1_ELLIPSIS="yes" git diff-tree --abbrev=5 HEAD^ HEAD |cut -d" " -f-3,5- >current &&
        git branch save HEAD &&
        cat >expected <<-\EOF &&
        :000000 160000 00000... A       sub1
index c515e3e53feef29fd6c7434e13d52b3ea913e167..9bed64d53e012db79acaf1c116367647049ed0d3 100755 (executable)
@@ -131,7 +131,7 @@ do
        test_expect_success "git $cmd" '
                {
                        echo "\$ git $cmd"
-                       git $cmd |
+                       GIT_PRINT_SHA1_ELLIPSIS="yes" git $cmd |
                        sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
                            -e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
                        echo "\$"
index d47560b6343db7006461259e4808837f3d35eecb..e4d06accc458191d0d52fe325b3118ac019e96c2 100755 (executable)
@@ -876,7 +876,7 @@ test_expect_success 'L: verify internal tree sorting' '
        EXPECT_END
 
        git fast-import <input &&
-       git diff-tree --abbrev --raw L^ L >output &&
+       GIT_PRINT_SHA1_ELLIPSIS="yes" git diff-tree --abbrev --raw L^ L >output &&
        test_cmp expect output
 '