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 <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Sep 8, 2017 at 15:51 UTC
9939b33d6a3900e76b9cf95cbbb30ad8cf38cab3
2 files changed
-201
refs/packed-backend.c
-193
@@ -91,19 +91,6 @@ struct ref_store *packed_ref_store_create(const char *path,
91
return ref_store;
92
}
93
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
-
94
/*
95
* Downcast `ref_store` to `packed_ref_store`. Die if `ref_store` is
96
* 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)
308
return get_packed_ref_dir(get_packed_ref_cache(refs));
309
}
310
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
-
311
/*
312
* Return the ref_entry for the given refname from the packed
313
* references. If it does not exist, return NULL.
@@ -596,152 +549,6 @@ int packed_refs_is_locked(struct ref_store *ref_store)
549
static const char PACKED_REFS_HEADER[] =
550
"# pack-refs with: peeled fully-peeled \n";
551
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
-
552
static int packed_init_db(struct ref_store *ref_store, struct strbuf *err)
553
{
554
/* Nothing to do. */
refs/packed-backend.h
-8
@@ -23,12 +23,4 @@ int packed_refs_lock(struct ref_store *ref_store, int flags, struct strbuf *err)
23
void packed_refs_unlock(struct ref_store *ref_store);
24
int packed_refs_is_locked(struct ref_store *ref_store);
25
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
-
26
#endif /* REFS_PACKED_BACKEND_H */