pretty: recalculate duplicate short hashes
b9c6232138 (--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 <michaelpg@chromium.org> Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Jun 14, 2017 at 20:24 UTC
fe9e2aefd4adac63821d0c007effcc8087e32ad6
3 files changed
-45
pretty.c
-32
@@ -782,29 +782,9 @@ struct format_commit_context {
782
size_t body_off;
783
784
/* 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;
785
size_t wrap_start;
786
};
787
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
-
788
static void parse_commit_header(struct format_commit_context *context)
789
{
790
const char *msg = context->message;
@@ -1136,24 +1116,16 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1116
return 1;
1117
case 'h': /* abbreviated commit hash */
1118
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
- }
1119
strbuf_add_unique_abbrev(sb, commit->object.oid.hash,
1120
c->pretty_ctx->abbrev);
1121
strbuf_addstr(sb, diff_get_color(c->auto_color, DIFF_RESET));
1146
- c->abbrev_commit_hash.len = sb->len - c->abbrev_commit_hash.off;
1122
return 1;
1123
case 'T': /* tree hash */
1124
strbuf_addstr(sb, oid_to_hex(&commit->tree->object.oid));
1125
return 1;
1126
case 't': /* abbreviated tree hash */
1152
- if (add_again(sb, &c->abbrev_tree_hash))
1153
- return 1;
1127
strbuf_add_unique_abbrev(sb, commit->tree->object.oid.hash,
1128
c->pretty_ctx->abbrev);
1156
- c->abbrev_tree_hash.len = sb->len - c->abbrev_tree_hash.off;
1129
return 1;
1130
case 'P': /* parent hashes */
1131
for (p = commit->parents; p; p = p->next) {
@@ -1163,16 +1135,12 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
1135
}
1136
return 1;
1137
case 'p': /* abbreviated parent hashes */
1166
- if (add_again(sb, &c->abbrev_parent_hashes))
1167
- return 1;
1138
for (p = commit->parents; p; p = p->next) {
1139
if (p != commit->parents)
1140
strbuf_addch(sb, ' ');
1141
strbuf_add_unique_abbrev(sb, p->item->object.oid.hash,
1142
c->pretty_ctx->abbrev);
1143
}
1174
- c->abbrev_parent_hashes.len = sb->len -
1175
- c->abbrev_parent_hashes.off;
1144
return 1;
1145
case 'm': /* left/right/bottom */
1146
strbuf_addstr(sb, get_revision_mark(NULL, commit));
strbuf.c
-7
@@ -204,13 +204,6 @@ void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2)
204
strbuf_setlen(sb, sb->len + sb2->len);
205
}
206
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
-
207
void strbuf_addchars(struct strbuf *sb, int c, size_t n)
208
{
209
strbuf_grow(sb, n);
strbuf.h
-6
@@ -265,12 +265,6 @@ static inline void strbuf_addstr(struct strbuf *sb, const char *s)
265
*/
266
extern void strbuf_addbuf(struct strbuf *sb, const struct strbuf *sb2);
267
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
-
268
/**
269
* This function can be used to expand a format string containing
270
* placeholders. To that end, it parses the string and calls the specified