зеркало из https://github.com/microsoft/git.git
refs API: remove refs_read_ref_full() wrapper
Remove the refs_read_ref_full() wrapper in favor of migrating various refs.c API users to the underlying refs_werrres_ref_unsafe() function. A careful reading of these callers shows that the callers of this function did not care about "errno", by moving away from the refs_resolve_ref_unsafe() wrapper we can be sure that nothing relies on it anymore. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
52106430dc
Коммит
76887df014
22
refs.c
22
refs.c
|
@ -290,18 +290,15 @@ struct ref_filter {
|
|||
void *cb_data;
|
||||
};
|
||||
|
||||
int refs_read_ref_full(struct ref_store *refs, const char *refname,
|
||||
int resolve_flags, struct object_id *oid, int *flags)
|
||||
{
|
||||
if (refs_resolve_ref_unsafe(refs, refname, resolve_flags, oid, flags))
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int read_ref_full(const char *refname, int resolve_flags, struct object_id *oid, int *flags)
|
||||
{
|
||||
return refs_read_ref_full(get_main_ref_store(the_repository), refname,
|
||||
resolve_flags, oid, flags);
|
||||
int ignore_errno;
|
||||
struct ref_store *refs = get_main_ref_store(the_repository);
|
||||
|
||||
if (refs_werrres_ref_unsafe(refs, refname, resolve_flags,
|
||||
oid, flags, &ignore_errno))
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int read_ref(const char *refname, struct object_id *oid)
|
||||
|
@ -1376,9 +1373,10 @@ int refs_head_ref(struct ref_store *refs, each_ref_fn fn, void *cb_data)
|
|||
{
|
||||
struct object_id oid;
|
||||
int flag;
|
||||
int ignore_errno;
|
||||
|
||||
if (!refs_read_ref_full(refs, "HEAD", RESOLVE_REF_READING,
|
||||
&oid, &flag))
|
||||
if (refs_werrres_ref_unsafe(refs, "HEAD", RESOLVE_REF_READING,
|
||||
&oid, &flag, &ignore_errno))
|
||||
return fn("HEAD", &oid, flag, cb_data);
|
||||
|
||||
return 0;
|
||||
|
|
2
refs.h
2
refs.h
|
@ -89,8 +89,6 @@ char *refs_resolve_refdup(struct ref_store *refs,
|
|||
char *resolve_refdup(const char *refname, int resolve_flags,
|
||||
struct object_id *oid, int *flags);
|
||||
|
||||
int refs_read_ref_full(struct ref_store *refs, const char *refname,
|
||||
int resolve_flags, struct object_id *oid, int *flags);
|
||||
int read_ref_full(const char *refname, int resolve_flags,
|
||||
struct object_id *oid, int *flags);
|
||||
int read_ref(const char *refname, struct object_id *oid);
|
||||
|
|
|
@ -1006,6 +1006,7 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
|
|||
{
|
||||
struct strbuf ref_file = STRBUF_INIT;
|
||||
struct ref_lock *lock;
|
||||
int ignore_errno;
|
||||
|
||||
files_assert_main_repository(refs, "lock_ref_oid_basic");
|
||||
assert(err);
|
||||
|
@ -1032,9 +1033,8 @@ static struct ref_lock *lock_ref_oid_basic(struct files_ref_store *refs,
|
|||
goto error_return;
|
||||
}
|
||||
|
||||
if (refs_read_ref_full(&refs->base, lock->ref_name,
|
||||
0,
|
||||
&lock->old_oid, NULL))
|
||||
if (!refs_werrres_ref_unsafe(&refs->base, lock->ref_name, 0,
|
||||
&lock->old_oid, NULL, &ignore_errno))
|
||||
oidclr(&lock->old_oid);
|
||||
goto out;
|
||||
|
||||
|
@ -1397,6 +1397,7 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
|
|||
struct strbuf tmp_renamed_log = STRBUF_INIT;
|
||||
int log, ret;
|
||||
struct strbuf err = STRBUF_INIT;
|
||||
int ignore_errno;
|
||||
|
||||
files_reflog_path(refs, &sb_oldref, oldrefname);
|
||||
files_reflog_path(refs, &sb_newref, newrefname);
|
||||
|
@ -1454,9 +1455,9 @@ static int files_copy_or_rename_ref(struct ref_store *ref_store,
|
|||
* the safety anyway; we want to delete the reference whatever
|
||||
* its current value.
|
||||
*/
|
||||
if (!copy && !refs_read_ref_full(&refs->base, newrefname,
|
||||
RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
|
||||
NULL, NULL) &&
|
||||
if (!copy && refs_werrres_ref_unsafe(&refs->base, newrefname,
|
||||
RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
|
||||
NULL, NULL, &ignore_errno) &&
|
||||
refs_delete_ref(&refs->base, NULL, newrefname,
|
||||
NULL, REF_NO_DEREF)) {
|
||||
if (errno == EISDIR) {
|
||||
|
@ -1868,9 +1869,12 @@ static void update_symref_reflog(struct files_ref_store *refs,
|
|||
{
|
||||
struct strbuf err = STRBUF_INIT;
|
||||
struct object_id new_oid;
|
||||
int ignore_errno;
|
||||
|
||||
if (logmsg &&
|
||||
!refs_read_ref_full(&refs->base, target,
|
||||
RESOLVE_REF_READING, &new_oid, NULL) &&
|
||||
refs_werrres_ref_unsafe(&refs->base, target,
|
||||
RESOLVE_REF_READING, &new_oid, NULL,
|
||||
&ignore_errno) &&
|
||||
files_log_ref_write(refs, refname, &lock->old_oid,
|
||||
&new_oid, logmsg, 0, &err)) {
|
||||
error("%s", err.buf);
|
||||
|
@ -2144,6 +2148,7 @@ static int files_reflog_iterator_advance(struct ref_iterator *ref_iterator)
|
|||
(struct files_reflog_iterator *)ref_iterator;
|
||||
struct dir_iterator *diter = iter->dir_iterator;
|
||||
int ok;
|
||||
int ignore_errno;
|
||||
|
||||
while ((ok = dir_iterator_advance(diter)) == ITER_OK) {
|
||||
int flags;
|
||||
|
@ -2155,9 +2160,10 @@ static int files_reflog_iterator_advance(struct ref_iterator *ref_iterator)
|
|||
if (ends_with(diter->basename, ".lock"))
|
||||
continue;
|
||||
|
||||
if (refs_read_ref_full(iter->ref_store,
|
||||
diter->relative_path, 0,
|
||||
&iter->oid, &flags)) {
|
||||
if (!refs_werrres_ref_unsafe(iter->ref_store,
|
||||
diter->relative_path, 0,
|
||||
&iter->oid, &flags,
|
||||
&ignore_errno)) {
|
||||
error("bad ref for %s", diter->path.buf);
|
||||
continue;
|
||||
}
|
||||
|
@ -2501,9 +2507,11 @@ static int lock_ref_for_update(struct files_ref_store *refs,
|
|||
* the transaction, so we have to read it here
|
||||
* to record and possibly check old_oid:
|
||||
*/
|
||||
if (refs_read_ref_full(&refs->base,
|
||||
referent.buf, 0,
|
||||
&lock->old_oid, NULL)) {
|
||||
int ignore_errno;
|
||||
if (!refs_werrres_ref_unsafe(&refs->base,
|
||||
referent.buf, 0,
|
||||
&lock->old_oid, NULL,
|
||||
&ignore_errno)) {
|
||||
if (update->flags & REF_HAVE_OLD) {
|
||||
strbuf_addf(err, "cannot lock ref '%s': "
|
||||
"error reading reference",
|
||||
|
|
|
@ -563,16 +563,17 @@ int other_head_refs(each_ref_fn fn, void *cb_data)
|
|||
struct worktree *wt = *p;
|
||||
struct object_id oid;
|
||||
int flag;
|
||||
int ignore_errno;
|
||||
|
||||
if (wt->is_current)
|
||||
continue;
|
||||
|
||||
strbuf_reset(&refname);
|
||||
strbuf_worktree_ref(wt, &refname, "HEAD");
|
||||
if (!refs_read_ref_full(get_main_ref_store(the_repository),
|
||||
refname.buf,
|
||||
RESOLVE_REF_READING,
|
||||
&oid, &flag))
|
||||
if (refs_werrres_ref_unsafe(get_main_ref_store(the_repository),
|
||||
refname.buf,
|
||||
RESOLVE_REF_READING,
|
||||
&oid, &flag, &ignore_errno))
|
||||
ret = fn(refname.buf, &oid, flag, cb_data);
|
||||
if (ret)
|
||||
break;
|
||||
|
|
Загрузка…
Ссылка в новой задаче