From def249911ad0e36a40a0603fc42b7e9cf0b21546 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 29 Jan 2013 12:58:50 -0800 Subject: parse_fetch_refspec(): clarify the codeflow a bit Most parts of the cascaded if/else if/... checked an allowable condition but some checked forbidden conditions. This makes adding new allowable conditions unnecessarily inconvenient. Signed-off-by: Junio C Hamano --- remote.c | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) (limited to 'remote.c') diff --git a/remote.c b/remote.c index 4b1153f02c..1b7828d19f 100644 --- a/remote.c +++ b/remote.c @@ -538,7 +538,7 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp /* * Before going on, special case ":" (or "+:") as a refspec - * for matching refs. + * for pushing matching refs. */ if (!fetch && rhs == lhs && rhs[1] == '\0') { rs[i].matching = 1; @@ -565,26 +565,21 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp flags = REFNAME_ALLOW_ONELEVEL | (is_glob ? REFNAME_REFSPEC_PATTERN : 0); if (fetch) { - /* - * LHS - * - empty is allowed; it means HEAD. - * - otherwise it must be a valid looking ref. - */ + /* LHS */ if (!*rs[i].src) - ; /* empty is ok */ - else if (check_refname_format(rs[i].src, flags)) + ; /* empty is ok; it means "HEAD" */ + else if (!check_refname_format(rs[i].src, flags)) + ; /* valid looking ref is ok */ + else goto invalid; - /* - * RHS - * - missing is ok, and is same as empty. - * - empty is ok; it means not to store. - * - otherwise it must be a valid looking ref. - */ + /* RHS */ if (!rs[i].dst) - ; /* ok */ + ; /* missing is ok; it is the same as empty */ else if (!*rs[i].dst) - ; /* ok */ - else if (check_refname_format(rs[i].dst, flags)) + ; /* empty is ok; it means "do not store" */ + else if (!check_refname_format(rs[i].dst, flags)) + ; /* valid looking ref is ok */ + else goto invalid; } else { /* -- cgit v1.2.1 From 6e7b66eebd18c11f58a9790b8f071618a1bb5b2c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 29 Jan 2013 14:02:15 -0800 Subject: fetch: fetch objects by their exact SHA-1 object names Teach "git fetch" to accept an exact SHA-1 object name the user may obtain out of band on the LHS of a pathspec, and send it on a "want" message when the server side advertises the allow-tip-sha1-in-want capability. Signed-off-by: Junio C Hamano --- remote.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'remote.c') diff --git a/remote.c b/remote.c index 1b7828d19f..1118d058d6 100644 --- a/remote.c +++ b/remote.c @@ -15,6 +15,7 @@ static struct refspec s_tag_refspec = { 0, 1, 0, + 0, "refs/tags/*", "refs/tags/*" }; @@ -565,9 +566,13 @@ static struct refspec *parse_refspec_internal(int nr_refspec, const char **refsp flags = REFNAME_ALLOW_ONELEVEL | (is_glob ? REFNAME_REFSPEC_PATTERN : 0); if (fetch) { + unsigned char unused[40]; + /* LHS */ if (!*rs[i].src) ; /* empty is ok; it means "HEAD" */ + else if (llen == 40 && !get_sha1_hex(rs[i].src, unused)) + rs[i].exact_sha1 = 1; /* ok */ else if (!check_refname_format(rs[i].src, flags)) ; /* valid looking ref is ok */ else @@ -1495,7 +1500,12 @@ int get_fetch_map(const struct ref *remote_refs, } else { const char *name = refspec->src[0] ? refspec->src : "HEAD"; - ref_map = get_remote_ref(remote_refs, name); + if (refspec->exact_sha1) { + ref_map = alloc_ref(name); + get_sha1_hex(name, ref_map->old_sha1); + } else { + ref_map = get_remote_ref(remote_refs, name); + } if (!missing_ok && !ref_map) die("Couldn't find remote ref %s", name); if (ref_map) { -- cgit v1.2.1