Skip to content

Commit 9a93403

Browse files
dreamergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 50c5cd5 commit 9a93403

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

builtin/blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ static int read_ancestry(const char *graft_file)
488488
return -1;
489489
while (!strbuf_getwholeline(&buf, fp, '\n')) {
490490
/* The format is just "Commit Parent1 Parent2 ...\n" */
491-
struct commit_graft *graft = read_graft_line(buf.buf, buf.len);
491+
struct commit_graft *graft = read_graft_line(&buf);
492492
if (graft)
493493
register_commit_graft(graft, 0);
494494
}

commit.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,34 +134,33 @@ int register_commit_graft(struct commit_graft *graft, int ignore_dups)
134134
return 0;
135135
}
136136

137-
struct commit_graft *read_graft_line(char *buf, int len)
137+
struct commit_graft *read_graft_line(struct strbuf *line)
138138
{
139139
/* The format is just "Commit Parent1 Parent2 ...\n" */
140140
int i;
141141
struct commit_graft *graft = NULL;
142142
const int entry_size = GIT_SHA1_HEXSZ + 1;
143143

144-
while (len && isspace(buf[len-1]))
145-
buf[--len] = '\0';
146-
if (buf[0] == '#' || buf[0] == '\0')
144+
strbuf_rtrim(line);
145+
if (!line->len || line->buf[0] == '#')
147146
return NULL;
148-
if ((len + 1) % entry_size)
147+
if ((line->len + 1) % entry_size)
149148
goto bad_graft_data;
150-
i = (len + 1) / entry_size - 1;
149+
i = (line->len + 1) / entry_size - 1;
151150
graft = xmalloc(st_add(sizeof(*graft), st_mult(GIT_SHA1_RAWSZ, i)));
152151
graft->nr_parent = i;
153-
if (get_oid_hex(buf, &graft->oid))
152+
if (get_oid_hex(line->buf, &graft->oid))
154153
goto bad_graft_data;
155-
for (i = GIT_SHA1_HEXSZ; i < len; i += entry_size) {
156-
if (buf[i] != ' ')
154+
for (i = GIT_SHA1_HEXSZ; i < line->len; i += entry_size) {
155+
if (line->buf[i] != ' ')
157156
goto bad_graft_data;
158-
if (get_sha1_hex(buf + i + 1, graft->parent[i/entry_size].hash))
157+
if (get_sha1_hex(line->buf + i + 1, graft->parent[i/entry_size].hash))
159158
goto bad_graft_data;
160159
}
161160
return graft;
162161

163162
bad_graft_data:
164-
error("bad graft data: %s", buf);
163+
error("bad graft data: %s", line->buf);
165164
free(graft);
166165
return NULL;
167166
}
@@ -174,7 +173,7 @@ static int read_graft_file(const char *graft_file)
174173
return -1;
175174
while (!strbuf_getwholeline(&buf, fp, '\n')) {
176175
/* The format is just "Commit Parent1 Parent2 ...\n" */
177-
struct commit_graft *graft = read_graft_line(buf.buf, buf.len);
176+
struct commit_graft *graft = read_graft_line(&buf);
178177
if (!graft)
179178
continue;
180179
if (register_commit_graft(graft, 1))

commit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ struct commit_graft {
247247
};
248248
typedef int (*each_commit_graft_fn)(const struct commit_graft *, void *);
249249

250-
struct commit_graft *read_graft_line(char *buf, int len);
250+
struct commit_graft *read_graft_line(struct strbuf *line);
251251
int register_commit_graft(struct commit_graft *, int);
252252
struct commit_graft *lookup_commit_graft(const struct object_id *oid);
253253

0 commit comments

Comments
 (0)