Skip to content

Commit 69e6544

Browse files
committed
Merge branch 'rs/cocci'
Code cleanup. * rs/cocci: use strbuf_add_unique_abbrev() for adding short hashes, part 3 remove unnecessary NULL check before free(3)
2 parents 9424bf2 + a94bb68 commit 69e6544

File tree

6 files changed

+21
-22
lines changed

6 files changed

+21
-22
lines changed

contrib/coccinelle/free.cocci

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@@
2+
expression E;
3+
@@
4+
- if (E)
5+
free(E);

merge-recursive.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ static void output_commit_title(struct merge_options *o, struct commit *commit)
202202
strbuf_addf(&o->obuf, "virtual %s\n",
203203
merge_remote_util(commit)->name);
204204
else {
205-
strbuf_addf(&o->obuf, "%s ",
206-
find_unique_abbrev(commit->object.oid.hash,
207-
DEFAULT_ABBREV));
205+
strbuf_add_unique_abbrev(&o->obuf, commit->object.oid.hash,
206+
DEFAULT_ABBREV);
207+
strbuf_addch(&o->obuf, ' ');
208208
if (parse_commit(commit) != 0)
209209
strbuf_addstr(&o->obuf, _("(bad commit)\n"));
210210
else {

parse-options-cb.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ int parse_opt_passthru(const struct option *opt, const char *arg, int unset)
211211
if (recreate_opt(&sb, opt, arg, unset) < 0)
212212
return -1;
213213

214-
if (*opt_value)
215-
free(*opt_value);
214+
free(*opt_value);
216215

217216
*opt_value = strbuf_detach(&sb, NULL);
218217

pretty.c

+5-7
Original file line numberDiff line numberDiff line change
@@ -544,15 +544,13 @@ static void add_merge_info(const struct pretty_print_context *pp,
544544
strbuf_addstr(sb, "Merge:");
545545

546546
while (parent) {
547-
struct commit *p = parent->item;
548-
const char *hex = NULL;
547+
struct object_id *oidp = &parent->item->object.oid;
548+
strbuf_addch(sb, ' ');
549549
if (pp->abbrev)
550-
hex = find_unique_abbrev(p->object.oid.hash, pp->abbrev);
551-
if (!hex)
552-
hex = oid_to_hex(&p->object.oid);
550+
strbuf_add_unique_abbrev(sb, oidp->hash, pp->abbrev);
551+
else
552+
strbuf_addstr(sb, oid_to_hex(oidp));
553553
parent = parent->next;
554-
555-
strbuf_addf(sb, " %s", hex);
556554
}
557555
strbuf_addch(sb, '\n');
558556
}

submodule.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,9 @@ static void show_submodule_header(FILE *f, const char *path,
371371
}
372372

373373
output_header:
374-
strbuf_addf(&sb, "%s%sSubmodule %s %s..", line_prefix, meta, path,
375-
find_unique_abbrev(one->hash, DEFAULT_ABBREV));
376-
if (!fast_backward && !fast_forward)
377-
strbuf_addch(&sb, '.');
374+
strbuf_addf(&sb, "%s%sSubmodule %s ", line_prefix, meta, path);
375+
strbuf_add_unique_abbrev(&sb, one->hash, DEFAULT_ABBREV);
376+
strbuf_addstr(&sb, (fast_backward || fast_forward) ? ".." : "...");
378377
strbuf_add_unique_abbrev(&sb, two->hash, DEFAULT_ABBREV);
379378
if (message)
380379
strbuf_addf(&sb, " %s%s\n", message, reset);

wt-status.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -1110,17 +1110,17 @@ static void abbrev_sha1_in_line(struct strbuf *line)
11101110
split = strbuf_split_max(line, ' ', 3);
11111111
if (split[0] && split[1]) {
11121112
unsigned char sha1[20];
1113-
const char *abbrev;
11141113

11151114
/*
11161115
* strbuf_split_max left a space. Trim it and re-add
11171116
* it after abbreviation.
11181117
*/
11191118
strbuf_trim(split[1]);
11201119
if (!get_sha1(split[1]->buf, sha1)) {
1121-
abbrev = find_unique_abbrev(sha1, DEFAULT_ABBREV);
11221120
strbuf_reset(split[1]);
1123-
strbuf_addf(split[1], "%s ", abbrev);
1121+
strbuf_add_unique_abbrev(split[1], sha1,
1122+
DEFAULT_ABBREV);
1123+
strbuf_addch(split[1], ' ');
11241124
strbuf_reset(line);
11251125
for (i = 0; split[i]; i++)
11261126
strbuf_addbuf(line, split[i]);
@@ -1343,10 +1343,8 @@ static char *get_branch(const struct worktree *wt, const char *path)
13431343
else if (starts_with(sb.buf, "refs/"))
13441344
;
13451345
else if (!get_sha1_hex(sb.buf, sha1)) {
1346-
const char *abbrev;
1347-
abbrev = find_unique_abbrev(sha1, DEFAULT_ABBREV);
13481346
strbuf_reset(&sb);
1349-
strbuf_addstr(&sb, abbrev);
1347+
strbuf_add_unique_abbrev(&sb, sha1, DEFAULT_ABBREV);
13501348
} else if (!strcmp(sb.buf, "detached HEAD")) /* rebase */
13511349
goto got_nothing;
13521350
else /* bisect */

0 commit comments

Comments
 (0)