diff_aligned_abbrev: use "struct oid"
Since we're modifying this function anyway, it's a good time to update it to the more modern "struct oid". We can also drop some of the magic numbers in favor of GIT_SHA1_HEXSZ, along with some descriptive comments. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Oct 20, 2016 at 02:20 UTC
d6cece51b83db5d8a523c4ba857013c4242e310e
3 files changed
+14
-12
combine-diff.c
+2
-2
@@ -1203,9 +1203,9 @@ static void show_raw_diff(struct combine_diff_path *p, int num_parent, struct re
1203
1204
/* Show sha1's */
1205
for (i = 0; i < num_parent; i++)
1206
- printf(" %s", diff_aligned_abbrev(p->parent[i].oid.hash,
1206
+ printf(" %s", diff_aligned_abbrev(&p->parent[i].oid,
1207
opt->abbrev));
1208
- printf(" %s ", diff_aligned_abbrev(p->oid.hash, opt->abbrev));
1208
+ printf(" %s ", diff_aligned_abbrev(&p->oid, opt->abbrev));
1209
}
1210
1211
if (opt->output_format & (DIFF_FORMAT_RAW | DIFF_FORMAT_NAME_STATUS)) {
diff.c
+11
-9
@@ -4157,14 +4157,15 @@ void diff_free_filepair(struct diff_filepair *p)
4157
free(p);
4158
}
4159
4160
-const char *diff_aligned_abbrev(const unsigned char *sha1, int len)
4160
+const char *diff_aligned_abbrev(const struct object_id *oid, int len)
4161
{
4162
int abblen;
4163
const char *abbrev;
4164
- if (len == 40)
4165
- return sha1_to_hex(sha1);
4164
4167
- abbrev = find_unique_abbrev(sha1, len);
4165
+ if (len == GIT_SHA1_HEXSZ)
4166
+ return oid_to_hex(oid);
4167
+
4168
+ abbrev = find_unique_abbrev(oid->hash, len);
4169
abblen = strlen(abbrev);
4170
4171
/*
@@ -4186,15 +4187,16 @@ const char *diff_aligned_abbrev(const unsigned char *sha1, int len)
4187
* the automatic sizing is supposed to give abblen that ensures
4188
* uniqueness across all objects (statistically speaking).
4189
*/
4189
- if (abblen < 37) {
4190
- static char hex[41];
4190
+ if (abblen < GIT_SHA1_HEXSZ - 3) {
4191
+ static char hex[GIT_SHA1_HEXSZ + 1];
4192
if (len < abblen && abblen <= len + 2)
4193
xsnprintf(hex, sizeof(hex), "%s%.*s", abbrev, len+3-abblen, "..");
4194
else
4195
xsnprintf(hex, sizeof(hex), "%s...", abbrev);
4196
return hex;
4197
}
4197
- return sha1_to_hex(sha1);
4198
+
4199
+ return oid_to_hex(oid);
4200
}
4201
4202
static void diff_flush_raw(struct diff_filepair *p, struct diff_options *opt)
@@ -4205,9 +4207,9 @@ static void diff_flush_raw(struct diff_filepair *p, struct diff_options *opt)
4207
fprintf(opt->file, "%s", diff_line_prefix(opt));
4208
if (!(opt->output_format & DIFF_FORMAT_NAME_STATUS)) {
4209
fprintf(opt->file, ":%06o %06o %s ", p->one->mode, p->two->mode,
4208
- diff_aligned_abbrev(p->one->oid.hash, opt->abbrev));
4210
+ diff_aligned_abbrev(&p->one->oid, opt->abbrev));
4211
fprintf(opt->file, "%s ",
4210
- diff_aligned_abbrev(p->two->oid.hash, opt->abbrev));
4212
+ diff_aligned_abbrev(&p->two->oid, opt->abbrev));
4213
}
4214
if (p->score) {
4215
fprintf(opt->file, "%c%03d%c", p->status, similarity_index(p),
diff.h
+1
-1
@@ -344,7 +344,7 @@ extern void diff_warn_rename_limit(const char *varname, int needed, int degraded
344
* This is different from find_unique_abbrev() in that
345
* it stuffs the result with dots for alignment.
346
*/
347
-extern const char *diff_aligned_abbrev(const unsigned char *sha1, int);
347
+extern const char *diff_aligned_abbrev(const struct object_id *sha1, int);
348
349
/* do not report anything on removed paths */
350
#define DIFF_SILENT_ON_REMOVED 01