]> git.ipfire.org Git - thirdparty/git.git/commitdiff
pack-write: split up finish_tmp_packfile() function
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Thu, 9 Sep 2021 23:24:56 +0000 (19:24 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Sep 2021 01:23:11 +0000 (18:23 -0700)
Split up the finish_tmp_packfile() function and use the split-up version
in pack-objects.c in preparation for moving the step of renaming the
*.idx file later as part of a function change.

Since the only other caller of finish_tmp_packfile() was in
bulk-checkin.c, and it won't be needing a change to its *.idx renaming,
provide a thin wrapper for the old function as a static function in that
file. If other callers end up needing the simpler version it could be
moved back to "pack-write.c" and "pack.h".

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/pack-objects.c
bulk-checkin.c
pack-write.c
pack.h

index d42de63fda407ef4714dee8bc7eeea0e7a857ddf..0a46584922ac687fd5d75e4bdc601892c19dac6f 100644 (file)
@@ -1217,6 +1217,7 @@ static void write_pack_file(void)
                if (!pack_to_stdout) {
                        struct stat st;
                        struct strbuf tmpname = STRBUF_INIT;
+                       char *idx_tmp_name = NULL;
 
                        /*
                         * Packs are runtime accessed in their mtime
@@ -1246,9 +1247,10 @@ static void write_pack_file(void)
                                        &to_pack, written_list, nr_written);
                        }
 
-                       finish_tmp_packfile(&tmpname, pack_tmp_name,
+                       stage_tmp_packfiles(&tmpname, pack_tmp_name,
                                            written_list, nr_written,
-                                           &pack_idx_opts, hash);
+                                           &pack_idx_opts, hash, &idx_tmp_name);
+                       rename_tmp_packfile_idx(&tmpname, &idx_tmp_name);
 
                        if (write_bitmap_index) {
                                size_t tmpname_len = tmpname.len;
@@ -1265,6 +1267,7 @@ static void write_pack_file(void)
                                strbuf_setlen(&tmpname, tmpname_len);
                        }
 
+                       free(idx_tmp_name);
                        strbuf_release(&tmpname);
                        free(pack_tmp_name);
                        puts(hash_to_hex(hash));
index c19d471f0bde9839466456fb375ad4ca0c88d0c2..8785b2ac80699255ae8abd0801922ba025235309 100644 (file)
@@ -23,6 +23,22 @@ static struct bulk_checkin_state {
        uint32_t nr_written;
 } state;
 
+static void finish_tmp_packfile(struct strbuf *basename,
+                               const char *pack_tmp_name,
+                               struct pack_idx_entry **written_list,
+                               uint32_t nr_written,
+                               struct pack_idx_option *pack_idx_opts,
+                               unsigned char hash[])
+{
+       char *idx_tmp_name = NULL;
+
+       stage_tmp_packfiles(basename, pack_tmp_name, written_list, nr_written,
+                           pack_idx_opts, hash, &idx_tmp_name);
+       rename_tmp_packfile_idx(basename, &idx_tmp_name);
+
+       free(idx_tmp_name);
+}
+
 static void finish_bulk_checkin(struct bulk_checkin_state *state)
 {
        unsigned char hash[GIT_MAX_RAWSZ];
index 51157916f516d9ac4cea4ba75365f54ad39d011e..32ebf0cdf76ab37b1f16043744ba0768cfb74b1c 100644 (file)
@@ -474,21 +474,28 @@ static void rename_tmp_packfile(struct strbuf *name_prefix, const char *source,
        strbuf_setlen(name_prefix, name_prefix_len);
 }
 
-void finish_tmp_packfile(struct strbuf *name_buffer,
+void rename_tmp_packfile_idx(struct strbuf *name_buffer,
+                            char **idx_tmp_name)
+{
+       rename_tmp_packfile(name_buffer, *idx_tmp_name, "idx");
+}
+
+void stage_tmp_packfiles(struct strbuf *name_buffer,
                         const char *pack_tmp_name,
                         struct pack_idx_entry **written_list,
                         uint32_t nr_written,
                         struct pack_idx_option *pack_idx_opts,
-                        unsigned char hash[])
+                        unsigned char hash[],
+                        char **idx_tmp_name)
 {
-       const char *idx_tmp_name, *rev_tmp_name = NULL;
+       const char *rev_tmp_name = NULL;
 
        if (adjust_shared_perm(pack_tmp_name))
                die_errno("unable to make temporary pack file readable");
 
-       idx_tmp_name = write_idx_file(NULL, written_list, nr_written,
-                                     pack_idx_opts, hash);
-       if (adjust_shared_perm(idx_tmp_name))
+       *idx_tmp_name = (char *)write_idx_file(NULL, written_list, nr_written,
+                                              pack_idx_opts, hash);
+       if (adjust_shared_perm(*idx_tmp_name))
                die_errno("unable to make temporary index file readable");
 
        rev_tmp_name = write_rev_file(NULL, written_list, nr_written, hash,
@@ -497,9 +504,6 @@ void finish_tmp_packfile(struct strbuf *name_buffer,
        rename_tmp_packfile(name_buffer, pack_tmp_name, "pack");
        if (rev_tmp_name)
                rename_tmp_packfile(name_buffer, rev_tmp_name, "rev");
-       rename_tmp_packfile(name_buffer, idx_tmp_name, "idx");
-
-       free((void *)idx_tmp_name);
 }
 
 void write_promisor_file(const char *promisor_name, struct ref **sought, int nr_sought)
diff --git a/pack.h b/pack.h
index 1c17254c0a4c1d11981e5c3c3e562580bac57ce5..b22bfc4a18e8543be54d6328c4e3cae6270c0aa7 100644 (file)
--- a/pack.h
+++ b/pack.h
@@ -110,11 +110,14 @@ int encode_in_pack_object_header(unsigned char *hdr, int hdr_len,
 int read_pack_header(int fd, struct pack_header *);
 
 struct hashfile *create_tmp_packfile(char **pack_tmp_name);
-void finish_tmp_packfile(struct strbuf *name_buffer,
+void stage_tmp_packfiles(struct strbuf *name_buffer,
                         const char *pack_tmp_name,
                         struct pack_idx_entry **written_list,
                         uint32_t nr_written,
                         struct pack_idx_option *pack_idx_opts,
-                        unsigned char sha1[]);
+                        unsigned char hash[],
+                        char **idx_tmp_name);
+void rename_tmp_packfile_idx(struct strbuf *basename,
+                            char **idx_tmp_name);
 
 #endif