Skip to content

Commit fe9e2ae

Browse files
rscharfegitster
authored andcommitted
pretty: recalculate duplicate short hashes
b9c6232 (--format=pretty: avoid calculating expensive expansions twice) optimized adding short hashes multiple times by using the fact that the output strbuf was only ever simply appended to and copying the added string from the previous run. That prerequisite is no longer given; we now have modfiers like %< and %+ that can cause the cache to lose track of the correct offsets. Remove it. Reported-by: Michael Giuffrida <[email protected]> Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 840ed14 commit fe9e2ae

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
@@ -782,29 +782,9 @@ struct format_commit_context {
782782
size_t body_off;
783783

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

791-
static int add_again(struct strbuf *sb, struct chunk *chunk)
792-
{
793-
if (chunk->len) {
794-
strbuf_adddup(sb, chunk->off, chunk->len);
795-
return 1;
796-
}
797-
798-
/*
799-
* We haven't seen this chunk before. Our caller is surely
800-
* going to add it the hard way now. Remember the most likely
801-
* start of the to-be-added chunk: the current end of the
802-
* struct strbuf.
803-
*/
804-
chunk->off = sb->len;
805-
return 0;
806-
}
807-
808788
static void parse_commit_header(struct format_commit_context *context)
809789
{
810790
const char *msg = context->message;
@@ -1136,24 +1116,16 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
11361116
return 1;
11371117
case 'h': /* abbreviated commit hash */
11381118
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_COMMIT));
1139-
if (add_again(sb, &c->abbrev_commit_hash)) {
1140-
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));
1141-
return 1;
1142-
}
11431119
strbuf_add_unique_abbrev(sb, commit->object.oid.hash,
11441120
c->pretty_ctx->abbrev);
11451121
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));
1146-
c->abbrev_commit_hash.len = sb->len - c->abbrev_commit_hash.off;
11471122
return 1;
11481123
case 'T': /* tree hash */
11491124
strbuf_addstr(sb, oid_to_hex(&commit->tree->object.oid));
11501125
return 1;
11511126
case 't': /* abbreviated tree hash */
1152-
if (add_again(sb, &c->abbrev_tree_hash))
1153-
return 1;
11541127
strbuf_add_unique_abbrev(sb, commit->tree->object.oid.hash,
11551128
c->pretty_ctx->abbrev);
1156-
c->abbrev_tree_hash.len = sb->len - c->abbrev_tree_hash.off;
11571129
return 1;
11581130
case 'P': /* parent hashes */
11591131
for (p = commit->parents; p; p = p->next) {
@@ -1163,16 +1135,12 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
11631135
}
11641136
return 1;
11651137
case 'p': /* abbreviated parent hashes */
1166-
if (add_again(sb, &c->abbrev_parent_hashes))
1167-
return 1;
11681138
for (p = commit->parents; p; p = p->next) {
11691139
if (p != commit->parents)
11701140
strbuf_addch(sb, ' ');
11711141
strbuf_add_unique_abbrev(sb, p->item->object.oid.hash,
11721142
c->pretty_ctx->abbrev);
11731143
}
1174-
c->abbrev_parent_hashes.len = sb->len -
1175-
c->abbrev_parent_hashes.off;
11761144
return 1;
11771145
case 'm': /* left/right/bottom */
11781146
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
@@ -265,12 +265,6 @@ static inline void strbuf_addstr(struct strbuf *sb, const char *s)
265265
*/
266266
extern void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2);
267267

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

0 commit comments

Comments
 (0)