index ed59e77e1923ee8f0df050dd6851b805a26127a2..14898835649f4156c86f53ecde658009c735ca3f 100644 (file)
--- a/builtin-fmt-merge-msg.c
+++ b/builtin-fmt-merge-msg.c
if (len < 43 || line[40] != '\t')
return 1;
if (len < 43 || line[40] != '\t')
return 1;
- if (!strncmp(line + 41, "not-for-merge", 13))
+ if (!prefixcmp(line + 41, "not-for-merge"))
return 0;
if (line[41] != '\t')
return 0;
if (line[41] != '\t')
i = find_in_list(&srcs, src);
if (i < 0) {
i = srcs.nr;
i = find_in_list(&srcs, src);
if (i < 0) {
i = srcs.nr;
- append_to_list(&srcs, strdup(src),
+ append_to_list(&srcs, xstrdup(src),
xcalloc(1, sizeof(struct src_data)));
}
src_data = srcs.payload[i];
if (pulling_head) {
xcalloc(1, sizeof(struct src_data)));
}
src_data = srcs.payload[i];
if (pulling_head) {
- origin = strdup(src);
+ origin = xstrdup(src);
src_data->head_status |= 1;
src_data->head_status |= 1;
- } else if (!strncmp(line, "branch ", 7)) {
- origin = strdup(line + 7);
+ } else if (!prefixcmp(line, "branch ")) {
+ origin = xstrdup(line + 7);
append_to_list(&src_data->branch, origin, NULL);
src_data->head_status |= 2;
append_to_list(&src_data->branch, origin, NULL);
src_data->head_status |= 2;
- } else if (!strncmp(line, "tag ", 4)) {
+ } else if (!prefixcmp(line, "tag ")) {
origin = line;
origin = line;
- append_to_list(&src_data->tag, strdup(origin + 4), NULL);
+ append_to_list(&src_data->tag, xstrdup(origin + 4), NULL);
src_data->head_status |= 2;
src_data->head_status |= 2;
- } else if (!strncmp(line, "remote branch ", 14)) {
- origin = strdup(line + 14);
+ } else if (!prefixcmp(line, "remote branch ")) {
+ origin = xstrdup(line + 14);
append_to_list(&src_data->r_branch, origin, NULL);
src_data->head_status |= 2;
} else {
append_to_list(&src_data->r_branch, origin, NULL);
src_data->head_status |= 2;
} else {
- origin = strdup(src);
- append_to_list(&src_data->generic, strdup(line), NULL);
+ origin = xstrdup(src);
+ append_to_list(&src_data->generic, xstrdup(line), NULL);
src_data->head_status |= 2;
}
src_data->head_status |= 2;
}
if (origin[0] == '\'' && origin[len - 1] == '\'') {
char *new_origin = xmalloc(len - 1);
memcpy(new_origin, origin + 1, len - 2);
if (origin[0] == '\'' && origin[len - 1] == '\'') {
char *new_origin = xmalloc(len - 1);
memcpy(new_origin, origin + 1, len - 2);
- new_origin[len - 1] = 0;
+ new_origin[len - 2] = 0;
origin = new_origin;
} else
origin = new_origin;
} else
- origin = strdup(origin);
+ origin = xstrdup(origin);
} else {
char *new_origin = xmalloc(strlen(origin) + strlen(src) + 5);
sprintf(new_origin, "%s of %s", origin, src);
} else {
char *new_origin = xmalloc(strlen(origin) + strlen(src) + 5);
sprintf(new_origin, "%s of %s", origin, src);
bol = strstr(commit->buffer, "\n\n");
if (!bol) {
bol = strstr(commit->buffer, "\n\n");
if (!bol) {
- append_to_list(&subjects, strdup(sha1_to_hex(
+ append_to_list(&subjects, xstrdup(sha1_to_hex(
commit->object.sha1)),
NULL);
continue;
commit->object.sha1)),
NULL);
continue;
memcpy(oneline, bol, len);
oneline[len] = 0;
} else
memcpy(oneline, bol, len);
oneline[len] = 0;
} else
- oneline = strdup(bol);
+ oneline = xstrdup(bol);
append_to_list(&subjects, oneline, NULL);
}
append_to_list(&subjects, oneline, NULL);
}
FILE *in = stdin;
const char *sep = "";
unsigned char head_sha1[20];
FILE *in = stdin;
const char *sep = "";
unsigned char head_sha1[20];
- const char *head, *current_branch;
+ const char *current_branch;
git_config(fmt_merge_msg_config);
git_config(fmt_merge_msg_config);
usage(fmt_merge_msg_usage);
/* get current branch */
usage(fmt_merge_msg_usage);
/* get current branch */
- head = strdup(git_path("HEAD"));
- current_branch = resolve_ref(head, head_sha1, 1);
- current_branch += strlen(head) - 4;
- free((char *)head);
- if (!strncmp(current_branch, "refs/heads/", 11))
+ current_branch = resolve_ref("HEAD", head_sha1, 1, NULL);
+ if (!current_branch)
+ die("No current branch");
+ if (!prefixcmp(current_branch, "refs/heads/"))
current_branch += 11;
while (fgets(line, sizeof(line), in)) {
current_branch += 11;
while (fgets(line, sizeof(line), in)) {