appp.sh: use the $( ... ) construct for command substitution
[gitweb.git] / builtin / pack-objects.c
index 8b89f8121ad0225117f7864e7b552d6e02f5ac45..0ee5f1ff94e1689b099f04fff8a05728c70f2f4f 100644 (file)
@@ -803,7 +803,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
@@ -823,26 +823,22 @@ static void write_pack_file(void)
                                utb.modtime = --last_mtime;
                                if (utime(pack_tmp_name, &utb) < 0)
                                        warning("failed utime() on %s: %s",
-                                               tmpname, strerror(errno));
+                                               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);
 
@@ -851,10 +847,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));
                }
@@ -1213,12 +1210,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,
@@ -2455,6 +2449,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')
@@ -2467,6 +2464,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))
@@ -2612,7 +2616,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
                OPT_END(),
        };
 
-       read_replace_refs = 0;
+       check_replace_refs = 0;
 
        reset_pack_idx_option(&pack_idx_opts);
        git_config(git_pack_config, NULL);