Skip to content

Commit 337e3f2

Browse files
committed
Merge branch 'rs/nth-switch-code-simplification'
Code simplification. * rs/nth-switch-code-simplification: sha1_name: simplify strbuf handling in interpret_nth_prior_checkout()
2 parents 8f53fe1 + 4b3aa17 commit 337e3f2

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

sha1-name.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ static int get_oid_oneline(struct repository *r,
12951295

12961296
struct grab_nth_branch_switch_cbdata {
12971297
int remaining;
1298-
struct strbuf buf;
1298+
struct strbuf *sb;
12991299
};
13001300

13011301
static int grab_nth_branch_switch(struct object_id *ooid, struct object_id *noid,
@@ -1313,8 +1313,8 @@ static int grab_nth_branch_switch(struct object_id *ooid, struct object_id *noid
13131313
return 0;
13141314
if (--(cb->remaining) == 0) {
13151315
len = target - match;
1316-
strbuf_reset(&cb->buf);
1317-
strbuf_add(&cb->buf, match, len);
1316+
strbuf_reset(cb->sb);
1317+
strbuf_add(cb->sb, match, len);
13181318
return 1; /* we are done */
13191319
}
13201320
return 0;
@@ -1347,18 +1347,15 @@ static int interpret_nth_prior_checkout(struct repository *r,
13471347
if (nth <= 0)
13481348
return -1;
13491349
cb.remaining = nth;
1350-
strbuf_init(&cb.buf, 20);
1350+
cb.sb = buf;
13511351

13521352
retval = refs_for_each_reflog_ent_reverse(get_main_ref_store(r),
13531353
"HEAD", grab_nth_branch_switch, &cb);
13541354
if (0 < retval) {
1355-
strbuf_reset(buf);
1356-
strbuf_addbuf(buf, &cb.buf);
13571355
retval = brace - name + 1;
13581356
} else
13591357
retval = 0;
13601358

1361-
strbuf_release(&cb.buf);
13621359
return retval;
13631360
}
13641361

0 commit comments

Comments
 (0)