Skip to content

Commit 8b72fea

Browse files
hanwengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ef18119 commit 8b72fea

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

refs.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,17 +1666,18 @@ static int refs_read_special_head(struct ref_store *ref_store,
16661666
return result;
16671667
}
16681668

1669-
int refs_read_raw_ref(struct ref_store *ref_store,
1670-
const char *refname, struct object_id *oid,
1671-
struct strbuf *referent, unsigned int *type)
1669+
int refs_read_raw_ref(struct ref_store *ref_store, const char *refname,
1670+
struct object_id *oid, struct strbuf *referent,
1671+
unsigned int *type, int *failure_errno)
16721672
{
1673+
assert(failure_errno);
16731674
if (!strcmp(refname, "FETCH_HEAD") || !strcmp(refname, "MERGE_HEAD")) {
16741675
return refs_read_special_head(ref_store, refname, oid, referent,
16751676
type);
16761677
}
16771678

16781679
return ref_store->be->read_raw_ref(ref_store, refname, oid, referent,
1679-
type, &errno);
1680+
type, failure_errno);
16801681
}
16811682

16821683
const char *refs_werrres_ref_unsafe(struct ref_store *refs,
@@ -1720,9 +1721,8 @@ const char *refs_werrres_ref_unsafe(struct ref_store *refs,
17201721
for (symref_count = 0; symref_count < SYMREF_MAXDEPTH; symref_count++) {
17211722
unsigned int read_flags = 0;
17221723

1723-
errno = 0;
1724-
if (refs_read_raw_ref(refs, refname,
1725-
oid, &sb_refname, &read_flags)) {
1724+
if (refs_read_raw_ref(refs, refname, oid, &sb_refname,
1725+
&read_flags, failure_errno)) {
17261726
*flags |= read_flags;
17271727
if (errno)
17281728
*failure_errno = errno;
@@ -2240,6 +2240,13 @@ int refs_verify_refname_available(struct ref_store *refs,
22402240

22412241
strbuf_grow(&dirname, strlen(refname) + 1);
22422242
for (slash = strchr(refname, '/'); slash; slash = strchr(slash + 1, '/')) {
2243+
/*
2244+
* Just saying "Is a directory" when we e.g. can't
2245+
* lock some multi-level ref isn't very informative,
2246+
* the user won't be told *what* is a directory, so
2247+
* let's not use strerror() below.
2248+
*/
2249+
int ignore_errno;
22432250
/* Expand dirname to the new prefix, not including the trailing slash: */
22442251
strbuf_add(&dirname, refname + dirname.len, slash - refname - dirname.len);
22452252

@@ -2251,7 +2258,8 @@ int refs_verify_refname_available(struct ref_store *refs,
22512258
if (skip && string_list_has_string(skip, dirname.buf))
22522259
continue;
22532260

2254-
if (!refs_read_raw_ref(refs, dirname.buf, &oid, &referent, &type)) {
2261+
if (!refs_read_raw_ref(refs, dirname.buf, &oid, &referent,
2262+
&type, &ignore_errno)) {
22552263
strbuf_addf(err, _("'%s' exists; cannot create '%s'"),
22562264
dirname.buf, refname);
22572265
goto cleanup;

refs/files-backend.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,11 @@ static int files_read_raw_ref(struct ref_store *ref_store, const char *refname,
381381
goto out;
382382

383383
if (lstat(path, &st) < 0) {
384+
int ignore_errno;
384385
if (errno != ENOENT)
385386
goto out;
386-
if (refs_read_raw_ref(refs->packed_ref_store, refname,
387-
oid, referent, type)) {
387+
if (refs_read_raw_ref(refs->packed_ref_store, refname, oid,
388+
referent, type, &ignore_errno)) {
388389
errno = ENOENT;
389390
goto out;
390391
}
@@ -418,13 +419,14 @@ static int files_read_raw_ref(struct ref_store *ref_store, const char *refname,
418419

419420
/* Is it a directory? */
420421
if (S_ISDIR(st.st_mode)) {
422+
int ignore_errno;
421423
/*
422424
* Even though there is a directory where the loose
423425
* ref is supposed to be, there could still be a
424426
* packed ref:
425427
*/
426-
if (refs_read_raw_ref(refs->packed_ref_store, refname,
427-
oid, referent, type)) {
428+
if (refs_read_raw_ref(refs->packed_ref_store, refname, oid,
429+
referent, type, &ignore_errno)) {
428430
errno = EISDIR;
429431
goto out;
430432
}

refs/packed-backend.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,7 @@ int is_packed_transaction_needed(struct ref_store *ref_store,
13471347
ret = 0;
13481348
for (i = 0; i < transaction->nr; i++) {
13491349
struct ref_update *update = transaction->updates[i];
1350+
int failure_errno;
13501351
unsigned int type;
13511352
struct object_id oid;
13521353

@@ -1357,9 +1358,9 @@ int is_packed_transaction_needed(struct ref_store *ref_store,
13571358
*/
13581359
continue;
13591360

1360-
if (!refs_read_raw_ref(ref_store, update->refname,
1361-
&oid, &referent, &type) ||
1362-
errno != ENOENT) {
1361+
if (!refs_read_raw_ref(ref_store, update->refname, &oid,
1362+
&referent, &type, &failure_errno) ||
1363+
failure_errno != ENOENT) {
13631364
/*
13641365
* We have to actually delete that reference
13651366
* -> this transaction is needed.

refs/refs-internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,9 @@ struct ref_update {
149149
const char refname[FLEX_ARRAY];
150150
};
151151

152-
int refs_read_raw_ref(struct ref_store *ref_store,
153-
const char *refname, struct object_id *oid,
154-
struct strbuf *referent, unsigned int *type);
152+
int refs_read_raw_ref(struct ref_store *ref_store, const char *refname,
153+
struct object_id *oid, struct strbuf *referent,
154+
unsigned int *type, int *failure_errno);
155155

156156
/*
157157
* Write an error to `err` and return a nonzero value iff the same

0 commit comments

Comments
 (0)