merge-file: clamp exit code to maximum 127
[gitweb.git] / builtin / pack-objects.c
index 021ec7ad794f6f2537bd6f02a029f771a3d3b7fd..de36c60ca11d248013c2de42d196f1aff8a2937b 100644 (file)
@@ -816,7 +816,7 @@ static void write_pack_file(void)
 
                if (!pack_to_stdout) {
                        struct stat st;
-                       char tmpname[PATH_MAX];
+                       struct strbuf tmpname = STRBUF_INIT;
 
                        /*
                         * Packs are runtime accessed in their mtime
@@ -839,23 +839,19 @@ static void write_pack_file(void)
                                                pack_tmp_name, strerror(errno));
                        }
 
-                       /* Enough space for "-<sha-1>.pack"? */
-                       if (sizeof(tmpname) <= strlen(base_name) + 50)
-                               die("pack base name '%s' too long", base_name);
-                       snprintf(tmpname, sizeof(tmpname), "%s-", base_name);
+                       strbuf_addf(&tmpname, "%s-", base_name);
 
                        if (write_bitmap_index) {
                                bitmap_writer_set_checksum(sha1);
                                bitmap_writer_build_type_index(written_list, nr_written);
                        }
 
-                       finish_tmp_packfile(tmpname, pack_tmp_name,
+                       finish_tmp_packfile(&tmpname, pack_tmp_name,
                                            written_list, nr_written,
                                            &pack_idx_opts, sha1);
 
                        if (write_bitmap_index) {
-                               char *end_of_name_prefix = strrchr(tmpname, 0);
-                               sprintf(end_of_name_prefix, "%s.bitmap", sha1_to_hex(sha1));
+                               strbuf_addf(&tmpname, "%s.bitmap", sha1_to_hex(sha1));
 
                                stop_progress(&progress_state);
 
@@ -864,10 +860,11 @@ static void write_pack_file(void)
                                bitmap_writer_select_commits(indexed_commits, indexed_commits_nr, -1);
                                bitmap_writer_build(&to_pack);
                                bitmap_writer_finish(written_list, nr_written,
-                                                    tmpname, write_bitmap_options);
+                                                    tmpname.buf, write_bitmap_options);
                                write_bitmap_index = 0;
                        }
 
+                       strbuf_release(&tmpname);
                        free(pack_tmp_name);
                        puts(sha1_to_hex(sha1));
                }
@@ -1011,6 +1008,10 @@ static void create_object_entry(const unsigned char *sha1,
        entry->no_try_delta = no_try_delta;
 }
 
+static const char no_closure_warning[] = N_(
+"disabling bitmap writing, as some objects are not being packed"
+);
+
 static int add_object_entry(const unsigned char *sha1, enum object_type type,
                            const char *name, int exclude)
 {
@@ -1021,8 +1022,14 @@ static int add_object_entry(const unsigned char *sha1, enum object_type type,
        if (have_duplicate_entry(sha1, exclude, &index_pos))
                return 0;
 
-       if (!want_object_in_pack(sha1, exclude, &found_pack, &found_offset))
+       if (!want_object_in_pack(sha1, exclude, &found_pack, &found_offset)) {
+               /* The pack is missing an object, so it will not have closure */
+               if (write_bitmap_index) {
+                       warning(_(no_closure_warning));
+                       write_bitmap_index = 0;
+               }
                return 0;
+       }
 
        create_object_entry(sha1, type, pack_name_hash(name),
                            exclude, name && no_try_delta(name),
@@ -1069,7 +1076,7 @@ static int pbase_tree_cache_ix_incr(int ix)
 static struct pbase_tree {
        struct pbase_tree *next;
        /* This is a phony "cache" entry; we are not
-        * going to evict it nor find it through _get()
+        * going to evict it or find it through _get()
         * mechanism -- this is for the toplevel node that
         * would almost always change with any commit.
         */
@@ -1226,12 +1233,9 @@ static int check_pbase_path(unsigned hash)
        if (0 <= pos)
                return 1;
        pos = -pos - 1;
-       if (done_pbase_paths_alloc <= done_pbase_paths_num) {
-               done_pbase_paths_alloc = alloc_nr(done_pbase_paths_alloc);
-               done_pbase_paths = xrealloc(done_pbase_paths,
-                                           done_pbase_paths_alloc *
-                                           sizeof(unsigned));
-       }
+       ALLOC_GROW(done_pbase_paths,
+                  done_pbase_paths_num + 1,
+                  done_pbase_paths_alloc);
        done_pbase_paths_num++;
        if (pos < done_pbase_paths_num)
                memmove(done_pbase_paths + pos + 1,
@@ -2435,12 +2439,23 @@ static void loosen_unused_packed_objects(struct rev_info *revs)
        }
 }
 
+/*
+ * This tracks any options which a reader of the pack might
+ * not understand, and which would therefore prevent blind reuse
+ * of what we have on disk.
+ */
+static int pack_options_allow_reuse(void)
+{
+       return allow_ofs_delta;
+}
+
 static int get_object_list_from_bitmap(struct rev_info *revs)
 {
        if (prepare_bitmap_walk(revs) < 0)
                return -1;
 
-       if (!reuse_partial_packfile_from_bitmap(
+       if (pack_options_allow_reuse() &&
+           !reuse_partial_packfile_from_bitmap(
                        &reuse_packfile,
                        &reuse_packfile_objects,
                        &reuse_packfile_offset)) {
@@ -2463,6 +2478,9 @@ static void get_object_list(int ac, const char **av)
        save_commit_buffer = 0;
        setup_revisions(ac, av, &revs, NULL);
 
+       /* make sure shallows are read */
+       is_repository_shallow();
+
        while (fgets(line, sizeof(line), stdin) != NULL) {
                int len = strlen(line);
                if (len && line[len - 1] == '\n')
@@ -2475,6 +2493,13 @@ static void get_object_list(int ac, const char **av)
                                write_bitmap_index = 0;
                                continue;
                        }
+                       if (starts_with(line, "--shallow ")) {
+                               unsigned char sha1[20];
+                               if (get_sha1_hex(line + 10, sha1))
+                                       die("not an SHA-1 '%s'", line + 10);
+                               register_shallow(sha1);
+                               continue;
+                       }
                        die("not a rev '%s'", line);
                }
                if (handle_revision_arg(line, &revs, flags, REVARG_CANNOT_BE_FILENAME))