Re: [PATCH] Function for updating refs.
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 5, 2007, 07:04 UTC
- Message-ID
- <7vy7flk2z5.fsf@gitster.siamese.dyndns.org>
- In-Reply-To
- <46DE0890.5020709@gmail.com>
Carlos Rica <jasampler@gmail.com> writes:
Show 5 quoted lines
> A function intended to be called from builtins updating refs > by locking them before write, specially those that came from > scripts using "git update-ref". > > Signed-off-by: Carlos Rica <jasampler@gmail.com>
Thanks. Very nice.
I have two comments but I think they are very minor details I can and should fix in my inbox and apply, instead of asking you to update and resend.
Show 29 quoted lines
> diff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c
> index e2f8ede..a192fd7 100644
> --- a/builtin-fetch--tool.c
> +++ b/builtin-fetch--tool.c
> @@ -31,24 +31,19 @@ static void show_new(enum object_type type, unsigned char *sha1_new)
> find_unique_abbrev(sha1_new, DEFAULT_ABBREV));
> }
>
> -static int update_ref(const char *action,
> +static int update_ref_env(const char *action,
> const char *refname,
> unsigned char *sha1,
> unsigned char *oldval)
> {
> char msg[1024];
> char *rla = getenv("GIT_REFLOG_ACTION");
> - static struct ref_lock *lock;
>
> if (!rla)
> rla = "(reflog update)";
> - snprintf(msg, sizeof(msg), "%s: %s", rla, action);
> - lock = lock_any_ref_for_update(refname, oldval, 0);
> - if (!lock)
> - return 1;
> - if (write_ref_sha1(lock, sha1, msg) < 0)
> - return 1;
> - return 0;
> + if (snprintf(msg, sizeof(msg), "%s: %s", rla, action) >= sizeof(msg))
> + error("reflog message too long: %.*s...", 50, msg);The original I did was sloppy and did not detect this situation; thanks for fixing it. You do not refuse the primary operation, which is to update the ref, so this should be a warning instead of an error, I think.
Show 16 quoted lines
> diff --git a/send-pack.c b/send-pack.c
> index 9fc8a81..c59eea4 100644
> --- a/send-pack.c
> +++ b/send-pack.c
> @@ -313,14 +313,9 @@ static int send_pack(int in, int out, struct remote *remote, int nr_refspec, cha
> if (delete_ref(rs.dst, NULL)) {
> error("Failed to delete");
> }
> - } else {
> - lock = lock_any_ref_for_update(rs.dst, NULL, 0);
> - if (!lock)
> - error("Failed to lock");
> - else
> - write_ref_sha1(lock, ref->new_sha1,
> - "update by push");
> - }This removal makes "struct ref_lock *lock" (not shown in the context) unused. I will remove the declaration.