Git development
 help / color / mirror / Atom feed
From: Christian Couder <chriscool@tuxfamily.org>
To: Junio Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: [PATCH 1/2] Move code resolving packed refs into its own function.
Date: Sat, 30 Sep 2006 22:01:58 +0200	[thread overview]
Message-ID: <20060930220158.d331bb7c.chriscool@tuxfamily.org> (raw)

This patch move Linus' packed refs resolving code from
"resolve_ref" into a new "resolve_packed_ref" extern
function so that it can be reused when needed.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 cache.h |    2 ++
 refs.c  |   34 ++++++++++++++++++++--------------
 2 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/cache.h b/cache.h
index 4e01a74..f37bc18 100644
--- a/cache.h
+++ b/cache.h
@@ -296,6 +296,8 @@ extern int get_sha1_hex(const char *hex,
 extern char *sha1_to_hex(const unsigned char *sha1);	/* static buffer result! */
 extern int read_ref(const char *filename, unsigned char *sha1);
 extern const char *resolve_ref(const char *path, unsigned char *sha1, int, int *);
+extern const char *resolve_packed_ref(const char *ref, unsigned char *sha1, int, int *);
+
 extern int create_symref(const char *ref, const char *refs_heads_master);
 extern int validate_symref(const char *ref);
 
diff --git a/refs.c b/refs.c
index 3d4cdd1..5e3988b 100644
--- a/refs.c
+++ b/refs.c
@@ -148,6 +148,25 @@ static struct ref_list *get_loose_refs(v
 	return refs;
 }
 
+const char *resolve_packed_ref(const char *ref, unsigned char *sha1,
+			       int reading, int *flag)
+{
+	struct ref_list *list = get_packed_refs();
+	while (list) {
+		if (!strcmp(ref, list->name)) {
+			hashcpy(sha1, list->sha1);
+			if (flag)
+				*flag |= REF_ISPACKED;
+			return ref;
+		}
+		list = list->next;
+	}
+	if (reading || errno != ENOENT)
+		return NULL;
+	hashclr(sha1);
+	return ref;
+}
+
 /* We allow "recursive" symbolic refs. Only within reason, though */
 #define MAXDEPTH 5
 
@@ -177,20 +196,7 @@ const char *resolve_ref(const char *ref,
 		 * reading.
 		 */
 		if (lstat(path, &st) < 0) {
-			struct ref_list *list = get_packed_refs();
-			while (list) {
-				if (!strcmp(ref, list->name)) {
-					hashcpy(sha1, list->sha1);
-					if (flag)
-						*flag |= REF_ISPACKED;
-					return ref;
-				}
-				list = list->next;
-			}
-			if (reading || errno != ENOENT)
-				return NULL;
-			hashclr(sha1);
-			return ref;
+			return resolve_packed_ref(ref, sha1, reading, flag);
 		}
 
 		/* Follow "normalized" - ie "refs/.." symlinks by hand */
-- 
1.4.2.1.g7cf04

             reply	other threads:[~2006-09-30 19:55 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-30 20:01 Christian Couder [this message]
2006-09-30 20:33 ` [PATCH 1/2] Move code resolving packed refs into its own function Junio C Hamano
2006-09-30 22:26   ` [PATCH 0/6] ref deletion and D/F conflict avoidance with packed-refs Junio C Hamano
2006-09-30 22:29     ` [PATCH 1/6] ref locking: allow 'foo' when 'foo/bar' used to exist but not anymore Junio C Hamano
2006-09-30 22:30     ` [PATCH 2/6] refs: minor restructuring of cached refs data Junio C Hamano
2006-09-30 22:30     ` [PATCH 3/6] lock_ref_sha1(): do not sometimes error() and sometimes die() Junio C Hamano
2006-09-30 22:30     ` [PATCH 4/6] lock_ref_sha1(): check D/F conflict with packed ref when creating Junio C Hamano
2006-09-30 22:30     ` [PATCH 5/6] delete_ref(): delete packed ref Junio C Hamano
2006-09-30 22:30     ` [PATCH 6/6] git-branch: remove D/F check done by hand Junio C Hamano
2006-09-30 22:36     ` [PATCH 0/6] ref deletion and D/F conflict avoidance with packed-refs Jeff King
2006-10-01  4:06   ` [PATCH 1/2] Move code resolving packed refs into its own function Christian Couder
2006-10-01  9:58     ` Junio C Hamano
2006-10-03 12:10       ` Jakub Narebski
2006-10-03 17:39         ` Junio C Hamano

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=20060930220158.d331bb7c.chriscool@tuxfamily.org \
    --to=chriscool@tuxfamily.org \
    --cc=git@vger.kernel.org \
    --cc=junkio@cox.net \
    /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