Skip to content

Commit a2cd709

Browse files
bedhangergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f61d89e commit a2cd709

File tree

6 files changed

+33
-3
lines changed

6 files changed

+33
-3
lines changed

Documentation/git.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,15 @@ of clones and fetches.
709709
the background which do not want to cause lock contention with
710710
other operations on the repository. Defaults to `1`.
711711

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+
712721
Discussion[[Discussion]]
713722
------------------------
714723

cache.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,4 +1942,10 @@ void sleep_millisec(int millisec);
19421942
*/
19431943
void safe_create_dir(const char *dir, int share);
19441944

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+
19451951
#endif /* CACHE_H */

environment.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,18 @@ int use_optional_locks(void)
343343
{
344344
return git_env_bool(GIT_OPTIONAL_LOCKS_ENVIRONMENT, 1);
345345
}
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ test_expect_success 'setup: create subprojects' '
1919
git update-index --add sub1 &&
2020
git add sub2 &&
2121
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 &&
2323
git branch save HEAD &&
2424
cat >expected <<-\EOF &&
2525
:000000 160000 00000... A sub1

t/t4013-diff-various.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ do
131131
test_expect_success "git $cmd" '
132132
{
133133
echo "\$ git $cmd"
134-
git $cmd |
134+
GIT_PRINT_SHA1_ELLIPSIS="yes" git $cmd |
135135
sed -e "s/^\\(-*\\)$V\\(-*\\)\$/\\1g-i-t--v-e-r-s-i-o-n\2/" \
136136
-e "s/^\\(.*mixed; boundary=\"-*\\)$V\\(-*\\)\"\$/\\1g-i-t--v-e-r-s-i-o-n\2\"/"
137137
echo "\$"

t/t9300-fast-import.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ test_expect_success 'L: verify internal tree sorting' '
876876
EXPECT_END
877877
878878
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 &&
880880
test_cmp expect output
881881
'
882882

0 commit comments

Comments
 (0)