@matheusbsbs / matheus-bagliano / commits / c51d13692d
Fork 0

get_sha1_basic(): try refs/... and finally refs/remotes/$foo/HEAD

This implements the suggestion by Jeff King to use refs/remotes/$foo/HEAD to interpret a shorthand "$foo" to mean the primary branch head of a tracked remote. clone needs to be told about this convention as well. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Mar 21, 2006 at 01:42 UTC c51d13692d4e451c755dd7da3521c5db395df192
1 file changed +12 -11
sha1_name.c
+12 -11
@@ -235,18 +235,21 @@ static int ambiguous_path(const char *path, int len)
235
236 static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
237 {
238 - static const char *prefix[] = {
239 - "",
240 - "refs",
241 - "refs/tags",
242 - "refs/heads",
243 - "refs/remotes",
238 + static const char *fmt[] = {
239 + "/%.*s",
240 + "refs/%.*s",
241 + "refs/tags/%.*s",
242 + "refs/heads/%.*s",
243 + "refs/remotes/%.*s",
244 + "refs/remotes/%.*s/HEAD",
245 NULL
246 };
247 const char **p;
248 const char *warning = "warning: refname '%.*s' is ambiguous.\n";
249 char *pathname;
250 int already_found = 0;
251 + unsigned char *this_result;
252 + unsigned char sha1_from_ref[20];
253
254 if (len == 40 && !get_sha1_hex(str, sha1))
255 return 0;
@@ -255,11 +258,9 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
258 if (ambiguous_path(str, len))
259 return -1;
260
258 - for (p = prefix; *p; p++) {
259 - unsigned char sha1_from_ref[20];
260 - unsigned char *this_result =
261 - already_found ? sha1_from_ref : sha1;
262 - pathname = git_path("%s/%.*s", *p, len, str);
261 + for (p = fmt; *p; p++) {
262 + this_result = already_found ? sha1_from_ref : sha1;
263 + pathname = git_path(*p, len, str);
264 if (!read_ref(pathname, this_result)) {
265 if (warn_ambiguous_refs) {
266 if (already_found &&