Skip to content

Commit 8af3c64

Browse files
committed
Merge branch 'rs/pretty-add-again'
The pretty-format specifiers like '%h', '%t', etc. had an optimization that no longer works correctly. In preparation/hope of getting it correctly implemented, first discard the optimization that is broken. * rs/pretty-add-again: pretty: recalculate duplicate short hashes
2 parents ef94023 + fe9e2ae commit 8af3c64

File tree

3 files changed

+0
-45
lines changed

3 files changed

+0
-45
lines changed

pretty.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -783,29 +783,9 @@ struct format_commit_context {
783783
size_t body_off;
784784

785785
/* The following ones are relative to the result struct strbuf. */
786-
struct chunk abbrev_commit_hash;
787-
struct chunk abbrev_tree_hash;
788-
struct chunk abbrev_parent_hashes;
789786
size_t wrap_start;
790787
};
791788

792-
static int add_again(struct strbuf *sb, struct chunk *chunk)
793-
{
794-
if (chunk->len) {
795-
strbuf_adddup(sb, chunk->off, chunk->len);
796-
return 1;
797-
}
798-
799-
/*
800-
* We haven't seen this chunk before. Our caller is surely
801-
* going to add it the hard way now. Remember the most likely
802-
* start of the to-be-added chunk: the current end of the
803-
* struct strbuf.
804-
*/
805-
chunk->off = sb->len;
806-
return 0;
807-
}
808-
809789
static void parse_commit_header(struct format_commit_context *context)
810790
{
811791
const char *msg = context->message;
@@ -1147,24 +1127,16 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
11471127
return 1;
11481128
case 'h': /* abbreviated commit hash */
11491129
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_COMMIT));
1150-
if (add_again(sb, &c->abbrev_commit_hash)) {
1151-
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));
1152-
return 1;
1153-
}
11541130
strbuf_add_unique_abbrev(sb, commit->object.oid.hash,
11551131
c->pretty_ctx->abbrev);
11561132
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));
1157-
c->abbrev_commit_hash.len = sb->len - c->abbrev_commit_hash.off;
11581133
return 1;
11591134
case 'T': /* tree hash */
11601135
strbuf_addstr(sb, oid_to_hex(&commit->tree->object.oid));
11611136
return 1;
11621137
case 't': /* abbreviated tree hash */
1163-
if (add_again(sb, &c->abbrev_tree_hash))
1164-
return 1;
11651138
strbuf_add_unique_abbrev(sb, commit->tree->object.oid.hash,
11661139
c->pretty_ctx->abbrev);
1167-
c->abbrev_tree_hash.len = sb->len - c->abbrev_tree_hash.off;
11681140
return 1;
11691141
case 'P': /* parent hashes */
11701142
for (p = commit->parents; p; p = p->next) {
@@ -1174,16 +1146,12 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
11741146
}
11751147
return 1;
11761148
case 'p': /* abbreviated parent hashes */
1177-
if (add_again(sb, &c->abbrev_parent_hashes))
1178-
return 1;
11791149
for (p = commit->parents; p; p = p->next) {
11801150
if (p != commit->parents)
11811151
strbuf_addch(sb, ' ');
11821152
strbuf_add_unique_abbrev(sb, p->item->object.oid.hash,
11831153
c->pretty_ctx->abbrev);
11841154
}
1185-
c->abbrev_parent_hashes.len = sb->len -
1186-
c->abbrev_parent_hashes.off;
11871155
return 1;
11881156
case 'm': /* left/right/bottom */
11891157
strbuf_addstr(sb, get_revision_mark(NULL, commit));

strbuf.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,6 @@ void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2)
204204
strbuf_setlen(sb, sb->len + sb2->len);
205205
}
206206

207-
void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len)
208-
{
209-
strbuf_grow(sb, len);
210-
memcpy(sb->buf + sb->len, sb->buf + pos, len);
211-
strbuf_setlen(sb, sb->len + len);
212-
}
213-
214207
void strbuf_addchars(struct strbuf *sb, int c, size_t n)
215208
{
216209
strbuf_grow(sb, n);

strbuf.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,6 @@ static inline void strbuf_addstr(struct strbuf *sb, const char *s)
263263
*/
264264
extern void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2);
265265

266-
/**
267-
* Copy part of the buffer from a given position till a given length to the
268-
* end of the buffer.
269-
*/
270-
extern void strbuf_adddup(struct strbuf *sb, size_t pos, size_t len);
271-
272266
/**
273267
* This function can be used to expand a format string containing
274268
* placeholders. To that end, it parses the string and calls the specified

0 commit comments

Comments
 (0)