Message ID | 20240330224623.579457-3-knayak@gitlab.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | update-ref: add support for update-symref option | expand |
On Sat, Mar 30, 2024 at 11:46:17PM +0100, Karthik Nayak wrote: > From: Karthik Nayak <karthik.188@gmail.com> > > The function `write_create_symref_table`, creates a > `reftable_ref_record` for a symref and adds it to the writer. Then it > also creates a log entry for the symref. It does all of this while also > obtaining and using a new update index. > > We extract out `write_symref_with_log` from this to provide the > functionality of creating a symref without making changes to the update > index. This will be used to add `update-symref` option to the > `git-update-ref` command. > > Rename the `create` field to `arg` while we're here, as `create` is a > bit misleading. > > Signed-off-by: Karthik Nayak <karthik.188@gmail.com> > --- > refs/reftable-backend.c | 41 +++++++++++++++++++++++++---------------- > 1 file changed, 25 insertions(+), 16 deletions(-) > > diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c > index e206d5a073..282a08e3cb 100644 > --- a/refs/reftable-backend.c > +++ b/refs/reftable-backend.c > @@ -1222,23 +1222,22 @@ struct write_create_symref_arg { > const char *logmsg; > }; > > -static int write_create_symref_table(struct reftable_writer *writer, void *cb_data) > +static int write_symref_with_log(struct reftable_writer *writer, > + struct write_create_symref_arg *arg, > + uint64_t update_index) > { > - struct write_create_symref_arg *create = cb_data; > - uint64_t ts = reftable_stack_next_update_index(create->stack); > struct reftable_ref_record ref = { > - .refname = (char *)create->refname, > + .refname = (char *)arg->refname, > .value_type = REFTABLE_REF_SYMREF, > - .value.symref = (char *)create->target, > - .update_index = ts, > + .value.symref = (char *)arg->target, > + .update_index = update_index, > }; > + Nit: let's remove this superfluous newline. Patrick > struct reftable_log_record log = {0}; > struct object_id new_oid; > struct object_id old_oid; > int ret; > > - reftable_writer_set_limits(writer, ts, ts); > - > ret = reftable_writer_add_ref(writer, &ref); > if (ret) > return ret; > @@ -1251,25 +1250,35 @@ static int write_create_symref_table(struct reftable_writer *writer, void *cb_da > * not resolve for new repositories this ordering will ensure that this > * never happens. > */ > - if (!create->logmsg || > - !refs_resolve_ref_unsafe(&create->refs->base, create->target, > + if (!arg->logmsg || > + !refs_resolve_ref_unsafe(&arg->refs->base, arg->target, > RESOLVE_REF_READING, &new_oid, NULL) || > - !should_write_log(&create->refs->base, create->refname)) > + !should_write_log(&arg->refs->base, arg->refname)) > return 0; > > fill_reftable_log_record(&log); > - log.refname = xstrdup(create->refname); > - log.update_index = ts; > - log.value.update.message = xstrndup(create->logmsg, > - create->refs->write_options.block_size / 2); > + log.refname = xstrdup(arg->refname); > + log.update_index = update_index; > + log.value.update.message = xstrndup(arg->logmsg, > + arg->refs->write_options.block_size / 2); > memcpy(log.value.update.new_hash, new_oid.hash, GIT_MAX_RAWSZ); > - if (refs_resolve_ref_unsafe(&create->refs->base, create->refname, > + if (refs_resolve_ref_unsafe(&arg->refs->base, arg->refname, > RESOLVE_REF_READING, &old_oid, NULL)) > memcpy(log.value.update.old_hash, old_oid.hash, GIT_MAX_RAWSZ); > > ret = reftable_writer_add_log(writer, &log); > reftable_log_record_release(&log); > return ret; > + > +} > + > +static int write_create_symref_table(struct reftable_writer *writer, void *cb_data) > +{ > + struct write_create_symref_arg *arg = cb_data; > + uint64_t ts = reftable_stack_next_update_index(arg->stack); > + reftable_writer_set_limits(writer, ts, ts); > + > + return write_symref_with_log(writer, arg, ts); > } > > static int reftable_be_create_symref(struct ref_store *ref_store, > -- > 2.43.GIT >
diff --git a/refs/reftable-backend.c b/refs/reftable-backend.c index e206d5a073..282a08e3cb 100644 --- a/refs/reftable-backend.c +++ b/refs/reftable-backend.c @@ -1222,23 +1222,22 @@ struct write_create_symref_arg { const char *logmsg; }; -static int write_create_symref_table(struct reftable_writer *writer, void *cb_data) +static int write_symref_with_log(struct reftable_writer *writer, + struct write_create_symref_arg *arg, + uint64_t update_index) { - struct write_create_symref_arg *create = cb_data; - uint64_t ts = reftable_stack_next_update_index(create->stack); struct reftable_ref_record ref = { - .refname = (char *)create->refname, + .refname = (char *)arg->refname, .value_type = REFTABLE_REF_SYMREF, - .value.symref = (char *)create->target, - .update_index = ts, + .value.symref = (char *)arg->target, + .update_index = update_index, }; + struct reftable_log_record log = {0}; struct object_id new_oid; struct object_id old_oid; int ret; - reftable_writer_set_limits(writer, ts, ts); - ret = reftable_writer_add_ref(writer, &ref); if (ret) return ret; @@ -1251,25 +1250,35 @@ static int write_create_symref_table(struct reftable_writer *writer, void *cb_da * not resolve for new repositories this ordering will ensure that this * never happens. */ - if (!create->logmsg || - !refs_resolve_ref_unsafe(&create->refs->base, create->target, + if (!arg->logmsg || + !refs_resolve_ref_unsafe(&arg->refs->base, arg->target, RESOLVE_REF_READING, &new_oid, NULL) || - !should_write_log(&create->refs->base, create->refname)) + !should_write_log(&arg->refs->base, arg->refname)) return 0; fill_reftable_log_record(&log); - log.refname = xstrdup(create->refname); - log.update_index = ts; - log.value.update.message = xstrndup(create->logmsg, - create->refs->write_options.block_size / 2); + log.refname = xstrdup(arg->refname); + log.update_index = update_index; + log.value.update.message = xstrndup(arg->logmsg, + arg->refs->write_options.block_size / 2); memcpy(log.value.update.new_hash, new_oid.hash, GIT_MAX_RAWSZ); - if (refs_resolve_ref_unsafe(&create->refs->base, create->refname, + if (refs_resolve_ref_unsafe(&arg->refs->base, arg->refname, RESOLVE_REF_READING, &old_oid, NULL)) memcpy(log.value.update.old_hash, old_oid.hash, GIT_MAX_RAWSZ); ret = reftable_writer_add_log(writer, &log); reftable_log_record_release(&log); return ret; + +} + +static int write_create_symref_table(struct reftable_writer *writer, void *cb_data) +{ + struct write_create_symref_arg *arg = cb_data; + uint64_t ts = reftable_stack_next_update_index(arg->stack); + reftable_writer_set_limits(writer, ts, ts); + + return write_symref_with_log(writer, arg, ts); } static int reftable_be_create_symref(struct ref_store *ref_store,