Merge branch 'ds/midx-expire-repack'
authorJunio C Hamano <gitster@pobox.com>
Fri, 19 Jul 2019 18:30:19 +0000 (11:30 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 19 Jul 2019 18:30:19 +0000 (11:30 -0700)
"git multi-pack-index" learned expire and repack subcommands.

* ds/midx-expire-repack:
t5319: use 'test-tool path-utils' instead of 'ls -l'
t5319-multi-pack-index.sh: test batch size zero
midx: add test that 'expire' respects .keep files
multi-pack-index: test expire while adding packs
midx: implement midx_repack()
multi-pack-index: prepare 'repack' subcommand
multi-pack-index: implement 'expire' subcommand
midx: refactor permutation logic and pack sorting
midx: simplify computation of pack name lengths
multi-pack-index: prepare for 'expire' subcommand
Docs: rearrange subcommands for multi-pack-index
repack: refactor pack deletion for future use

1  2 
builtin/repack.c
packfile.c
packfile.h
diff --combined builtin/repack.c
index f834b5551b1ffe003b943c18cd35397e9196e730,3ea0583d0244ba98faf158fdc7ed22c006519d2b..d6abf74608fe1a84f6ad425c16798bfad81f69c3
@@@ -129,19 -129,9 +129,9 @@@ static void get_non_kept_pack_filenames
  
  static void remove_redundant_pack(const char *dir_name, const char *base_name)
  {
-       const char *exts[] = {".pack", ".idx", ".keep", ".bitmap", ".promisor"};
-       int i;
        struct strbuf buf = STRBUF_INIT;
-       size_t plen;
-       strbuf_addf(&buf, "%s/%s", dir_name, base_name);
-       plen = buf.len;
-       for (i = 0; i < ARRAY_SIZE(exts); i++) {
-               strbuf_setlen(&buf, plen);
-               strbuf_addstr(&buf, exts[i]);
-               unlink(buf.buf);
-       }
+       strbuf_addf(&buf, "%s/%s.pack", dir_name, base_name);
+       unlink_pack_path(buf.buf, 1);
        strbuf_release(&buf);
  }
  
@@@ -422,7 -412,7 +412,7 @@@ int cmd_repack(int argc, const char **a
        if (!names.nr && !po_args.quiet)
                printf_ln(_("Nothing new to pack."));
  
 -      close_all_packs(the_repository->objects);
 +      close_object_store(the_repository->objects);
  
        /*
         * Ok we have prepared all new packfiles.
diff --combined packfile.c
index c0d83fdfed973de8574224e46fb0afd4be0a98c9,020e61a3b6b470a71536d9fefa1f2ba1294a4b17..fc43a6c52c75a32548c20bbc4a5aa7d0cc3ddd0d
@@@ -16,7 -16,6 +16,7 @@@
  #include "tree.h"
  #include "object-store.h"
  #include "midx.h"
 +#include "commit-graph.h"
  
  char *odb_pack_name(struct strbuf *buf,
                    const unsigned char *sha1,
@@@ -337,7 -336,7 +337,7 @@@ void close_pack(struct packed_git *p
        close_pack_index(p);
  }
  
 -void close_all_packs(struct raw_object_store *o)
 +void close_object_store(struct raw_object_store *o)
  {
        struct packed_git *p;
  
                close_midx(o->multi_pack_index);
                o->multi_pack_index = NULL;
        }
 +
 +      close_commit_graph(o);
  }
  
+ void unlink_pack_path(const char *pack_name, int force_delete)
+ {
+       static const char *exts[] = {".pack", ".idx", ".keep", ".bitmap", ".promisor"};
+       int i;
+       struct strbuf buf = STRBUF_INIT;
+       size_t plen;
+       strbuf_addstr(&buf, pack_name);
+       strip_suffix_mem(buf.buf, &buf.len, ".pack");
+       plen = buf.len;
+       if (!force_delete) {
+               strbuf_addstr(&buf, ".keep");
+               if (!access(buf.buf, F_OK)) {
+                       strbuf_release(&buf);
+                       return;
+               }
+       }
+       for (i = 0; i < ARRAY_SIZE(exts); i++) {
+               strbuf_setlen(&buf, plen);
+               strbuf_addstr(&buf, exts[i]);
+               unlink(buf.buf);
+       }
+       strbuf_release(&buf);
+ }
  /*
   * The LRU pack is the one with the oldest MRU window, preferring packs
   * with no used windows, or the oldest mtime if it has no windows allocated.
@@@ -643,7 -668,7 +671,7 @@@ unsigned char *use_pack(struct packed_g
                        while (packed_git_limit < pack_mapped
                                && unuse_one_window(p))
                                ; /* nothing */
 -                      win->base = xmmap(NULL, win->len,
 +                      win->base = xmmap_gently(NULL, win->len,
                                PROT_READ, MAP_PRIVATE,
                                p->pack_fd, win->offset);
                        if (win->base == MAP_FAILED)
@@@ -1272,7 -1297,7 +1300,7 @@@ static enum object_type packed_to_objec
                if (poi_stack_nr >= poi_stack_alloc && poi_stack == small_poi_stack) {
                        poi_stack_alloc = alloc_nr(poi_stack_nr);
                        ALLOC_ARRAY(poi_stack, poi_stack_alloc);
 -                      memcpy(poi_stack, small_poi_stack, sizeof(off_t)*poi_stack_nr);
 +                      COPY_ARRAY(poi_stack, small_poi_stack, poi_stack_nr);
                } else {
                        ALLOC_GROW(poi_stack, poi_stack_nr+1, poi_stack_alloc);
                }
@@@ -1682,8 -1707,8 +1710,8 @@@ void *unpack_entry(struct repository *r
                    && delta_stack == small_delta_stack) {
                        delta_stack_alloc = alloc_nr(delta_stack_nr);
                        ALLOC_ARRAY(delta_stack, delta_stack_alloc);
 -                      memcpy(delta_stack, small_delta_stack,
 -                             sizeof(*delta_stack)*delta_stack_nr);
 +                      COPY_ARRAY(delta_stack, small_delta_stack,
 +                                 delta_stack_nr);
                } else {
                        ALLOC_GROW(delta_stack, delta_stack_nr+1, delta_stack_alloc);
                }
diff --combined packfile.h
index 81e868d55a9b1f1aeaafa4925a72ae5c53af86e9,3c436c124f2801caa42584be6eb82c24e1f22278..3e98910bdd191f45d3dd86ff0360f40060944705
@@@ -90,11 -90,18 +90,18 @@@ uint32_t get_pack_fanout(struct packed_
  unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
  void close_pack_windows(struct packed_git *);
  void close_pack(struct packed_git *);
 -void close_all_packs(struct raw_object_store *o);
 +void close_object_store(struct raw_object_store *o);
  void unuse_pack(struct pack_window **);
  void clear_delta_base_cache(void);
  struct packed_git *add_packed_git(const char *path, size_t path_len, int local);
  
+ /*
+  * Unlink the .pack and associated extension files.
+  * Does not unlink if 'force_delete' is false and the pack-file is
+  * marked as ".keep".
+  */
+ extern void unlink_pack_path(const char *pack_name, int force_delete);
  /*
   * Make sure that a pointer access into an mmap'd index file is within bounds,
   * and can provide at least 8 bytes of data.