refs API: make refs_read_raw_ref() not set errno
Add a "failure_errno" to refs_read_raw_ref(), his allows refs_werrres_ref_unsafe() to pass along its "failure_errno", as a first step before its own callers are migrated to pass it further up the chain. We are leaving out out the refs_read_special_head() in refs_read_raw_ref() for now, as noted in a subsequent commit moving it to "failure_errno" will require some special consideration. Signed-off-by: Han-Wen Nienhuys <hanwen@google.com> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
ef18119dec
commit
8b72fea7e9
24
refs.c
24
refs.c
@ -1666,17 +1666,18 @@ done:
|
||||
return result;
|
||||
}
|
||||
|
||||
int refs_read_raw_ref(struct ref_store *ref_store,
|
||||
const char *refname, struct object_id *oid,
|
||||
struct strbuf *referent, unsigned int *type)
|
||||
int refs_read_raw_ref(struct ref_store *ref_store, const char *refname,
|
||||
struct object_id *oid, struct strbuf *referent,
|
||||
unsigned int *type, int *failure_errno)
|
||||
{
|
||||
assert(failure_errno);
|
||||
if (!strcmp(refname, "FETCH_HEAD") || !strcmp(refname, "MERGE_HEAD")) {
|
||||
return refs_read_special_head(ref_store, refname, oid, referent,
|
||||
type);
|
||||
}
|
||||
|
||||
return ref_store->be->read_raw_ref(ref_store, refname, oid, referent,
|
||||
type, &errno);
|
||||
type, failure_errno);
|
||||
}
|
||||
|
||||
const char *refs_werrres_ref_unsafe(struct ref_store *refs,
|
||||
@ -1720,9 +1721,8 @@ const char *refs_werrres_ref_unsafe(struct ref_store *refs,
|
||||
for (symref_count = 0; symref_count < SYMREF_MAXDEPTH; symref_count++) {
|
||||
unsigned int read_flags = 0;
|
||||
|
||||
errno = 0;
|
||||
if (refs_read_raw_ref(refs, refname,
|
||||
oid, &sb_refname, &read_flags)) {
|
||||
if (refs_read_raw_ref(refs, refname, oid, &sb_refname,
|
||||
&read_flags, failure_errno)) {
|
||||
*flags |= read_flags;
|
||||
if (errno)
|
||||
*failure_errno = errno;
|
||||
@ -2240,6 +2240,13 @@ int refs_verify_refname_available(struct ref_store *refs,
|
||||
|
||||
strbuf_grow(&dirname, strlen(refname) + 1);
|
||||
for (slash = strchr(refname, '/'); slash; slash = strchr(slash + 1, '/')) {
|
||||
/*
|
||||
* Just saying "Is a directory" when we e.g. can't
|
||||
* lock some multi-level ref isn't very informative,
|
||||
* the user won't be told *what* is a directory, so
|
||||
* let's not use strerror() below.
|
||||
*/
|
||||
int ignore_errno;
|
||||
/* Expand dirname to the new prefix, not including the trailing slash: */
|
||||
strbuf_add(&dirname, refname + dirname.len, slash - refname - dirname.len);
|
||||
|
||||
@ -2251,7 +2258,8 @@ int refs_verify_refname_available(struct ref_store *refs,
|
||||
if (skip && string_list_has_string(skip, dirname.buf))
|
||||
continue;
|
||||
|
||||
if (!refs_read_raw_ref(refs, dirname.buf, &oid, &referent, &type)) {
|
||||
if (!refs_read_raw_ref(refs, dirname.buf, &oid, &referent,
|
||||
&type, &ignore_errno)) {
|
||||
strbuf_addf(err, _("'%s' exists; cannot create '%s'"),
|
||||
dirname.buf, refname);
|
||||
goto cleanup;
|
||||
|
@ -381,10 +381,11 @@ stat_ref:
|
||||
goto out;
|
||||
|
||||
if (lstat(path, &st) < 0) {
|
||||
int ignore_errno;
|
||||
if (errno != ENOENT)
|
||||
goto out;
|
||||
if (refs_read_raw_ref(refs->packed_ref_store, refname,
|
||||
oid, referent, type)) {
|
||||
if (refs_read_raw_ref(refs->packed_ref_store, refname, oid,
|
||||
referent, type, &ignore_errno)) {
|
||||
errno = ENOENT;
|
||||
goto out;
|
||||
}
|
||||
@ -418,13 +419,14 @@ stat_ref:
|
||||
|
||||
/* Is it a directory? */
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
int ignore_errno;
|
||||
/*
|
||||
* Even though there is a directory where the loose
|
||||
* ref is supposed to be, there could still be a
|
||||
* packed ref:
|
||||
*/
|
||||
if (refs_read_raw_ref(refs->packed_ref_store, refname,
|
||||
oid, referent, type)) {
|
||||
if (refs_read_raw_ref(refs->packed_ref_store, refname, oid,
|
||||
referent, type, &ignore_errno)) {
|
||||
errno = EISDIR;
|
||||
goto out;
|
||||
}
|
||||
|
@ -1347,6 +1347,7 @@ int is_packed_transaction_needed(struct ref_store *ref_store,
|
||||
ret = 0;
|
||||
for (i = 0; i < transaction->nr; i++) {
|
||||
struct ref_update *update = transaction->updates[i];
|
||||
int failure_errno;
|
||||
unsigned int type;
|
||||
struct object_id oid;
|
||||
|
||||
@ -1357,9 +1358,9 @@ int is_packed_transaction_needed(struct ref_store *ref_store,
|
||||
*/
|
||||
continue;
|
||||
|
||||
if (!refs_read_raw_ref(ref_store, update->refname,
|
||||
&oid, &referent, &type) ||
|
||||
errno != ENOENT) {
|
||||
if (!refs_read_raw_ref(ref_store, update->refname, &oid,
|
||||
&referent, &type, &failure_errno) ||
|
||||
failure_errno != ENOENT) {
|
||||
/*
|
||||
* We have to actually delete that reference
|
||||
* -> this transaction is needed.
|
||||
|
@ -149,9 +149,9 @@ struct ref_update {
|
||||
const char refname[FLEX_ARRAY];
|
||||
};
|
||||
|
||||
int refs_read_raw_ref(struct ref_store *ref_store,
|
||||
const char *refname, struct object_id *oid,
|
||||
struct strbuf *referent, unsigned int *type);
|
||||
int refs_read_raw_ref(struct ref_store *ref_store, const char *refname,
|
||||
struct object_id *oid, struct strbuf *referent,
|
||||
unsigned int *type, int *failure_errno);
|
||||
|
||||
/*
|
||||
* Write an error to `err` and return a nonzero value iff the same
|
||||
|
Loading…
Reference in New Issue
Block a user