git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Jens Lindström" <jl@opera.com>
To: git@vger.kernel.org
Subject: [PATCH 2/2] remote prune: optimize "dangling symref" check/warning
Date: Tue, 20 May 2014 12:41:25 +0200	[thread overview]
Message-ID: <537B3155.1010309@opera.com> (raw)
In-Reply-To: <537B2FA4.7020001@opera.com>

When 'git remote prune' was used to delete many refs in a repository
with many refs, a lot of time was spent checking for (now) dangling
symbolic refs pointing to the deleted ref, since warn_dangling_symref()
was once per deleted ref to check all other refs in the repository.

Avoid this using the new warn_dangling_symrefs() function which
makes one pass over all refs and checks for all the deleted refs in
one go, after they have all been deleted.

Signed-off-by: Jens Lindström <jl@opera.com>
---
 builtin/remote.c |  6 +++++-
 refs.c           | 19 ++++++++++++++++++-
 refs.h           |  1 +
 3 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/builtin/remote.c b/builtin/remote.c
index ce60a30..5e4a8dd 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -1306,6 +1306,7 @@ static int prune_remote(const char *remote, int dry_run)
 {
 	int result = 0, i;
 	struct ref_states states;
+	struct string_list delete_refs_list = STRING_LIST_INIT_NODUP;
 	const char **delete_refs;
 	const char *dangling_msg = dry_run
 		? _(" %s will become dangling!")
@@ -1327,6 +1328,7 @@ static int prune_remote(const char *remote, int dry_run)
 		const char *refname = states.stale.items[i].util;
 
 		delete_refs[i] = refname;
+		string_list_insert(&delete_refs_list, refname);
 
 		if (!dry_run)
 			result |= delete_ref(refname, NULL, REF_DEFERREPACK);
@@ -1337,9 +1339,11 @@ static int prune_remote(const char *remote, int dry_run)
 		else
 			printf_ln(_(" * [pruned] %s"),
 			       abbrev_ref(refname, "refs/remotes/"));
-		warn_dangling_symref(stdout, dangling_msg, refname);
 	}
 
+	warn_dangling_symrefs(stdout, dangling_msg, &delete_refs_list);
+	string_list_clear(&delete_refs_list, 0);
+
 	if (states.stale.nr) {
 		if (!dry_run)
 			result |= repack_without_refs(delete_refs, states.stale.nr);
diff --git a/refs.c b/refs.c
index 3b62aca..fdd8b74 100644
--- a/refs.c
+++ b/refs.c
@@ -1611,6 +1611,7 @@ int peel_ref(const char *refname, unsigned char *sha1)
 struct warn_if_dangling_data {
 	FILE *fp;
 	const char *refname;
+	const struct string_list *refnames;
 	const char *msg_fmt;
 };
 
@@ -1625,8 +1626,12 @@ static int warn_if_dangling_symref(const char *refname, const unsigned char *sha
 		return 0;
 
 	resolves_to = resolve_ref_unsafe(refname, junk, 0, NULL);
-	if (!resolves_to || strcmp(resolves_to, d->refname))
+	if (!resolves_to
+	    || (d->refname
+		? strcmp(resolves_to, d->refname)
+		: !string_list_has_string(d->refnames, resolves_to))) {
 		return 0;
+	}
 
 	fprintf(d->fp, d->msg_fmt, refname);
 	fputc('\n', d->fp);
@@ -1639,6 +1644,18 @@ void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname)
 
 	data.fp = fp;
 	data.refname = refname;
+	data.refnames = NULL;
+	data.msg_fmt = msg_fmt;
+	for_each_rawref(warn_if_dangling_symref, &data);
+}
+
+void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct string_list *refnames)
+{
+	struct warn_if_dangling_data data;
+
+	data.fp = fp;
+	data.refname = NULL;
+	data.refnames = refnames;
 	data.msg_fmt = msg_fmt;
 	for_each_rawref(warn_if_dangling_symref, &data);
 }
diff --git a/refs.h b/refs.h
index 0db5584..cd4710d 100644
--- a/refs.h
+++ b/refs.h
@@ -89,7 +89,7 @@ static inline const char *has_glob_specials(const char *pattern)
 extern int for_each_rawref(each_ref_fn, void *);
 
 extern void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname);
+extern void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct string_list* refnames);
 
 /*
  * Lock the packed-refs file for writing.  Flags is passed to
--
1.9.1

  parent reply	other threads:[~2014-05-20 10:41 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 ` Jens Lindström [this message]
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
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=537B3155.1010309@opera.com \
    --to=jl@opera.com \
    --cc=git@vger.kernel.org \
    /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.
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 NNTP newsgroup(s).