};
static char line_termination = '\n';
-static int update_flags;
+static unsigned int update_flags;
+static unsigned int default_flags;
static unsigned create_reflog_flag;
static const char *msg;
msg, &err))
die("%s", err.buf);
- update_flags = 0;
+ update_flags = default_flags;
free(refname);
strbuf_release(&err);
msg, &err))
die("%s", err.buf);
- update_flags = 0;
+ update_flags = default_flags;
free(refname);
strbuf_release(&err);
update_flags, msg, &err))
die("%s", err.buf);
- update_flags = 0;
+ update_flags = default_flags;
free(refname);
strbuf_release(&err);
update_flags, &err))
die("%s", err.buf);
- update_flags = 0;
+ update_flags = default_flags;
free(refname);
strbuf_release(&err);
static const char *parse_cmd_option(struct strbuf *input, const char *next)
{
- if (!strncmp(next, "no-deref", 8) && next[8] == line_termination)
+ const char *rest;
+ if (skip_prefix(next, "no-deref", &rest) && *rest == line_termination)
update_flags |= REF_NO_DEREF;
else
die("option unknown: %s", next);
- return next + 8;
+ return rest;
}
static void update_refs_stdin(struct ref_transaction *transaction)
die("empty command in input");
else if (isspace(*next))
die("whitespace before command: %s", next);
- else if (starts_with(next, "update "))
- next = parse_cmd_update(transaction, &input, next + 7);
- else if (starts_with(next, "create "))
- next = parse_cmd_create(transaction, &input, next + 7);
- else if (starts_with(next, "delete "))
- next = parse_cmd_delete(transaction, &input, next + 7);
- else if (starts_with(next, "verify "))
- next = parse_cmd_verify(transaction, &input, next + 7);
- else if (starts_with(next, "option "))
- next = parse_cmd_option(&input, next + 7);
+ else if (skip_prefix(next, "update ", &next))
+ next = parse_cmd_update(transaction, &input, next);
+ else if (skip_prefix(next, "create ", &next))
+ next = parse_cmd_create(transaction, &input, next);
+ else if (skip_prefix(next, "delete ", &next))
+ next = parse_cmd_delete(transaction, &input, next);
+ else if (skip_prefix(next, "verify ", &next))
+ next = parse_cmd_verify(transaction, &input, next);
+ else if (skip_prefix(next, "option ", &next))
+ next = parse_cmd_option(&input, next);
else
die("unknown command: %s", next);
const char *refname, *oldval;
struct object_id oid, oldoid;
int delete = 0, no_deref = 0, read_stdin = 0, end_null = 0;
- unsigned int flags = 0;
int create_reflog = 0;
struct option options[] = {
OPT_STRING( 'm', NULL, &msg, N_("reason"), N_("reason of the update")),
create_reflog_flag = create_reflog ? REF_FORCE_CREATE_REFLOG : 0;
+ if (no_deref) {
+ default_flags = REF_NO_DEREF;
+ update_flags = default_flags;
+ }
+
if (read_stdin) {
struct strbuf err = STRBUF_INIT;
struct ref_transaction *transaction;
transaction = ref_transaction_begin(&err);
if (!transaction)
die("%s", err.buf);
- if (delete || no_deref || argc > 0)
+ if (delete || argc > 0)
usage_with_options(git_update_ref_usage, options);
if (end_null)
line_termination = '\0';
die("%s: not a valid old SHA1", oldval);
}
- if (no_deref)
- flags = REF_NO_DEREF;
if (delete)
/*
* For purposes of backwards compatibility, we treat
*/
return delete_ref(msg, refname,
(oldval && !is_null_oid(&oldoid)) ? &oldoid : NULL,
- flags);
+ default_flags);
else
return update_ref(msg, refname, &oid, oldval ? &oldoid : NULL,
- flags | create_reflog_flag,
+ default_flags | create_reflog_flag,
UPDATE_REFS_DIE_ON_ERR);
}