public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: "Jens Lindström" <jl@opera•com>
Cc: git@vger•kernel.org
Subject: Re: [PATCH v2 2/3] remote: repack packed-refs once when deleting multiple refs
Date: Fri, 23 May 2014 12:11:57 -0700	[thread overview]
Message-ID: <xmqq61kwjon6.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <537F2319.7040105@opera.com> ("Jens Lindström"'s message of "Fri, 23 May 2014 12:29:45 +0200")

Jens Lindström <jl@opera•com> writes:

> When 'git remote rm' or 'git remote prune' were used in a repository
> with many refs, and needed to delete many remote-tracking refs, a lot
> of time was spent deleting those refs since for each deleted ref,
> repack_without_refs() was called to rewrite packed-refs without just
> that deleted ref.
>
> To avoid this, call repack_without_refs() first to repack without all
> the refs that will be deleted, before calling delete_ref() to delete
> each one completely.  The call to repack_without_ref() in delete_ref()
> then becomes a no-op, since packed-refs already won't contain any of
> the deleted refs.
>
> Signed-off-by: Jens Lindström <jl@opera•com>
> ---
> Note: remove_branches() no longer checks that the remote-tracking
> branches it deletes point at the right object before deleting them
> by passing the expected SHA-1 to delete_ref().  This was a required
> change since all packed refs have been deleted already by the time
> we call delete_ref(), which causes delete_ref() to fail if given an
> expected SHA-1 to check.  'remote prune' already behaved this way.
>
>  builtin/remote.c | 20 ++++++++++++++++++--
>  refs.c           |  2 +-
>  refs.h           |  2 ++
>  3 files changed, 21 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/remote.c b/builtin/remote.c
> index 84802cd..d33abe6 100644
> --- a/builtin/remote.c
> +++ b/builtin/remote.c
> @@ -749,15 +749,23 @@ static int mv(int argc, const char **argv)
>  
>  static int remove_branches(struct string_list *branches)
>  {
> +	const char **branch_names;
>  	int i, result = 0;
> +
> +	branch_names = xmalloc(branches->nr * sizeof(*branch_names));
> +	for (i = 0; i < branches->nr; i++)
> +		branch_names[i] = branches->items[i].string;
> +	result |= repack_without_refs(branch_names, branches->nr);
> +	free(branch_names);

Hmph.  I wonder if you can refactor/enhance the interface to the
repack_without_refs() function before this step in the series, so
that the function lets the caller to know if each ref was actually
removed or it was not in packed-refs from the beginning, and also I
wonder if such a refactoring helps.  My gut feeling is that it would
not help that much this particular series, but it would probably be
a good thing to do in the longer run. So probably it is better to do
without such a change as a part of this series.

>  	for (i = 0; i < branches->nr; i++) {
>  		struct string_list_item *item = branches->items + i;
>  		const char *refname = item->string;
> -		unsigned char *sha1 = item->util;

Here, you can check if the refname still exists as a ref; if it no
longer exists, it would mean that the only copy of the ref was in
the packed-refs file and you have already deleted it, and you can
refrain from calling delete_ref() altogether, e.g.


	if (!ref_exists(refname))
		continue; /* already removed the sole copy from packed-ref */

and then still retain the safetly against racing somebody else who
created or updated the ref you wanted to remove here by passing the
object name to delete_ref().

> -		if (delete_ref(refname, sha1, 0))
> +		if (delete_ref(refname, NULL, 0))
>  			result |= error(_("Could not remove branch %s"), refname);
>  	}
> +
>  	return result;
>  }

  reply	other threads:[~2014-05-23 19:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-20 10:34 [PATCH 0/2] remote: optimize rm/prune ref deletion Jens Lindström
2014-05-20 10:39 ` [PATCH 1/2] remote: defer repacking packed-refs when deleting refs Jens Lindström
2014-05-20 19:30   ` Junio C Hamano
2014-05-20 20:29     ` Junio C Hamano
2014-05-23 10:03       ` Jens Lindström
2014-05-23 17:09         ` Junio C Hamano
2014-05-24  7:54           ` Jens Lindström
2014-05-27 16:55             ` Junio C Hamano
2014-05-20 10:41 ` [PATCH 2/2] remote prune: optimize "dangling symref" check/warning Jens Lindström
2014-05-23 10:26 ` [PATCH v2 0/3] remote: optimize rm/prune ref deletion Jens Lindström
2014-05-23 10:28   ` [PATCH v2 1/3] remote rm: delete remote configuration as the last Jens Lindström
2014-05-23 18:55     ` Junio C Hamano
2014-05-23 10:29   ` [PATCH v2 2/3] remote: repack packed-refs once when deleting multiple refs Jens Lindström
2014-05-23 19:11     ` Junio C Hamano [this message]
2014-05-23 19:25       ` Junio C Hamano
2014-05-23 10:30   ` [PATCH v2 3/3] remote prune: optimize "dangling symref" check/warning Jens Lindström

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

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

  git send-email \
    --in-reply-to=xmqq61kwjon6.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=jl@opera$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox