Skip to content

Commit 03bdcfc

Browse files
committed
Merge branch 'ab/no-errno-from-resolve-ref-unsafe'
Remaining code-clean-up. * ab/no-errno-from-resolve-ref-unsafe: refs API: remove "failure_errno" from refs_resolve_ref_unsafe() sequencer: don't use die_errno() on refs_resolve_ref_unsafe() failure
2 parents c46452e + ce14de0 commit 03bdcfc

File tree

7 files changed

+35
-81
lines changed

7 files changed

+35
-81
lines changed

refs.c

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,9 @@ char *refs_resolve_refdup(struct ref_store *refs,
269269
struct object_id *oid, int *flags)
270270
{
271271
const char *result;
272-
int ignore_errno;
273272

274273
result = refs_resolve_ref_unsafe(refs, refname, resolve_flags,
275-
oid, flags, &ignore_errno);
274+
oid, flags);
276275
return xstrdup_or_null(result);
277276
}
278277

@@ -294,11 +293,10 @@ struct ref_filter {
294293

295294
int read_ref_full(const char *refname, int resolve_flags, struct object_id *oid, int *flags)
296295
{
297-
int ignore_errno;
298296
struct ref_store *refs = get_main_ref_store(the_repository);
299297

300298
if (refs_resolve_ref_unsafe(refs, refname, resolve_flags,
301-
oid, flags, &ignore_errno))
299+
oid, flags))
302300
return 0;
303301
return -1;
304302
}
@@ -310,9 +308,8 @@ int read_ref(const char *refname, struct object_id *oid)
310308

311309
int refs_ref_exists(struct ref_store *refs, const char *refname)
312310
{
313-
int ignore_errno;
314311
return !!refs_resolve_ref_unsafe(refs, refname, RESOLVE_REF_READING,
315-
NULL, NULL, &ignore_errno);
312+
NULL, NULL);
316313
}
317314

318315
int ref_exists(const char *refname)
@@ -656,15 +653,13 @@ int expand_ref(struct repository *repo, const char *str, int len,
656653
struct object_id *this_result;
657654
int flag;
658655
struct ref_store *refs = get_main_ref_store(repo);
659-
int ignore_errno;
660656

661657
this_result = refs_found ? &oid_from_ref : oid;
662658
strbuf_reset(&fullref);
663659
strbuf_addf(&fullref, *p, len, str);
664660
r = refs_resolve_ref_unsafe(refs, fullref.buf,
665661
RESOLVE_REF_READING,
666-
this_result, &flag,
667-
&ignore_errno);
662+
this_result, &flag);
668663
if (r) {
669664
if (!refs_found++)
670665
*ref = xstrdup(r);
@@ -693,14 +688,12 @@ int repo_dwim_log(struct repository *r, const char *str, int len,
693688
for (p = ref_rev_parse_rules; *p; p++) {
694689
struct object_id hash;
695690
const char *ref, *it;
696-
int ignore_errno;
697691

698692
strbuf_reset(&path);
699693
strbuf_addf(&path, *p, len, str);
700694
ref = refs_resolve_ref_unsafe(refs, path.buf,
701695
RESOLVE_REF_READING,
702-
oid ? &hash : NULL, NULL,
703-
&ignore_errno);
696+
oid ? &hash : NULL, NULL);
704697
if (!ref)
705698
continue;
706699
if (refs_reflog_exists(refs, path.buf))
@@ -1390,10 +1383,9 @@ int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
13901383
{
13911384
struct object_id oid;
13921385
int flag;
1393-
int ignore_errno;
13941386

13951387
if (refs_resolve_ref_unsafe(refs, "HEAD", RESOLVE_REF_READING,
1396-
&oid, &flag, &ignore_errno))
1388+
&oid, &flag))
13971389
return fn("HEAD", &oid, flag, cb_data);
13981390

13991391
return 0;
@@ -1682,15 +1674,13 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
16821674
const char *refname,
16831675
int resolve_flags,
16841676
struct object_id *oid,
1685-
int *flags, int *failure_errno)
1677+
int *flags)
16861678
{
16871679
static struct strbuf sb_refname = STRBUF_INIT;
16881680
struct object_id unused_oid;
16891681
int unused_flags;
16901682
int symref_count;
16911683

1692-
assert(failure_errno);
1693-
16941684
if (!oid)
16951685
oid = &unused_oid;
16961686
if (!flags)
@@ -1700,10 +1690,8 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
17001690

17011691
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
17021692
if (!(resolve_flags & RESOLVE_REF_ALLOW_BAD_NAME) ||
1703-
!refname_is_safe(refname)) {
1704-
*failure_errno = EINVAL;
1693+
!refname_is_safe(refname))
17051694
return NULL;
1706-
}
17071695

17081696
/*
17091697
* dwim_ref() uses REF_ISBROKEN to distinguish between
@@ -1718,9 +1706,10 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
17181706

17191707
for (symref_count = 0; symref_count < SYMREF_MAXDEPTH; symref_count++) {
17201708
unsigned int read_flags = 0;
1709+
int failure_errno;
17211710

17221711
if (refs_read_raw_ref(refs, refname, oid, &sb_refname,
1723-
&read_flags, failure_errno)) {
1712+
&read_flags, &failure_errno)) {
17241713
*flags |= read_flags;
17251714

17261715
/* In reading mode, refs must eventually resolve */
@@ -1732,9 +1721,9 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
17321721
* may show errors besides ENOENT if there are
17331722
* similarly-named refs.
17341723
*/
1735-
if (*failure_errno != ENOENT &&
1736-
*failure_errno != EISDIR &&
1737-
*failure_errno != ENOTDIR)
1724+
if (failure_errno != ENOENT &&
1725+
failure_errno != EISDIR &&
1726+
failure_errno != ENOTDIR)
17381727
return NULL;
17391728

17401729
oidclr(oid);
@@ -1760,16 +1749,13 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
17601749
}
17611750
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL)) {
17621751
if (!(resolve_flags & RESOLVE_REF_ALLOW_BAD_NAME) ||
1763-
!refname_is_safe(refname)) {
1764-
*failure_errno = EINVAL;
1752+
!refname_is_safe(refname))
17651753
return NULL;
1766-
}
17671754

17681755
*flags |= REF_ISBROKEN | REF_BAD_NAME;
17691756
}
17701757
}
17711758

1772-
*failure_errno = ELOOP;
17731759
return NULL;
17741760
}
17751761

@@ -1784,26 +1770,23 @@ int refs_init_db(struct strbuf *err)
17841770
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
17851771
struct object_id *oid, int *flags)
17861772
{
1787-
int ignore_errno;
1788-
17891773
return refs_resolve_ref_unsafe(get_main_ref_store(the_repository), refname,
1790-
resolve_flags, oid, flags, &ignore_errno);
1774+
resolve_flags, oid, flags);
17911775
}
17921776

17931777
int resolve_gitlink_ref(const char *submodule, const char *refname,
17941778
struct object_id *oid)
17951779
{
17961780
struct ref_store *refs;
17971781
int flags;
1798-
int ignore_errno;
17991782

18001783
refs = get_submodule_ref_store(submodule);
18011784

18021785
if (!refs)
18031786
return -1;
18041787

1805-
if (!refs_resolve_ref_unsafe(refs, refname, 0, oid, &flags,
1806-
&ignore_errno) || is_null_oid(oid))
1788+
if (!refs_resolve_ref_unsafe(refs, refname, 0, oid, &flags) ||
1789+
is_null_oid(oid))
18071790
return -1;
18081791
return 0;
18091792
}

refs.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,6 @@ struct worktree;
5858
* resolved. The function returns NULL for such ref names.
5959
* Caps and underscores refers to the special refs, such as HEAD,
6060
* FETCH_HEAD and friends, that all live outside of the refs/ directory.
61-
*
62-
* Callers should not inspect "errno" on failure, but rather pass in a
63-
* "failure_errno" parameter, on failure the "errno" will indicate the
64-
* type of failure encountered, but not necessarily one that came from
65-
* a syscall. We might have faked it up.
6661
*/
6762
#define RESOLVE_REF_READING 0x01
6863
#define RESOLVE_REF_NO_RECURSE 0x02
@@ -72,7 +67,7 @@ const char *refs_resolve_ref_unsafe(struct ref_store *refs,
7267
const char *refname,
7368
int resolve_flags,
7469
struct object_id *oid,
75-
int *flags, int *failure_errno);
70+
int *flags);
7671

7772
const char *resolve_ref_unsafe(const char *refname, int resolve_flags,
7873
struct object_id *oid, int *flags);

refs/files-backend.c

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,10 @@ static void loose_fill_ref_dir(struct ref_store *ref_store,
277277
create_dir_entry(dir->cache, refname.buf,
278278
refname.len));
279279
} else {
280-
int ignore_errno;
281280
if (!refs_resolve_ref_unsafe(&refs->base,
282281
refname.buf,
283282
RESOLVE_REF_READING,
284-
&oid, &flag, &ignore_errno)) {
283+
&oid, &flag)) {
285284
oidclr(&oid);
286285
flag |= REF_ISBROKEN;
287286
} else if (is_null_oid(&oid)) {
@@ -1006,7 +1005,6 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
10061005
{
10071006
struct strbuf ref_file = STRBUF_INIT;
10081007
struct ref_lock *lock;
1009-
int ignore_errno;
10101008

10111009
files_assert_main_repository(refs, "lock_ref_oid_basic");
10121010
assert(err);
@@ -1034,7 +1032,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
10341032
}
10351033

10361034
if (!refs_resolve_ref_unsafe(&refs->base, lock->ref_name, 0,
1037-
&lock->old_oid, NULL, &ignore_errno))
1035+
&lock->old_oid, NULL))
10381036
oidclr(&lock->old_oid);
10391037
goto out;
10401038

@@ -1399,7 +1397,6 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
13991397
struct strbuf tmp_renamed_log = STRBUF_INIT;
14001398
int log, ret;
14011399
struct strbuf err = STRBUF_INIT;
1402-
int ignore_errno;
14031400

14041401
files_reflog_path(refs, &sb_oldref, oldrefname);
14051402
files_reflog_path(refs, &sb_newref, newrefname);
@@ -1413,7 +1410,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
14131410

14141411
if (!refs_resolve_ref_unsafe(&refs->base, oldrefname,
14151412
RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
1416-
&orig_oid, &flag, &ignore_errno)) {
1413+
&orig_oid, &flag)) {
14171414
ret = error("refname %s not found", oldrefname);
14181415
goto out;
14191416
}
@@ -1459,7 +1456,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
14591456
*/
14601457
if (!copy && refs_resolve_ref_unsafe(&refs->base, newrefname,
14611458
RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
1462-
NULL, NULL, &ignore_errno) &&
1459+
NULL, NULL) &&
14631460
refs_delete_ref(&refs->base, NULL, newrefname,
14641461
NULL, REF_NO_DEREF)) {
14651462
if (errno == EISDIR) {
@@ -1828,12 +1825,10 @@ static int commit_ref_update(struct files_ref_store *refs,
18281825
*/
18291826
int head_flag;
18301827
const char *head_ref;
1831-
int ignore_errno;
18321828

18331829
head_ref = refs_resolve_ref_unsafe(&refs->base, "HEAD",
18341830
RESOLVE_REF_READING,
1835-
NULL, &head_flag,
1836-
&ignore_errno);
1831+
NULL, &head_flag);
18371832
if (head_ref && (head_flag & REF_ISSYMREF) &&
18381833
!strcmp(head_ref, lock->ref_name)) {
18391834
struct strbuf log_err = STRBUF_INIT;
@@ -1877,12 +1872,10 @@ static void update_symref_reflog(struct files_ref_store *refs,
18771872
{
18781873
struct strbuf err = STRBUF_INIT;
18791874
struct object_id new_oid;
1880-
int ignore_errno;
18811875

18821876
if (logmsg &&
18831877
refs_resolve_ref_unsafe(&refs->base, target,
1884-
RESOLVE_REF_READING, &new_oid, NULL,
1885-
&ignore_errno) &&
1878+
RESOLVE_REF_READING, &new_oid, NULL) &&
18861879
files_log_ref_write(refs, refname, &lock->old_oid,
18871880
&new_oid, logmsg, 0, &err)) {
18881881
error("%s", err.buf);
@@ -2156,7 +2149,6 @@ static int files_reflog_iterator_advance(struct ref_iterator *ref_iterator)
21562149
(struct files_reflog_iterator *)ref_iterator;
21572150
struct dir_iterator *diter = iter->dir_iterator;
21582151
int ok;
2159-
int ignore_errno;
21602152

21612153
while ((ok = dir_iterator_advance(diter)) == ITER_OK) {
21622154
int flags;
@@ -2170,8 +2162,7 @@ static int files_reflog_iterator_advance(struct ref_iterator *ref_iterator)
21702162

21712163
if (!refs_resolve_ref_unsafe(iter->ref_store,
21722164
diter->relative_path, 0,
2173-
&iter->oid, &flags,
2174-
&ignore_errno)) {
2165+
&iter->oid, &flags)) {
21752166
error("bad ref for %s", diter->path.buf);
21762167
continue;
21772168
}
@@ -2515,11 +2506,9 @@ static int lock_ref_for_update(struct files_ref_store *refs,
25152506
* the transaction, so we have to read it here
25162507
* to record and possibly check old_oid:
25172508
*/
2518-
int ignore_errno;
25192509
if (!refs_resolve_ref_unsafe(&refs->base,
25202510
referent.buf, 0,
2521-
&lock->old_oid, NULL,
2522-
&ignore_errno)) {
2511+
&lock->old_oid, NULL)) {
25232512
if (update->flags & REF_HAVE_OLD) {
25242513
strbuf_addf(err, "cannot lock ref '%s': "
25252514
"error reading reference",
@@ -3208,14 +3197,12 @@ static int files_reflog_expire(struct ref_store *ref_store,
32083197

32093198
if ((expire_flags & EXPIRE_REFLOGS_UPDATE_REF) &&
32103199
!is_null_oid(&cb.last_kept_oid)) {
3211-
int ignore_errno;
32123200
int type;
32133201
const char *ref;
32143202

32153203
ref = refs_resolve_ref_unsafe(&refs->base, refname,
32163204
RESOLVE_REF_NO_RECURSE,
3217-
NULL, &type,
3218-
&ignore_errno);
3205+
NULL, &type);
32193206
update = !!(ref && !(type & REF_ISSYMREF));
32203207
}
32213208

remote.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,8 @@ static void read_config(struct repository *repo)
508508

509509
repo->remote_state->current_branch = NULL;
510510
if (startup_info->have_repository) {
511-
int ignore_errno;
512511
const char *head_ref = refs_resolve_ref_unsafe(
513-
get_main_ref_store(repo), "HEAD", 0, NULL, &flag, &ignore_errno);
512+
get_main_ref_store(repo), "HEAD", 0, NULL, &flag);
514513
if (head_ref && (flag & REF_ISSYMREF) &&
515514
skip_prefix(head_ref, "refs/heads/", &head_ref)) {
516515
repo->remote_state->current_branch = make_branch(

sequencer.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,6 @@ void print_commit_summary(struct repository *r,
12811281
struct strbuf author_ident = STRBUF_INIT;
12821282
struct strbuf committer_ident = STRBUF_INIT;
12831283
struct ref_store *refs;
1284-
int resolve_errno;
12851284

12861285
commit = lookup_commit(r, oid);
12871286
if (!commit)
@@ -1332,12 +1331,9 @@ void print_commit_summary(struct repository *r,
13321331
diff_setup_done(&rev.diffopt);
13331332

13341333
refs = get_main_ref_store(the_repository);
1335-
head = refs_resolve_ref_unsafe(refs, "HEAD", 0, NULL, NULL,
1336-
&resolve_errno);
1337-
if (!head) {
1338-
errno = resolve_errno;
1339-
die_errno(_("unable to resolve HEAD after creating commit"));
1340-
}
1334+
head = refs_resolve_ref_unsafe(refs, "HEAD", 0, NULL, NULL);
1335+
if (!head)
1336+
die(_("unable to resolve HEAD after creating commit"));
13411337
if (!strcmp(head, "HEAD"))
13421338
head = _("detached HEAD");
13431339
else

t/helper/test-ref-store.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,9 @@ static int cmd_resolve_ref(struct ref_store *refs, const char **argv)
180180
int resolve_flags = arg_flags(*argv++, "resolve-flags", empty_flags);
181181
int flags;
182182
const char *ref;
183-
int ignore_errno;
184183

185184
ref = refs_resolve_ref_unsafe(refs, refname, resolve_flags,
186-
&oid, &flags, &ignore_errno);
185+
&oid, &flags);
187186
printf("%s %s 0x%x\n", oid_to_hex(&oid), ref ? ref : "(null)", flags);
188187
return ref ? 0 : 1;
189188
}

0 commit comments

Comments
 (0)