From: Jay Soffian <jaysoffian@gmail.com>
To: git@vger.kernel.org
Cc: Jay Soffian <jaysoffian@gmail.com>, Jeff King <peff@peff.net>,
Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 07/21] remote: simplify guess_remote_head()
Date: Wed, 25 Feb 2009 03:32:14 -0500 [thread overview]
Message-ID: <7a4c3693fd5f1e53a63182a2da9ed9e46fb99441.1235546708.git.jaysoffian@gmail.com> (raw)
In-Reply-To: <cover.1235546707.git.jaysoffian@gmail.com>
This function had complications which made it hard to extend.
- It used to do two things: find the HEAD ref, and then find a
matching ref, optionally returning the former via assignment to a
passed-in pointer. Since finding HEAD is a one-liner, just have a
caller do it themselves and pass it as an argument.
- It used to manually search through the ref list for
refs/heads/master; this can be a one-line call to
find_ref_by_name.
Originally contributed by Jeff King along with the next commit as a
single patch.
Signed-off-by: Jay Soffian <jaysoffian@gmail.com>
---
I split Jeff's patch into two as it makes the diff a littler easier on
the eyes and the history is clearer this way.
builtin-clone.c | 4 ++--
remote.c | 31 ++++++++-----------------------
remote.h | 13 ++++++-------
3 files changed, 16 insertions(+), 32 deletions(-)
diff --git a/builtin-clone.c b/builtin-clone.c
index d179d1c..f9ce4fb 100644
--- a/builtin-clone.c
+++ b/builtin-clone.c
@@ -509,8 +509,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
mapped_refs = write_remote_refs(refs, &refspec, reflog_msg.buf);
- head_points_at = guess_remote_head(refs, mapped_refs,
- &remote_head);
+ remote_head = find_ref_by_name(refs, "HEAD");
+ head_points_at = guess_remote_head(remote_head, mapped_refs);
}
else {
warning("You appear to have cloned an empty repository.");
diff --git a/remote.c b/remote.c
index 49a183e..aed760e 100644
--- a/remote.c
+++ b/remote.c
@@ -1452,37 +1452,22 @@ struct ref *get_local_heads(void)
return local_refs;
}
-const struct ref *guess_remote_head(const struct ref *refs,
- const struct ref *mapped_refs,
- const struct ref **remote_head_p)
+const struct ref *guess_remote_head(const struct ref *head,
+ const struct ref *refs)
{
- const struct ref *remote_head = NULL;
- const struct ref *remote_master = NULL;
const struct ref *r;
- for (r = refs; r; r = r->next)
- if (!strcmp(r->name, "HEAD"))
- remote_head = r;
- for (r = mapped_refs; r; r = r->next)
- if (!strcmp(r->name, "refs/heads/master"))
- remote_master = r;
-
- if (remote_head_p)
- *remote_head_p = remote_head;
-
- /* If there's no HEAD value at all, never mind. */
- if (!remote_head)
+ if (!head)
return NULL;
/* If refs/heads/master could be right, it is. */
- if (remote_master && !hashcmp(remote_master->old_sha1,
- remote_head->old_sha1))
- return remote_master;
+ r = find_ref_by_name(refs, "refs/heads/master");
+ if (r && !hashcmp(r->old_sha1, head->old_sha1))
+ return r;
/* Look for another ref that points there */
- for (r = mapped_refs; r; r = r->next)
- if (r != remote_head &&
- !hashcmp(r->old_sha1, remote_head->old_sha1))
+ for (r = refs; r; r = r->next)
+ if (r != head && !hashcmp(r->old_sha1, head->old_sha1))
return r;
/* Nothing is the same */
diff --git a/remote.h b/remote.h
index 9605da9..db49ce0 100644
--- a/remote.h
+++ b/remote.h
@@ -139,13 +139,12 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs);
int format_tracking_info(struct branch *branch, struct strbuf *sb);
struct ref *get_local_heads(void);
+
/*
- * Look in refs for HEAD. Then look for a matching SHA1 in mapped_refs,
- * first checking if refs/heads/master matches. Return NULL if nothing matches
- * or if there is no HEAD in refs. remote_head_p is assigned HEAD if not NULL.
+ * Look for a ref in refs whose SHA1 matches head, first checking if
+ * refs/heads/master matches. Return NULL if nothing matches or if head
+ * is NULL.
*/
-const struct ref *guess_remote_head(const struct ref *refs,
- const struct ref *mapped_refs,
- const struct ref **remote_head_p);
-
+const struct ref *guess_remote_head(const struct ref *head,
+ const struct ref *refs);
#endif
--
1.6.2.rc1.291.g83eb
next prev parent reply other threads:[~2009-02-25 8:35 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-25 8:32 [PATCH 00/21] git remote: set-head and new show output Jay Soffian
2009-02-25 8:32 ` [PATCH 01/21] test scripts: refactor start_httpd helper Jay Soffian
2009-02-25 8:32 ` [PATCH 02/21] add basic http clone/fetch tests Jay Soffian
2009-02-25 8:32 ` [PATCH 03/21] refactor find_ref_by_name() to accept const list Jay Soffian
2009-02-25 8:32 ` [PATCH 04/21] move duplicated get_local_heads() to remote.c Jay Soffian
2009-02-25 8:32 ` [PATCH 05/21] move duplicated ref_newer() " Jay Soffian
2009-02-25 8:32 ` [PATCH 06/21] move locate_head() " Jay Soffian
2009-02-25 8:32 ` Jay Soffian [this message]
2009-02-25 8:32 ` [PATCH 08/21] remote: let guess_remote_head() optionally return all matches Jay Soffian
2009-02-26 14:37 ` Jeff King
2009-02-26 14:40 ` Jeff King
2009-02-26 18:47 ` Jay Soffian
2009-02-27 11:43 ` Jeff King
2009-02-27 19:10 ` [PATCH 0/3] git remote: set-head and new show output (UPDATED) Jay Soffian
2009-02-28 6:33 ` Jeff King
2009-02-25 8:32 ` [PATCH 09/21] remote: make match_refs() copy src ref before assigning to peer_ref Jay Soffian
2009-02-25 8:32 ` [PATCH 10/21] remote: make match_refs() not short-circuit Jay Soffian
2009-02-25 8:32 ` [PATCH 11/21] string-list: new for_each_string_list() function Jay Soffian
2009-02-25 8:32 ` [PATCH 12/21] builtin-remote: refactor duplicated cleanup code Jay Soffian
2009-02-25 8:32 ` [PATCH 13/21] builtin-remote: remove unused code in get_ref_states Jay Soffian
2009-02-25 8:32 ` [PATCH 14/21] builtin-remote: rename variables and eliminate redundant function call Jay Soffian
2009-02-25 8:32 ` [PATCH 15/21] builtin-remote: make get_remote_ref_states() always populate states.tracked Jay Soffian
2009-02-25 8:32 ` [PATCH 16/21] builtin-remote: fix two inconsistencies in the output of "show <remote>" Jay Soffian
2009-02-25 8:32 ` [PATCH 17/21] builtin-remote: teach show to display remote HEAD Jay Soffian
2009-02-25 8:32 ` [PATCH 18/21] builtin-remote: add set-head subcommand Jay Soffian
2009-02-25 8:32 ` [PATCH 19/21] remote: make guess_remote_head() use exact HEAD lookup if it is available Jay Soffian
2009-02-25 8:32 ` [PATCH 20/21] builtin-remote: new show output style Jay Soffian
2009-02-25 8:32 ` [PATCH 21/21] builtin-remote: new show output style for push refspecs Jay Soffian
2009-02-26 14:53 ` [PATCH 00/21] git remote: set-head and new show output Jeff King
2009-02-26 17:04 ` Junio C Hamano
2009-02-27 19:10 ` [PATCH 07a/21] remote: make copy_ref() perform a deep copy Jay Soffian
2009-02-27 19:10 ` [PATCH 08/21] remote: let guess_remote_head() optionally return all matches Jay Soffian
2009-02-27 19:10 ` [PATCH 19/21] remote: make guess_remote_head() use exact HEAD lookup if it is available Jay Soffian
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=7a4c3693fd5f1e53a63182a2da9ed9e46fb99441.1235546708.git.jaysoffian@gmail.com \
--to=jaysoffian@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.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;
as well as URLs for NNTP newsgroup(s).