From: Junio C Hamano <gitster@pobox.com>
To: Michael Haggerty <mhagger@alum.mit.edu>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] refname_match(): always use the rules in ref_rev_parse_rules
Date: Tue, 14 Jan 2014 14:16:02 -0800 [thread overview]
Message-ID: <xmqq38kq43bx.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1389669367-27343-1-git-send-email-mhagger@alum.mit.edu> (Michael Haggerty's message of "Tue, 14 Jan 2014 04:16:07 +0100")
Michael Haggerty <mhagger@alum.mit.edu> writes:
> We used to use two separate rules for the normal ref resolution
> dwimming and dwimming done to decide which remote ref to grab. The
> third parameter to refname_match() selected which rules to use.
>
> When these two rules were harmonized in
>
> 2011-11-04 dd621df9cd refs DWIMmery: use the same rule for both "git fetch" and others
>
> , ref_fetch_rules was #defined to avoid potential breakages for
> in-flight topics.
>
> It is now safe to remove the backwards-compatibility code, so remove
> refname_match()'s third parameter, make ref_rev_parse_rules private to
> refs.c, and remove ref_fetch_rules entirely.
>
> Suggested-by: Junio C Hamano <gitster@pobox.com>
> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
> ---
> See
>
> http://article.gmane.org/gmane.comp.version-control.git/240305
>
> in which Junio made the suggestion and wrote most of the commit
> message :-)
;-) ...and on top of it this may be an obvious endgame follow-up.
was done mindlessly and mechanically, so there may be some slip-ups,
though.
refs.c | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/refs.c b/refs.c
index 5a10c25..b1c9cf5 100644
--- a/refs.c
+++ b/refs.c
@@ -1886,16 +1886,16 @@ static const char *ref_rev_parse_rules[] = {
"refs/tags/%.*s",
"refs/heads/%.*s",
"refs/remotes/%.*s",
- "refs/remotes/%.*s/HEAD",
- NULL
+ "refs/remotes/%.*s/HEAD"
};
int refname_match(const char *abbrev_name, const char *full_name)
{
- const char **p;
+ int i;
const int abbrev_name_len = strlen(abbrev_name);
- for (p = ref_rev_parse_rules; *p; p++) {
+ for (i = 0; i < ARRAY_SIZE(ref_rev_parse_rules); i++) {
+ const char **p = &ref_rev_parse_rules[i];
if (!strcmp(full_name, mkpath(*p, abbrev_name_len, abbrev_name))) {
return 1;
}
@@ -1963,11 +1963,13 @@ static char *substitute_branch_name(const char **string, int *len)
int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
{
char *last_branch = substitute_branch_name(&str, &len);
- const char **p, *r;
+ int i;
+ const char *r;
int refs_found = 0;
*ref = NULL;
- for (p = ref_rev_parse_rules; *p; p++) {
+ for (i = 0; i < ARRAY_SIZE(ref_rev_parse_rules); i++) {
+ const char **p = &ref_rev_parse_rules[i];
char fullref[PATH_MAX];
unsigned char sha1_from_ref[20];
unsigned char *this_result;
@@ -1994,11 +1996,11 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
int dwim_log(const char *str, int len, unsigned char *sha1, char **log)
{
char *last_branch = substitute_branch_name(&str, &len);
- const char **p;
- int logs_found = 0;
+ int logs_found = 0, i;
*log = NULL;
- for (p = ref_rev_parse_rules; *p; p++) {
+ for (i = 0; i < ARRAY_SIZE(ref_rev_parse_rules); i++) {
+ const char **p = &ref_rev_parse_rules[i];
struct stat st;
unsigned char hash[20];
char path[PATH_MAX];
@@ -3368,8 +3370,8 @@ char *shorten_unambiguous_ref(const char *refname, int strict)
if (!nr_rules) {
size_t total_len = 0;
- /* the rule list is NULL terminated, count them first */
- for (nr_rules = 0; ref_rev_parse_rules[nr_rules]; nr_rules++)
+ /* Count the bytesize needed to hold rule strings */
+ for (nr_rules = 0; ARRAY_SIZE(ref_rev_parse_rules); nr_rules++)
/* no +1 because strlen("%s") < strlen("%.*s") */
total_len += strlen(ref_rev_parse_rules[nr_rules]);
next prev parent reply other threads:[~2014-01-14 22:16 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-01-08 14:43 [PATCH 0/3] Generate scanf_fmts more simply Michael Haggerty
2014-01-08 14:43 ` [PATCH 1/3] shorten_unambiguous_ref(): introduce a new local variable Michael Haggerty
2014-01-08 14:43 ` [PATCH 2/3] gen_scanf_fmt(): delete function and use snprintf() instead Michael Haggerty
2014-01-09 22:56 ` Junio C Hamano
2014-01-08 14:43 ` [PATCH 3/3] shorten_unambiguous_ref(): tighten up pointer arithmetic Michael Haggerty
2014-01-09 23:01 ` Junio C Hamano
2014-01-10 14:16 ` Michael Haggerty
2014-01-10 18:03 ` Junio C Hamano
2014-01-14 3:16 ` [PATCH] refname_match(): always use the rules in ref_rev_parse_rules Michael Haggerty
2014-01-14 22:16 ` Junio C Hamano [this message]
2014-01-15 16:54 ` Michael Haggerty
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=xmqq38kq43bx.fsf@gitster.dls.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=mhagger@alum.mit.edu \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.