Documentation: clearly specify what refs are honored by core.logAllRefUpdates
[gitweb.git] / builtin-pack-objects.c
index 3186035fb4ee0b3e1ccc1052e98c6108cdeeeeb1..e1d3adf405bb6ac842a3415e0461b4772396060d 100644 (file)
@@ -77,7 +77,7 @@ static int allow_ofs_delta;
 static const char *base_name;
 static int progress = 1;
 static int window = 10;
-static uint32_t pack_size_limit, pack_size_limit_cfg;
+static unsigned long pack_size_limit, pack_size_limit_cfg;
 static int depth = 50;
 static int delta_search_threads;
 static int pack_to_stdout;
@@ -445,13 +445,9 @@ static int write_one(struct sha1file *f,
        if (e->idx.offset || e->preferred_base)
                return -1;
 
-       /*
-        * If we are deltified, attempt to write out base object first.
-        * If that fails due to the pack size limit then the current
-        * object might still possibly fit undeltified within that limit.
-        */
-       if (e->delta)
-              write_one(f, e->delta, offset);
+       /* if we are deltified, write out base object first. */
+       if (e->delta && !write_one(f, e->delta, offset))
+               return 0;
 
        e->idx.offset = *offset;
        size = write_object(f, e, *offset);
@@ -505,9 +501,11 @@ static void write_pack_file(void)
                sha1write(f, &hdr, sizeof(hdr));
                offset = sizeof(hdr);
                nr_written = 0;
-               for (i = 0; i < nr_objects; i++)
-                       if (write_one(f, objects + i, &offset) == 1)
-                               display_progress(progress_state, written);
+               for (; i < nr_objects; i++) {
+                       if (!write_one(f, objects + i, &offset))
+                               break;
+                       display_progress(progress_state, written);
+               }
 
                /*
                 * Did we write the wrong # entries in the header?
@@ -582,7 +580,7 @@ static void write_pack_file(void)
                        written_list[j]->offset = (off_t)-1;
                }
                nr_remaining -= nr_written;
-       } while (nr_remaining);
+       } while (nr_remaining && i < nr_objects);
 
        free(written_list);
        stop_progress(&progress_state);
@@ -2192,10 +2190,8 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
                        continue;
                }
                if (!prefixcmp(arg, "--max-pack-size=")) {
-                       char *end;
                        pack_size_limit_cfg = 0;
-                       pack_size_limit = strtoul(arg+16, &end, 0) * 1024 * 1024;
-                       if (!arg[16] || *end)
+                       if (!git_parse_ulong(arg+16, &pack_size_limit))
                                usage(pack_usage);
                        continue;
                }
@@ -2335,9 +2331,12 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 
        if (!pack_to_stdout && !pack_size_limit)
                pack_size_limit = pack_size_limit_cfg;
-
        if (pack_to_stdout && pack_size_limit)
                die("--max-pack-size cannot be used to build a pack for transfer.");
+       if (pack_size_limit && pack_size_limit < 1024*1024) {
+               warning("minimum pack size limit is 1 MiB");
+               pack_size_limit = 1024*1024;
+       }
 
        if (!pack_to_stdout && thin)
                die("--thin cannot be used to build an indexable pack.");