MCPcopy Index your code
hub / github.com/git/git / diff_aligned_abbrev

Function diff_aligned_abbrev

diff.c:6421–6467  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6419}
6420
6421const char *diff_aligned_abbrev(const struct object_id *oid, int len)
6422{
6423 int abblen;
6424 const char *abbrev;
6425
6426 /* Do we want all 40 hex characters? */
6427 if (len == the_hash_algo->hexsz)
6428 return oid_to_hex(oid);
6429
6430 /* An abbreviated value is fine, possibly followed by an ellipsis. */
6431 abbrev = diff_abbrev_oid(oid, len);
6432
6433 if (!print_sha1_ellipsis())
6434 return abbrev;
6435
6436 abblen = strlen(abbrev);
6437
6438 /*
6439 * In well-behaved cases, where the abbreviated result is the
6440 * same as the requested length, append three dots after the
6441 * abbreviation (hence the whole logic is limited to the case
6442 * where abblen < 37); when the actual abbreviated result is a
6443 * bit longer than the requested length, we reduce the number
6444 * of dots so that they match the well-behaved ones. However,
6445 * if the actual abbreviation is longer than the requested
6446 * length by more than three, we give up on aligning, and add
6447 * three dots anyway, to indicate that the output is not the
6448 * full object name. Yes, this may be suboptimal, but this
6449 * appears only in "diff --raw --abbrev" output and it is not
6450 * worth the effort to change it now. Note that this would
6451 * likely to work fine when the automatic sizing of default
6452 * abbreviation length is used--we would be fed -1 in "len" in
6453 * that case, and will end up always appending three-dots, but
6454 * the automatic sizing is supposed to give abblen that ensures
6455 * uniqueness across all objects (statistically speaking).
6456 */
6457 if (abblen < the_hash_algo->hexsz - 3) {
6458 static char hex[GIT_MAX_HEXSZ + 1];
6459 if (len < abblen && abblen <= len + 2)
6460 xsnprintf(hex, sizeof(hex), "%s%.*s", abbrev, len+3-abblen, "..");
6461 else
6462 xsnprintf(hex, sizeof(hex), "%s...", abbrev);
6463 return hex;
6464 }
6465
6466 return oid_to_hex(oid);
6467}
6468
6469static void diff_flush_raw(struct diff_filepair *p, struct diff_options *opt)
6470{

Callers 2

show_raw_diffFunction · 0.85
diff_flush_rawFunction · 0.85

Calls 4

oid_to_hexFunction · 0.85
diff_abbrev_oidFunction · 0.85
print_sha1_ellipsisFunction · 0.85
xsnprintfFunction · 0.85

Tested by

no test coverage detected