Merge branch 'jc/broken-ref-dwim-fix' into next

* jc/broken-ref-dwim-fix:
  resolve_ref(): report breakage to the caller without warning
  resolve_ref(): expose REF_ISBROKEN flag

Conflicts:
	refs.c
This commit is contained in:
Junio C Hamano
2011-10-19 14:09:58 -07:00
2 changed files with 20 additions and 16 deletions

31
refs.c
View File

@@ -4,9 +4,8 @@
#include "tag.h"
#include "dir.h"
/* ISSYMREF=01 and ISPACKED=02 are public interfaces */
#define REF_KNOWS_PEELED 04
#define REF_BROKEN 010
/* ISSYMREF=0x01, ISPACKED=0x02 and ISBROKEN=0x04 are public interfaces */
#define REF_KNOWS_PEELED 0x10
struct ref_entry {
unsigned char flag; /* ISSYMREF? ISPACKED? */
@@ -352,12 +351,12 @@ static void get_ref_dir(struct ref_cache *refs, const char *base,
flag = 0;
if (resolve_gitlink_ref(refs->name, ref, sha1) < 0) {
hashclr(sha1);
flag |= REF_BROKEN;
flag |= REF_ISBROKEN;
}
} else
if (!resolve_ref(ref, sha1, 1, &flag)) {
hashclr(sha1);
flag |= REF_BROKEN;
flag |= REF_ISBROKEN;
}
add_ref(ref, sha1, flag, array, NULL);
}
@@ -507,7 +506,6 @@ const char *resolve_ref(const char *refname, unsigned char *sha1, int reading, i
ssize_t len;
char buffer[256];
static char refname_buffer[256];
char path[PATH_MAX];
if (flag)
*flag = 0;
@@ -516,6 +514,7 @@ const char *resolve_ref(const char *refname, unsigned char *sha1, int reading, i
return NULL;
for (;;) {
char path[PATH_MAX];
struct stat st;
char *buf;
int fd;
@@ -588,21 +587,22 @@ const char *resolve_ref(const char *refname, unsigned char *sha1, int reading, i
*/
if (prefixcmp(buffer, "ref:"))
break;
if (flag)
*flag |= REF_ISSYMREF;
buf = buffer + 4;
while (isspace(*buf))
buf++;
if (check_refname_format(buf, REFNAME_ALLOW_ONELEVEL)) {
warning("symbolic reference in %s is formatted incorrectly",
path);
if (flag)
*flag |= REF_ISBROKEN;
return NULL;
}
refname = strcpy(refname_buffer, buf);
if (flag)
*flag |= REF_ISSYMREF;
}
/* Please note that FETCH_HEAD has a second line containing other data. */
if (get_sha1_hex(buffer, sha1) || (buffer[40] != '\0' && !isspace(buffer[40]))) {
warning("reference in %s is formatted incorrectly", path);
if (flag)
*flag |= REF_ISBROKEN;
return NULL;
}
return refname;
@@ -630,8 +630,8 @@ static int do_one_ref(const char *base, each_ref_fn fn, int trim,
return 0;
if (!(flags & DO_FOR_EACH_INCLUDE_BROKEN)) {
if (entry->flag & REF_BROKEN)
return 0; /* ignore dangling symref */
if (entry->flag & REF_ISBROKEN)
return 0; /* ignore broken refs e.g. dangling symref */
if (!has_sha1_file(entry->sha1)) {
error("%s does not point to a valid object!", entry->name);
return 0;
@@ -1129,8 +1129,11 @@ int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref)
*ref = xstrdup(r);
if (!warn_ambiguous_refs)
break;
} else if ((flag & REF_ISSYMREF) && strcmp(fullref, "HEAD"))
} else if ((flag & REF_ISSYMREF) && strcmp(fullref, "HEAD")) {
warning("ignoring dangling symref %s.", fullref);
} else if ((flag & REF_ISBROKEN) && strchr(fullref, '/')) {
warning("ignoring broken ref %s.", fullref);
}
}
free(last_branch);
return refs_found;

5
refs.h
View File

@@ -10,8 +10,9 @@ struct ref_lock {
int force_write;
};
#define REF_ISSYMREF 01
#define REF_ISPACKED 02
#define REF_ISSYMREF 0x01
#define REF_ISPACKED 0x02
#define REF_ISBROKEN 0x04
/*
* Calls the specified function for each ref file until it returns nonzero,