Skip to content

Commit 8d7fefa

Browse files
committed
Merge branch 'ar/unconfuse-three-dots'
Ancient part of codebase still shows dots after an abbreviated object name just to show that it is not a full object name, but these ellipses are confusing to people who newly discovered Git who are used to seeing abbreviated object names and find them confusing with the range syntax. * ar/unconfuse-three-dots: t2020: test variations that matter t4013: test new output from diff --abbrev --raw diff: diff_aligned_abbrev: remove ellipsis after abbreviated SHA-1 value t4013: prepare for upcoming "diff --raw --abbrev" output format change checkout: describe_detached_head: remove ellipsis after committish print_sha1_ellipsis: introduce helper Documentation: user-manual: limit usage of ellipsis Documentation: revisions: fix typo: "three dot" ---> "three-dot" (in line with "two-dot").
2 parents 66d3f19 + 64a5e98 commit 8d7fefa

25 files changed

+458
-24
lines changed

Documentation/git.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,15 @@ corresponding standard handle, and if `GIT_REDIRECT_STDERR` is
736736
`2>&1`, standard error will be redirected to the same handle as
737737
standard output.
738738

739+
`GIT_PRINT_SHA1_ELLIPSIS` (deprecated)::
740+
If set to `yes`, print an ellipsis following an
741+
(abbreviated) SHA-1 value. This affects indications of
742+
detached HEADs (linkgit:git-checkout[1]) and the raw
743+
diff output (linkgit:git-diff[1]). Printing an
744+
ellipsis in the cases mentioned is no longer considered
745+
adequate and support for it is likely to be removed in the
746+
foreseeable future (along with the variable).
747+
739748
Discussion[[Discussion]]
740749
------------------------
741750

Documentation/revisions.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ The '..' (two-dot) Range Notation::
271271
for commits that are reachable from r2 excluding those that are reachable
272272
from r1 by '{caret}r1 r2' and it can be written as 'r1..r2'.
273273

274-
The '...' (three dot) Symmetric Difference Notation::
274+
The '...' (three-dot) Symmetric Difference Notation::
275275
A similar notation 'r1\...r2' is called symmetric difference
276276
of 'r1' and 'r2' and is defined as
277277
'r1 r2 --not $(git merge-base --all r1 r2)'.

Documentation/user-manual.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ do so (now or later) by using -b with the checkout command again. Example:
319319

320320
git checkout -b new_branch_name
321321

322-
HEAD is now at 427abfa... Linux v2.6.17
322+
HEAD is now at 427abfa Linux v2.6.17
323323
------------------------------------------------
324324

325325
The HEAD then refers to the SHA-1 of the commit instead of to a branch,
@@ -508,7 +508,7 @@ Bisecting: 3537 revisions left to test after this
508508

509509
If you run `git branch` at this point, you'll see that Git has
510510
temporarily moved you in "(no branch)". HEAD is now detached from any
511-
branch and points directly to a commit (with commit id 65934...) that
511+
branch and points directly to a commit (with commit id 65934) that
512512
is reachable from "master" but not from v2.6.18. Compile and test it,
513513
and see whether it crashes. Assume it does crash. Then:
514514

@@ -549,14 +549,14 @@ says "bisect". Choose a safe-looking commit nearby, note its commit
549549
id, and check it out with:
550550

551551
-------------------------------------------------
552-
$ git reset --hard fb47ddb2db...
552+
$ git reset --hard fb47ddb2db
553553
-------------------------------------------------
554554

555555
then test, run `bisect good` or `bisect bad` as appropriate, and
556556
continue.
557557

558558
Instead of `git bisect visualize` and then `git reset --hard
559-
fb47ddb2db...`, you might just want to tell Git that you want to skip
559+
fb47ddb2db`, you might just want to tell Git that you want to skip
560560
the current commit:
561561

562562
-------------------------------------------------
@@ -3416,15 +3416,15 @@ commit abc
34163416
Author:
34173417
Date:
34183418
...
3419-
:100644 100644 4b9458b... newsha... M somedirectory/myfile
3419+
:100644 100644 4b9458b newsha M somedirectory/myfile
34203420

34213421

34223422
commit xyz
34233423
Author:
34243424
Date:
34253425

34263426
...
3427-
:100644 100644 oldsha... 4b9458b... M somedirectory/myfile
3427+
:100644 100644 oldsha 4b9458b M somedirectory/myfile
34283428
------------------------------------------------
34293429

34303430
This tells you that the immediately following version of the file was
@@ -3449,7 +3449,7 @@ and your repository is good again!
34493449
$ git log --raw --all
34503450
------------------------------------------------
34513451

3452-
and just looked for the sha of the missing object (4b9458b..) in that
3452+
and just looked for the sha of the missing object (4b9458b) in that
34533453
whole thing. It's up to you--Git does *have* a lot of information, it is
34543454
just missing one particular blob version.
34553455

@@ -4114,9 +4114,9 @@ program, e.g. `diff3`, `merge`, or Git's own merge-file, on
41144114
the blob objects from these three stages yourself, like this:
41154115

41164116
------------------------------------------------
4117-
$ git cat-file blob 263414f... >hello.c~1
4118-
$ git cat-file blob 06fa6a2... >hello.c~2
4119-
$ git cat-file blob cc44c73... >hello.c~3
4117+
$ git cat-file blob 263414f >hello.c~1
4118+
$ git cat-file blob 06fa6a2 >hello.c~2
4119+
$ git cat-file blob cc44c73 >hello.c~3
41204120
$ git merge-file hello.c~2 hello.c~1 hello.c~3
41214121
------------------------------------------------
41224122

@@ -4374,7 +4374,7 @@ $ git log --no-merges t/
43744374
------------------------
43754375

43764376
In the pager (`less`), just search for "bundle", go a few lines back,
4377-
and see that it is in commit 18449ab0... Now just copy this object name,
4377+
and see that it is in commit 18449ab0. Now just copy this object name,
43784378
and paste it into the command line
43794379

43804380
-------------------

builtin/checkout.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,16 @@ static void show_local_changes(struct object *head,
401401
static void describe_detached_head(const char *msg, struct commit *commit)
402402
{
403403
struct strbuf sb = STRBUF_INIT;
404+
404405
if (!parse_commit(commit))
405406
pp_commit_easy(CMIT_FMT_ONELINE, commit, &sb);
406-
fprintf(stderr, "%s %s... %s\n", msg,
407-
find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV), sb.buf);
407+
if (print_sha1_ellipsis()) {
408+
fprintf(stderr, "%s %s... %s\n", msg,
409+
find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV), sb.buf);
410+
} else {
411+
fprintf(stderr, "%s %s %s\n", msg,
412+
find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV), sb.buf);
413+
}
408414
strbuf_release(&sb);
409415
}
410416

cache.h

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

1975+
/*
1976+
* Should we print an ellipsis after an abbreviated SHA-1 value
1977+
* when doing diff-raw output or indicating a detached HEAD?
1978+
*/
1979+
extern int print_sha1_ellipsis(void);
1980+
19751981
#endif /* CACHE_H */

diff.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4920,14 +4920,20 @@ const char *diff_aligned_abbrev(const struct object_id *oid, int len)
49204920
int abblen;
49214921
const char *abbrev;
49224922

4923+
/* Do we want all 40 hex characters? */
49234924
if (len == GIT_SHA1_HEXSZ)
49244925
return oid_to_hex(oid);
49254926

4927+
/* An abbreviated value is fine, possibly followed by an ellipsis. */
49264928
abbrev = diff_abbrev_oid(oid, len);
4929+
4930+
if (!print_sha1_ellipsis())
4931+
return abbrev;
4932+
49274933
abblen = strlen(abbrev);
49284934

49294935
/*
4930-
* In well-behaved cases, where the abbbreviated result is the
4936+
* In well-behaved cases, where the abbreviated result is the
49314937
* same as the requested length, append three dots after the
49324938
* abbreviation (hence the whole logic is limited to the case
49334939
* where abblen < 37); when the actual abbreviated result is a

environment.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,3 +344,18 @@ int use_optional_locks(void)
344344
{
345345
return git_env_bool(GIT_OPTIONAL_LOCKS_ENVIRONMENT, 1);
346346
}
347+
348+
int print_sha1_ellipsis(void)
349+
{
350+
/*
351+
* Determine if the calling environment contains the variable
352+
* GIT_PRINT_SHA1_ELLIPSIS set to "yes".
353+
*/
354+
static int cached_result = -1; /* unknown */
355+
356+
if (cached_result < 0) {
357+
const char *v = getenv("GIT_PRINT_SHA1_ELLIPSIS");
358+
cached_result = (v && !strcasecmp(v, "yes"));
359+
}
360+
return cached_result;
361+
}

t/t2020-checkout-detach.sh

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,127 @@ test_expect_success 'no advice given for explicit detached head state' '
186186
test_cmp expect.no-advice actual
187187
'
188188

189+
# Detached HEAD tests for GIT_PRINT_SHA1_ELLIPSIS (new format)
190+
test_expect_success 'describe_detached_head prints no SHA-1 ellipsis when not asked to' "
191+
192+
# The first detach operation is more chatty than the following ones.
193+
cat >1st_detach <<-'EOF' &&
194+
Note: checking out 'HEAD^'.
195+
196+
You are in 'detached HEAD' state. You can look around, make experimental
197+
changes and commit them, and you can discard any commits you make in this
198+
state without impacting any branches by performing another checkout.
199+
200+
If you want to create a new branch to retain commits you create, you may
201+
do so (now or later) by using -b with the checkout command again. Example:
202+
203+
git checkout -b <new-branch-name>
204+
205+
HEAD is now at 7c7cd714e262 three
206+
EOF
207+
208+
# The remaining ones just show info about previous and current HEADs.
209+
cat >2nd_detach <<-'EOF' &&
210+
Previous HEAD position was 7c7cd714e262 three
211+
HEAD is now at 139b20d8e6c5 two
212+
EOF
213+
214+
cat >3rd_detach <<-'EOF' &&
215+
Previous HEAD position was 139b20d8e6c5 two
216+
HEAD is now at d79ce1670bdc one
217+
EOF
218+
219+
reset &&
220+
check_not_detached &&
221+
222+
# Various ways of *not* asking for ellipses
223+
224+
sane_unset GIT_PRINT_SHA1_ELLIPSIS &&
225+
git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
226+
check_detached &&
227+
test_i18ncmp 1st_detach actual &&
228+
229+
GIT_PRINT_SHA1_ELLIPSIS="no" git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
230+
check_detached &&
231+
test_i18ncmp 2nd_detach actual &&
232+
233+
GIT_PRINT_SHA1_ELLIPSIS= git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
234+
check_detached &&
235+
test_i18ncmp 3rd_detach actual &&
236+
237+
sane_unset GIT_PRINT_SHA1_ELLIPSIS &&
238+
239+
# We only have four commits, but we can re-use them
240+
reset &&
241+
check_not_detached &&
242+
243+
# Make no mention of the env var at all
244+
git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
245+
check_detached &&
246+
test_i18ncmp 1st_detach actual &&
247+
248+
GIT_PRINT_SHA1_ELLIPSIS='nope' &&
249+
git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
250+
check_detached &&
251+
test_i18ncmp 2nd_detach actual &&
252+
253+
GIT_PRINT_SHA1_ELLIPSIS=nein &&
254+
git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
255+
check_detached &&
256+
test_i18ncmp 3rd_detach actual &&
257+
258+
true
259+
"
260+
261+
# Detached HEAD tests for GIT_PRINT_SHA1_ELLIPSIS (old format)
262+
test_expect_success 'describe_detached_head does print SHA-1 ellipsis when asked to' "
263+
264+
# The first detach operation is more chatty than the following ones.
265+
cat >1st_detach <<-'EOF' &&
266+
Note: checking out 'HEAD^'.
267+
268+
You are in 'detached HEAD' state. You can look around, make experimental
269+
changes and commit them, and you can discard any commits you make in this
270+
state without impacting any branches by performing another checkout.
271+
272+
If you want to create a new branch to retain commits you create, you may
273+
do so (now or later) by using -b with the checkout command again. Example:
274+
275+
git checkout -b <new-branch-name>
276+
277+
HEAD is now at 7c7cd714e262... three
278+
EOF
279+
280+
# The remaining ones just show info about previous and current HEADs.
281+
cat >2nd_detach <<-'EOF' &&
282+
Previous HEAD position was 7c7cd714e262... three
283+
HEAD is now at 139b20d8e6c5... two
284+
EOF
285+
286+
cat >3rd_detach <<-'EOF' &&
287+
Previous HEAD position was 139b20d8e6c5... two
288+
HEAD is now at d79ce1670bdc... one
289+
EOF
290+
291+
reset &&
292+
check_not_detached &&
293+
294+
# Various ways of asking for ellipses...
295+
# The user can just use any kind of quoting (including none).
296+
297+
GIT_PRINT_SHA1_ELLIPSIS=yes git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
298+
check_detached &&
299+
test_i18ncmp 1st_detach actual &&
300+
301+
GIT_PRINT_SHA1_ELLIPSIS=Yes git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
302+
check_detached &&
303+
test_i18ncmp 2nd_detach actual &&
304+
305+
GIT_PRINT_SHA1_ELLIPSIS=YES git -c 'core.abbrev=12' checkout HEAD^ >actual 2>&1 &&
306+
check_detached &&
307+
test_i18ncmp 3rd_detach actual &&
308+
309+
true
310+
"
311+
189312
test_done

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

0 commit comments

Comments
 (0)