mirror of
https://github.com/git/git.git
synced 2024-05-09 04:26:08 +02:00
commit: replace the raw buffer with strbuf in read_graft_line
This simplifies function declaration and allows for use of strbuf_rtrim instead of modifying buffer directly. Signed-off-by: Patryk Obara <patryk.obara@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
50c5cd5800
commit
9a9340329a
|
@ -488,7 +488,7 @@ static int read_ancestry(const char *graft_file)
|
||||||
return -1;
|
return -1;
|
||||||
while (!strbuf_getwholeline(&buf, fp, '\n')) {
|
while (!strbuf_getwholeline(&buf, fp, '\n')) {
|
||||||
/* The format is just "Commit Parent1 Parent2 ...\n" */
|
/* The format is just "Commit Parent1 Parent2 ...\n" */
|
||||||
struct commit_graft *graft = read_graft_line(buf.buf, buf.len);
|
struct commit_graft *graft = read_graft_line(&buf);
|
||||||
if (graft)
|
if (graft)
|
||||||
register_commit_graft(graft, 0);
|
register_commit_graft(graft, 0);
|
||||||
}
|
}
|
||||||
|
|
23
commit.c
23
commit.c
|
@ -134,34 +134,33 @@ int register_commit_graft(struct commit_graft *graft, int ignore_dups)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct commit_graft *read_graft_line(char *buf, int len)
|
struct commit_graft *read_graft_line(struct strbuf *line)
|
||||||
{
|
{
|
||||||
/* The format is just "Commit Parent1 Parent2 ...\n" */
|
/* The format is just "Commit Parent1 Parent2 ...\n" */
|
||||||
int i;
|
int i;
|
||||||
struct commit_graft *graft = NULL;
|
struct commit_graft *graft = NULL;
|
||||||
const int entry_size = GIT_SHA1_HEXSZ + 1;
|
const int entry_size = GIT_SHA1_HEXSZ + 1;
|
||||||
|
|
||||||
while (len && isspace(buf[len-1]))
|
strbuf_rtrim(line);
|
||||||
buf[--len] = '\0';
|
if (!line->len || line->buf[0] == '#')
|
||||||
if (buf[0] == '#' || buf[0] == '\0')
|
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((len + 1) % entry_size)
|
if ((line->len + 1) % entry_size)
|
||||||
goto bad_graft_data;
|
goto bad_graft_data;
|
||||||
i = (len + 1) / entry_size - 1;
|
i = (line->len + 1) / entry_size - 1;
|
||||||
graft = xmalloc(st_add(sizeof(*graft), st_mult(GIT_SHA1_RAWSZ, i)));
|
graft = xmalloc(st_add(sizeof(*graft), st_mult(GIT_SHA1_RAWSZ, i)));
|
||||||
graft->nr_parent = i;
|
graft->nr_parent = i;
|
||||||
if (get_oid_hex(buf, &graft->oid))
|
if (get_oid_hex(line->buf, &graft->oid))
|
||||||
goto bad_graft_data;
|
goto bad_graft_data;
|
||||||
for (i = GIT_SHA1_HEXSZ; i < len; i += entry_size) {
|
for (i = GIT_SHA1_HEXSZ; i < line->len; i += entry_size) {
|
||||||
if (buf[i] != ' ')
|
if (line->buf[i] != ' ')
|
||||||
goto bad_graft_data;
|
goto bad_graft_data;
|
||||||
if (get_sha1_hex(buf + i + 1, graft->parent[i/entry_size].hash))
|
if (get_sha1_hex(line->buf + i + 1, graft->parent[i/entry_size].hash))
|
||||||
goto bad_graft_data;
|
goto bad_graft_data;
|
||||||
}
|
}
|
||||||
return graft;
|
return graft;
|
||||||
|
|
||||||
bad_graft_data:
|
bad_graft_data:
|
||||||
error("bad graft data: %s", buf);
|
error("bad graft data: %s", line->buf);
|
||||||
free(graft);
|
free(graft);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -174,7 +173,7 @@ static int read_graft_file(const char *graft_file)
|
||||||
return -1;
|
return -1;
|
||||||
while (!strbuf_getwholeline(&buf, fp, '\n')) {
|
while (!strbuf_getwholeline(&buf, fp, '\n')) {
|
||||||
/* The format is just "Commit Parent1 Parent2 ...\n" */
|
/* The format is just "Commit Parent1 Parent2 ...\n" */
|
||||||
struct commit_graft *graft = read_graft_line(buf.buf, buf.len);
|
struct commit_graft *graft = read_graft_line(&buf);
|
||||||
if (!graft)
|
if (!graft)
|
||||||
continue;
|
continue;
|
||||||
if (register_commit_graft(graft, 1))
|
if (register_commit_graft(graft, 1))
|
||||||
|
|
2
commit.h
2
commit.h
|
@ -247,7 +247,7 @@ struct commit_graft {
|
||||||
};
|
};
|
||||||
typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);
|
typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);
|
||||||
|
|
||||||
struct commit_graft *read_graft_line(char *buf, int len);
|
struct commit_graft *read_graft_line(struct strbuf *line);
|
||||||
int register_commit_graft(struct commit_graft *, int);
|
int register_commit_graft(struct commit_graft *, int);
|
||||||
struct commit_graft *lookup_commit_graft(const struct object_id *oid);
|
struct commit_graft *lookup_commit_graft(const struct object_id *oid);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue