Skip to content

Commit 9939b33

Browse files
mhaggergitster
authored andcommitted
packed-backend: rip out some now-unused code
Now the outside world interacts with the packed ref store only via the generic refs API plus a few lock-related functions. This allows us to delete some functions that are no longer used, thereby completing the encapsulation of the packed ref store. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dc39e09 commit 9939b33

File tree

2 files changed

+0
-201
lines changed

2 files changed

+0
-201
lines changed

refs/packed-backend.c

Lines changed: 0 additions & 193 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,6 @@ struct ref_store *packed_ref_store_create(const char *path,
9191
return ref_store;
9292
}
9393

94-
/*
95-
* Die if refs is not the main ref store. caller is used in any
96-
* necessary error messages.
97-
*/
98-
static void packed_assert_main_repository(struct packed_ref_store *refs,
99-
const char *caller)
100-
{
101-
if (refs->store_flags & REF_STORE_MAIN)
102-
return;
103-
104-
die("BUG: operation %s only allowed for main ref store", caller);
105-
}
106-
10794
/*
10895
* Downcast `ref_store` to `packed_ref_store`. Die if `ref_store` is
10996
* not a `packed_ref_store`. Also die if `packed_ref_store` doesn't
@@ -321,40 +308,6 @@ static struct ref_dir *get_packed_refs(struct packed_ref_store *refs)
321308
return get_packed_ref_dir(get_packed_ref_cache(refs));
322309
}
323310

324-
/*
325-
* Add or overwrite a reference in the in-memory packed reference
326-
* cache. This may only be called while the packed-refs file is locked
327-
* (see packed_refs_lock()). To actually write the packed-refs file,
328-
* call commit_packed_refs().
329-
*/
330-
void add_packed_ref(struct ref_store *ref_store,
331-
const char *refname, const struct object_id *oid)
332-
{
333-
struct packed_ref_store *refs =
334-
packed_downcast(ref_store, REF_STORE_WRITE,
335-
"add_packed_ref");
336-
struct ref_dir *packed_refs;
337-
struct ref_entry *packed_entry;
338-
339-
if (!is_lock_file_locked(&refs->lock))
340-
die("BUG: packed refs not locked");
341-
342-
if (check_refname_format(refname, REFNAME_ALLOW_ONELEVEL))
343-
die("Reference has invalid format: '%s'", refname);
344-
345-
packed_refs = get_packed_refs(refs);
346-
packed_entry = find_ref_entry(packed_refs, refname);
347-
if (packed_entry) {
348-
/* Overwrite the existing entry: */
349-
oidcpy(&packed_entry->u.value.oid, oid);
350-
packed_entry->flag = REF_ISPACKED;
351-
oidclr(&packed_entry->u.value.peeled);
352-
} else {
353-
packed_entry = create_ref_entry(refname, oid, REF_ISPACKED);
354-
add_ref_entry(packed_refs, packed_entry);
355-
}
356-
}
357-
358311
/*
359312
* Return the ref_entry for the given refname from the packed
360313
* references. If it does not exist, return NULL.
@@ -596,152 +549,6 @@ int packed_refs_is_locked(struct ref_store *ref_store)
596549
static const char PACKED_REFS_HEADER[] =
597550
"# pack-refs with: peeled fully-peeled \n";
598551

599-
/*
600-
* Write the current version of the packed refs cache from memory to
601-
* disk. The packed-refs file must already be locked for writing (see
602-
* packed_refs_lock()). Return zero on success. On errors, rollback
603-
* the lockfile, write an error message to `err`, and return a nonzero
604-
* value.
605-
*/
606-
int commit_packed_refs(struct ref_store *ref_store, struct strbuf *err)
607-
{
608-
struct packed_ref_store *refs =
609-
packed_downcast(ref_store, REF_STORE_WRITE | REF_STORE_MAIN,
610-
"commit_packed_refs");
611-
struct packed_ref_cache *packed_ref_cache =
612-
get_packed_ref_cache(refs);
613-
int ok;
614-
int ret = -1;
615-
struct strbuf sb = STRBUF_INIT;
616-
FILE *out;
617-
struct ref_iterator *iter;
618-
char *packed_refs_path;
619-
620-
if (!is_lock_file_locked(&refs->lock))
621-
die("BUG: commit_packed_refs() called when unlocked");
622-
623-
/*
624-
* If packed-refs is a symlink, we want to overwrite the
625-
* symlinked-to file, not the symlink itself. Also, put the
626-
* staging file next to it:
627-
*/
628-
packed_refs_path = get_locked_file_path(&refs->lock);
629-
strbuf_addf(&sb, "%s.new", packed_refs_path);
630-
if (create_tempfile(&refs->tempfile, sb.buf) < 0) {
631-
strbuf_addf(err, "unable to create file %s: %s",
632-
sb.buf, strerror(errno));
633-
strbuf_release(&sb);
634-
goto out;
635-
}
636-
strbuf_release(&sb);
637-
638-
out = fdopen_tempfile(&refs->tempfile, "w");
639-
if (!out) {
640-
strbuf_addf(err, "unable to fdopen packed-refs tempfile: %s",
641-
strerror(errno));
642-
goto error;
643-
}
644-
645-
if (fprintf(out, "%s", PACKED_REFS_HEADER) < 0) {
646-
strbuf_addf(err, "error writing to %s: %s",
647-
get_tempfile_path(&refs->tempfile), strerror(errno));
648-
goto error;
649-
}
650-
651-
iter = cache_ref_iterator_begin(packed_ref_cache->cache, NULL, 0);
652-
while ((ok = ref_iterator_advance(iter)) == ITER_OK) {
653-
struct object_id peeled;
654-
int peel_error = ref_iterator_peel(iter, &peeled);
655-
656-
if (write_packed_entry(out, iter->refname, iter->oid->hash,
657-
peel_error ? NULL : peeled.hash)) {
658-
strbuf_addf(err, "error writing to %s: %s",
659-
get_tempfile_path(&refs->tempfile),
660-
strerror(errno));
661-
ref_iterator_abort(iter);
662-
goto error;
663-
}
664-
}
665-
666-
if (ok != ITER_DONE) {
667-
strbuf_addf(err, "unable to rewrite packed-refs file: "
668-
"error iterating over old contents");
669-
goto error;
670-
}
671-
672-
if (rename_tempfile(&refs->tempfile, packed_refs_path)) {
673-
strbuf_addf(err, "error replacing %s: %s",
674-
refs->path, strerror(errno));
675-
goto out;
676-
}
677-
678-
ret = 0;
679-
goto out;
680-
681-
error:
682-
delete_tempfile(&refs->tempfile);
683-
684-
out:
685-
free(packed_refs_path);
686-
return ret;
687-
}
688-
689-
/*
690-
* Rewrite the packed-refs file, omitting any refs listed in
691-
* 'refnames'. On error, leave packed-refs unchanged, write an error
692-
* message to 'err', and return a nonzero value. The packed refs lock
693-
* must be held when calling this function; it will still be held when
694-
* the function returns.
695-
*
696-
* The refs in 'refnames' needn't be sorted. `err` must not be NULL.
697-
*/
698-
int repack_without_refs(struct ref_store *ref_store,
699-
struct string_list *refnames, struct strbuf *err)
700-
{
701-
struct packed_ref_store *refs =
702-
packed_downcast(ref_store, REF_STORE_WRITE | REF_STORE_MAIN,
703-
"repack_without_refs");
704-
struct ref_dir *packed;
705-
struct string_list_item *refname;
706-
int needs_repacking = 0, removed = 0;
707-
708-
packed_assert_main_repository(refs, "repack_without_refs");
709-
assert(err);
710-
711-
if (!is_lock_file_locked(&refs->lock))
712-
die("BUG: repack_without_refs called without holding lock");
713-
714-
/* Look for a packed ref */
715-
for_each_string_list_item(refname, refnames) {
716-
if (get_packed_ref(refs, refname->string)) {
717-
needs_repacking = 1;
718-
break;
719-
}
720-
}
721-
722-
/* Avoid locking if we have nothing to do */
723-
if (!needs_repacking)
724-
return 0; /* no refname exists in packed refs */
725-
726-
packed = get_packed_refs(refs);
727-
728-
/* Remove refnames from the cache */
729-
for_each_string_list_item(refname, refnames)
730-
if (remove_entry_from_dir(packed, refname->string) != -1)
731-
removed = 1;
732-
if (!removed) {
733-
/*
734-
* All packed entries disappeared while we were
735-
* acquiring the lock.
736-
*/
737-
clear_packed_ref_cache(refs);
738-
return 0;
739-
}
740-
741-
/* Write what remains */
742-
return commit_packed_refs(&refs->base, err);
743-
}
744-
745552
static int packed_init_db(struct ref_store *ref_store, struct strbuf *err)
746553
{
747554
/* Nothing to do. */

refs/packed-backend.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,4 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)
2323
void packed_refs_unlock(struct ref_store *ref_store);
2424
int packed_refs_is_locked(struct ref_store *ref_store);
2525

26-
void add_packed_ref(struct ref_store *ref_store,
27-
const char *refname, const struct object_id *oid);
28-
29-
int commit_packed_refs(struct ref_store *ref_store, struct strbuf *err);
30-
31-
int repack_without_refs(struct ref_store *ref_store,
32-
struct string_list *refnames, struct strbuf *err);
33-
3426
#endif /* REFS_PACKED_BACKEND_H */

0 commit comments

Comments
 (0)