Merge branch 'mh/packed-ref-store-prep'
Bugfix for a topic that is (only) in 'master'. * mh/packed-ref-store-prep: for_each_bisect_ref(): don't trim refnames lock_packed_refs(): fix cache validity check
This commit is contained in:
commit
5c83d850d0
12
refs.c
12
refs.c
@ -1342,6 +1342,18 @@ int for_each_ref_in_submodule(const char *submodule, const char *prefix,
|
|||||||
prefix, fn, cb_data);
|
prefix, fn, cb_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int for_each_fullref_in_submodule(const char *submodule, const char *prefix,
|
||||||
|
each_ref_fn fn, void *cb_data,
|
||||||
|
unsigned int broken)
|
||||||
|
{
|
||||||
|
unsigned int flag = 0;
|
||||||
|
|
||||||
|
if (broken)
|
||||||
|
flag = DO_FOR_EACH_INCLUDE_BROKEN;
|
||||||
|
return do_for_each_ref(get_submodule_ref_store(submodule),
|
||||||
|
prefix, fn, 0, flag, cb_data);
|
||||||
|
}
|
||||||
|
|
||||||
int for_each_replace_ref(each_ref_fn fn, void *cb_data)
|
int for_each_replace_ref(each_ref_fn fn, void *cb_data)
|
||||||
{
|
{
|
||||||
return do_for_each_ref(get_main_ref_store(),
|
return do_for_each_ref(get_main_ref_store(),
|
||||||
|
5
refs.h
5
refs.h
@ -303,7 +303,10 @@ int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);
|
|||||||
int for_each_ref_submodule(const char *submodule,
|
int for_each_ref_submodule(const char *submodule,
|
||||||
each_ref_fn fn, void *cb_data);
|
each_ref_fn fn, void *cb_data);
|
||||||
int for_each_ref_in_submodule(const char *submodule, const char *prefix,
|
int for_each_ref_in_submodule(const char *submodule, const char *prefix,
|
||||||
each_ref_fn fn, void *cb_data);
|
each_ref_fn fn, void *cb_data);
|
||||||
|
int for_each_fullref_in_submodule(const char *submodule, const char *prefix,
|
||||||
|
each_ref_fn fn, void *cb_data,
|
||||||
|
unsigned int broken);
|
||||||
int for_each_tag_ref_submodule(const char *submodule,
|
int for_each_tag_ref_submodule(const char *submodule,
|
||||||
each_ref_fn fn, void *cb_data);
|
each_ref_fn fn, void *cb_data);
|
||||||
int for_each_branch_ref_submodule(const char *submodule,
|
int for_each_branch_ref_submodule(const char *submodule,
|
||||||
|
@ -370,6 +370,18 @@ static void files_ref_path(struct files_ref_store *refs,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Check that the packed refs cache (if any) still reflects the
|
||||||
|
* contents of the file. If not, clear the cache.
|
||||||
|
*/
|
||||||
|
static void validate_packed_ref_cache(struct files_ref_store *refs)
|
||||||
|
{
|
||||||
|
if (refs->packed &&
|
||||||
|
!stat_validity_check(&refs->packed->validity,
|
||||||
|
files_packed_refs_path(refs)))
|
||||||
|
clear_packed_ref_cache(refs);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the packed_ref_cache for the specified files_ref_store,
|
* Get the packed_ref_cache for the specified files_ref_store,
|
||||||
* creating and populating it if it hasn't been read before or if the
|
* creating and populating it if it hasn't been read before or if the
|
||||||
@ -382,10 +394,8 @@ static struct packed_ref_cache *get_packed_ref_cache(struct files_ref_store *ref
|
|||||||
{
|
{
|
||||||
const char *packed_refs_file = files_packed_refs_path(refs);
|
const char *packed_refs_file = files_packed_refs_path(refs);
|
||||||
|
|
||||||
if (refs->packed &&
|
if (!is_lock_file_locked(&refs->packed_refs_lock))
|
||||||
!is_lock_file_locked(&refs->packed_refs_lock) &&
|
validate_packed_ref_cache(refs);
|
||||||
!stat_validity_check(&refs->packed->validity, packed_refs_file))
|
|
||||||
clear_packed_ref_cache(refs);
|
|
||||||
|
|
||||||
if (!refs->packed)
|
if (!refs->packed)
|
||||||
refs->packed = read_packed_refs(packed_refs_file);
|
refs->packed = read_packed_refs(packed_refs_file);
|
||||||
@ -1312,13 +1322,17 @@ static int lock_packed_refs(struct files_ref_store *refs, int flags)
|
|||||||
&refs->packed_refs_lock, files_packed_refs_path(refs),
|
&refs->packed_refs_lock, files_packed_refs_path(refs),
|
||||||
flags, timeout_value) < 0)
|
flags, timeout_value) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the current packed-refs while holding the lock. It is
|
* Now that we hold the `packed-refs` lock, make sure that our
|
||||||
* important that we call `get_packed_ref_cache()` before
|
* cache matches the current version of the file. Normally
|
||||||
* setting `packed_ref_cache->lock`, because otherwise the
|
* `get_packed_ref_cache()` does that for us, but that
|
||||||
* former will see that the file is locked and assume that the
|
* function assumes that when the file is locked, any existing
|
||||||
* cache can't be stale.
|
* cache is still valid. We've just locked the file, but it
|
||||||
|
* might have changed the moment *before* we locked it.
|
||||||
*/
|
*/
|
||||||
|
validate_packed_ref_cache(refs);
|
||||||
|
|
||||||
packed_ref_cache = get_packed_ref_cache(refs);
|
packed_ref_cache = get_packed_ref_cache(refs);
|
||||||
/* Increment the reference count to prevent it from being freed: */
|
/* Increment the reference count to prevent it from being freed: */
|
||||||
acquire_packed_ref_cache(packed_ref_cache);
|
acquire_packed_ref_cache(packed_ref_cache);
|
||||||
|
@ -2075,7 +2075,7 @@ static int for_each_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_d
|
|||||||
struct strbuf bisect_refs = STRBUF_INIT;
|
struct strbuf bisect_refs = STRBUF_INIT;
|
||||||
int status;
|
int status;
|
||||||
strbuf_addf(&bisect_refs, "refs/bisect/%s", term);
|
strbuf_addf(&bisect_refs, "refs/bisect/%s", term);
|
||||||
status = for_each_ref_in_submodule(submodule, bisect_refs.buf, fn, cb_data);
|
status = for_each_fullref_in_submodule(submodule, bisect_refs.buf, fn, cb_data, 0);
|
||||||
strbuf_release(&bisect_refs);
|
strbuf_release(&bisect_refs);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -235,4 +235,18 @@ test_sequence "--bisect"
|
|||||||
|
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
|
test_expect_success '--bisect can default to good/bad refs' '
|
||||||
|
git update-ref refs/bisect/bad c3 &&
|
||||||
|
good=$(git rev-parse b1) &&
|
||||||
|
git update-ref refs/bisect/good-$good $good &&
|
||||||
|
good=$(git rev-parse c1) &&
|
||||||
|
git update-ref refs/bisect/good-$good $good &&
|
||||||
|
|
||||||
|
# the only thing between c3 and c1 is c2
|
||||||
|
git rev-parse c2 >expect &&
|
||||||
|
git rev-list --bisect >actual &&
|
||||||
|
test_cmp expect actual
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user