git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Carlos Rica <jasampler@gmail.com>
Cc: git@vger.kernel.org, Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH] Function for updating refs.
Date: Wed, 05 Sep 2007 00:04:14 -0700	[thread overview]
Message-ID: <7vy7flk2z5.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: 46DE0890.5020709@gmail.com

Carlos Rica <jasampler@gmail.com> writes:

> 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.

> 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.

> 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.

  reply	other threads:[~2007-09-05  7:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-05  1:38 [PATCH] Function for updating refs Carlos Rica
2007-09-05  7:04 ` Junio C Hamano [this message]
2007-09-05 12:03   ` Carlos Rica

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7vy7flk2z5.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=jasampler@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).