void clear_commit_marks(struct commit *commit, unsigned int mark)
{
- struct commit_list *parents;
+ while (commit) {
+ struct commit_list *parents;
- commit->object.flags &= ~mark;
- parents = commit->parents;
- while (parents) {
- struct commit *parent = parents->item;
+ if (!(mark & commit->object.flags))
+ return;
- /* Have we already cleared this? */
- if (mark & parent->object.flags)
- clear_commit_marks(parent, mark);
- parents = parents->next;
+ commit->object.flags &= ~mark;
+
+ parents = commit->parents;
+ if (!parents)
+ return;
+
+ while ((parents = parents->next))
+ clear_commit_marks(parents->item, mark);
+
+ commit = commit->parents->item;
}
}
if (eol - line > key_len &&
!strncmp(line, key, key_len) &&
line[key_len] == ' ') {
- int len = eol - line - key_len;
- char *ret = xmalloc(len);
- memcpy(ret, line + key_len + 1, len - 1);
- ret[len - 1] = '\0';
- return ret;
+ return xmemdupz(line + key_len + 1, eol - line - key_len - 1);
}
line = next;
}
strbuf_attach(&tmp, buf, strlen(buf), strlen(buf) + 1);
if (is_encoding_utf8(encoding)) {
/* we have re-coded to UTF-8; drop the header */
- strbuf_splice(&tmp, start, len, NULL, 0);
+ strbuf_remove(&tmp, start, len);
} else {
/* just replaces XXXX in 'encoding XXXX\n' */
strbuf_splice(&tmp, start + strlen("encoding "),
len - strlen("encoding \n"),
encoding, strlen(encoding));
}
- return tmp.buf;
+ return strbuf_detach(&tmp, NULL);
}
static char *logmsg_reencode(const struct commit *commit,
start = end + 1;
while (end > 0 && isspace(msg[end - 1]))
end--;
- table[0].value = xstrndup(msg, end);
+ table[0].value = xmemdupz(msg, end);
if (start >= len)
return;
if (end >= len)
return;
- table[1].value = xstrndup(msg + start, end - start);
+ table[1].value = xmemdupz(msg + start, end - start);
/* parse date */
for (start = end + 1; start < len && isspace(msg[start]); start++)
if (msg + start == ep)
return;
- table[5].value = xstrndup(msg + start, ep - (msg + start));
+ table[5].value = xmemdupz(msg + start, ep - (msg + start));
/* parse tz */
for (start = ep - msg + 1; start < len && isspace(msg[start]); start++)
; /* do nothing */
if (state == SUBJECT) {
- table[ISUBJECT].value = xstrndup(msg + i, eol - i);
+ table[ISUBJECT].value = xmemdupz(msg + i, eol - i);
i = eol;
}
if (i == eol) {
msg + i + 10, eol - i - 10);
else if (!prefixcmp(msg + i, "encoding "))
table[IENCODING].value =
- xstrndup(msg + i + 9, eol - i - 9);
+ xmemdupz(msg + i + 9, eol - i - 9);
i = eol;
}
if (msg[i])
table[IBODY].value = xstrdup(msg + i);
- for (i = 0; i < ARRAY_SIZE(table); i++)
- if (!table[i].value)
- interp_set_entry(table, i, "<unknown>");
len = interpolate(sb->buf + sb->len, strbuf_avail(sb),
format, table, ARRAY_SIZE(table));