Skip to content

Commit 61cee0d

Browse files
bradkinggitster
authored andcommitted
refs: add function to repack without multiple refs
Generalize repack_without_ref as repack_without_refs to support a list of refs and implement the former in terms of the latter. Signed-off-by: Brad King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2ddb5d1 commit 61cee0d

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

refs.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,42 +2414,57 @@ static int curate_packed_ref_fn(struct ref_entry *entry, void *cb_data)
24142414
return 0;
24152415
}
24162416

2417-
static int repack_without_ref(const char *refname)
2417+
static int repack_without_refs(const char **refnames, int n)
24182418
{
24192419
struct ref_dir *packed;
24202420
struct string_list refs_to_delete = STRING_LIST_INIT_DUP;
24212421
struct string_list_item *ref_to_delete;
2422+
int i, removed = 0;
2423+
2424+
/* Look for a packed ref */
2425+
for (i = 0; i < n; i++)
2426+
if (get_packed_ref(refnames[i]))
2427+
break;
24222428

2423-
if (!get_packed_ref(refname))
2424-
return 0; /* refname does not exist in packed refs */
2429+
/* Avoid locking if we have nothing to do */
2430+
if (i == n)
2431+
return 0; /* no refname exists in packed refs */
24252432

24262433
if (lock_packed_refs(0)) {
24272434
unable_to_lock_error(git_path("packed-refs"), errno);
2428-
return error("cannot delete '%s' from packed refs", refname);
2435+
return error("cannot delete '%s' from packed refs", refnames[i]);
24292436
}
24302437
packed = get_packed_refs(&ref_cache);
24312438

2432-
/* Remove refname from the cache: */
2433-
if (remove_entry(packed, refname) == -1) {
2439+
/* Remove refnames from the cache */
2440+
for (i = 0; i < n; i++)
2441+
if (remove_entry(packed, refnames[i]) != -1)
2442+
removed = 1;
2443+
if (!removed) {
24342444
/*
2435-
* The packed entry disappeared while we were
2445+
* All packed entries disappeared while we were
24362446
* acquiring the lock.
24372447
*/
24382448
rollback_packed_refs();
24392449
return 0;
24402450
}
24412451

2442-
/* Remove any other accumulated cruft: */
2452+
/* Remove any other accumulated cruft */
24432453
do_for_each_entry_in_dir(packed, 0, curate_packed_ref_fn, &refs_to_delete);
24442454
for_each_string_list_item(ref_to_delete, &refs_to_delete) {
24452455
if (remove_entry(packed, ref_to_delete->string) == -1)
24462456
die("internal error");
24472457
}
24482458

2449-
/* Write what remains: */
2459+
/* Write what remains */
24502460
return commit_packed_refs();
24512461
}
24522462

2463+
static int repack_without_ref(const char *refname)
2464+
{
2465+
return repack_without_refs(&refname, 1);
2466+
}
2467+
24532468
static int delete_ref_loose(struct ref_lock *lock, int flag)
24542469
{
24552470
if (!(flag & REF_ISPACKED) || flag & REF_ISSYMREF) {

0 commit comments

Comments
 (0)