Skip to content

Commit 804dba5

Browse files
pks-tgitster
authored andcommitted
update-ref: pass end pointer instead of strbuf
We currently pass both an `strbuf` containing the current command line as well as the `next` pointer pointing to the first argument to commands. This is both confusing and makes code more intertwined. Convert this to use a simple pointer as well as a pointer pointing to the end of the input as a preparatory step to line-wise reading of stdin. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5ae6c5a commit 804dba5

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

builtin/update-ref.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ static char *parse_refname(const char **next)
9595
* provided but cannot be converted to a SHA-1, die. flags can
9696
* include PARSE_SHA1_OLD and/or PARSE_SHA1_ALLOW_EMPTY.
9797
*/
98-
static int parse_next_oid(struct strbuf *input, const char **next,
98+
static int parse_next_oid(const char **next, const char *end,
9999
struct object_id *oid,
100100
const char *command, const char *refname,
101101
int flags)
102102
{
103103
struct strbuf arg = STRBUF_INIT;
104104
int ret = 0;
105105

106-
if (*next == input->buf + input->len)
106+
if (*next == end)
107107
goto eof;
108108

109109
if (line_termination) {
@@ -128,7 +128,7 @@ static int parse_next_oid(struct strbuf *input, const char **next,
128128
die("%s %s: expected NUL but got: %s",
129129
command, refname, *next);
130130
(*next)++;
131-
if (*next == input->buf + input->len)
131+
if (*next == end)
132132
goto eof;
133133
strbuf_addstr(&arg, *next);
134134
*next += arg.len;
@@ -179,7 +179,7 @@ static int parse_next_oid(struct strbuf *input, const char **next,
179179
*/
180180

181181
static const char *parse_cmd_update(struct ref_transaction *transaction,
182-
struct strbuf *input, const char *next)
182+
const char *next, const char *end)
183183
{
184184
struct strbuf err = STRBUF_INIT;
185185
char *refname;
@@ -190,11 +190,11 @@ static const char *parse_cmd_update(struct ref_transaction *transaction,
190190
if (!refname)
191191
die("update: missing <ref>");
192192

193-
if (parse_next_oid(input, &next, &new_oid, "update", refname,
193+
if (parse_next_oid(&next, end, &new_oid, "update", refname,
194194
PARSE_SHA1_ALLOW_EMPTY))
195195
die("update %s: missing <newvalue>", refname);
196196

197-
have_old = !parse_next_oid(input, &next, &old_oid, "update", refname,
197+
have_old = !parse_next_oid(&next, end, &old_oid, "update", refname,
198198
PARSE_SHA1_OLD);
199199

200200
if (*next != line_termination)
@@ -214,7 +214,7 @@ static const char *parse_cmd_update(struct ref_transaction *transaction,
214214
}
215215

216216
static const char *parse_cmd_create(struct ref_transaction *transaction,
217-
struct strbuf *input, const char *next)
217+
const char *next, const char *end)
218218
{
219219
struct strbuf err = STRBUF_INIT;
220220
char *refname;
@@ -224,7 +224,7 @@ static const char *parse_cmd_create(struct ref_transaction *transaction,
224224
if (!refname)
225225
die("create: missing <ref>");
226226

227-
if (parse_next_oid(input, &next, &new_oid, "create", refname, 0))
227+
if (parse_next_oid(&next, end, &new_oid, "create", refname, 0))
228228
die("create %s: missing <newvalue>", refname);
229229

230230
if (is_null_oid(&new_oid))
@@ -246,7 +246,7 @@ static const char *parse_cmd_create(struct ref_transaction *transaction,
246246
}
247247

248248
static const char *parse_cmd_delete(struct ref_transaction *transaction,
249-
struct strbuf *input, const char *next)
249+
const char *next, const char *end)
250250
{
251251
struct strbuf err = STRBUF_INIT;
252252
char *refname;
@@ -257,7 +257,7 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction,
257257
if (!refname)
258258
die("delete: missing <ref>");
259259

260-
if (parse_next_oid(input, &next, &old_oid, "delete", refname,
260+
if (parse_next_oid(&next, end, &old_oid, "delete", refname,
261261
PARSE_SHA1_OLD)) {
262262
have_old = 0;
263263
} else {
@@ -282,7 +282,7 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction,
282282
}
283283

284284
static const char *parse_cmd_verify(struct ref_transaction *transaction,
285-
struct strbuf *input, const char *next)
285+
const char *next, const char *end)
286286
{
287287
struct strbuf err = STRBUF_INIT;
288288
char *refname;
@@ -292,7 +292,7 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction,
292292
if (!refname)
293293
die("verify: missing <ref>");
294294

295-
if (parse_next_oid(input, &next, &old_oid, "verify", refname,
295+
if (parse_next_oid(&next, end, &old_oid, "verify", refname,
296296
PARSE_SHA1_OLD))
297297
oidclr(&old_oid);
298298

@@ -311,7 +311,7 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction,
311311
}
312312

313313
static const char *parse_cmd_option(struct ref_transaction *transaction,
314-
struct strbuf *input, const char *next)
314+
const char *next, const char *end)
315315
{
316316
const char *rest;
317317
if (skip_prefix(next, "no-deref", &rest) && *rest == line_termination)
@@ -323,7 +323,7 @@ static const char *parse_cmd_option(struct ref_transaction *transaction,
323323

324324
static const struct parse_cmd {
325325
const char *prefix;
326-
const char *(*fn)(struct ref_transaction *, struct strbuf *, const char *);
326+
const char *(*fn)(struct ref_transaction *, const char *, const char *);
327327
} command[] = {
328328
{ "update", parse_cmd_update },
329329
{ "create", parse_cmd_create },
@@ -363,7 +363,7 @@ static void update_refs_stdin(struct ref_transaction *transaction)
363363
if (!cmd)
364364
die("unknown command: %s", next);
365365

366-
next = cmd->fn(transaction, &input, next);
366+
next = cmd->fn(transaction, next, input.buf + input.len);
367367
next++;
368368
}
369369

0 commit comments

Comments
 (0)