]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin-pack-objects.c
fast-import: introduce "feature notes" command
[thirdparty/git.git] / builtin-pack-objects.c
index b0887d759dc02e1b57fbbfa9e8e3d16c9ac00d8b..539e75d56f7a33fdb1971b51ee0681c43e9662b0 100644 (file)
@@ -17,7 +17,7 @@
 #include "progress.h"
 #include "refs.h"
 
-#ifdef THREADED_DELTA_SEARCH
+#ifndef NO_PTHREADS
 #include "thread-utils.h"
 #include <pthread.h>
 #endif
@@ -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;
@@ -246,7 +246,7 @@ static unsigned long write_object(struct sha1file *f,
 
        type = entry->type;
 
-       /* write limit if limited packsize and not first object */
+       /* apply size limit if limited packsize and not first object */
        if (!pack_size_limit || !nr_written)
                limit = 0;
        else if (pack_size_limit <= write_offset)
@@ -443,7 +443,7 @@ static int write_one(struct sha1file *f,
 
        /* offset is non zero if object is written already. */
        if (e->idx.offset || e->preferred_base)
-               return 1;
+               return -1;
 
        /* if we are deltified, write out base object first. */
        if (e->delta && !write_one(f, e->delta, offset))
@@ -464,9 +464,6 @@ static int write_one(struct sha1file *f,
        return 1;
 }
 
-/* forward declaration for write_pack_file */
-static int adjust_perm(const char *path, mode_t mode);
-
 static void write_pack_file(void)
 {
        uint32_t i = 0, j;
@@ -523,21 +520,17 @@ static void write_pack_file(void)
                }
 
                if (!pack_to_stdout) {
-                       mode_t mode = umask(0);
                        struct stat st;
                        const char *idx_tmp_name;
                        char tmpname[PATH_MAX];
 
-                       umask(mode);
-                       mode = 0444 & ~mode;
-
                        idx_tmp_name = write_idx_file(NULL, written_list,
                                                      nr_written, sha1);
 
                        snprintf(tmpname, sizeof(tmpname), "%s-%s.pack",
                                 base_name, sha1_to_hex(sha1));
                        free_pack_by_name(tmpname);
-                       if (adjust_perm(pack_tmp_name, mode))
+                       if (adjust_shared_perm(pack_tmp_name))
                                die_errno("unable to make temporary pack file readable");
                        if (rename(pack_tmp_name, tmpname))
                                die_errno("unable to rename temporary pack file");
@@ -565,7 +558,7 @@ static void write_pack_file(void)
 
                        snprintf(tmpname, sizeof(tmpname), "%s-%s.idx",
                                 base_name, sha1_to_hex(sha1));
-                       if (adjust_perm(idx_tmp_name, mode))
+                       if (adjust_shared_perm(idx_tmp_name))
                                die_errno("unable to make temporary index file readable");
                        if (rename(idx_tmp_name, tmpname))
                                die_errno("unable to rename temporary index file");
@@ -587,19 +580,6 @@ static void write_pack_file(void)
        if (written != nr_result)
                die("wrote %"PRIu32" objects while expecting %"PRIu32,
                        written, nr_result);
-       /*
-        * We have scanned through [0 ... i).  Since we have written
-        * the correct number of objects,  the remaining [i ... nr_objects)
-        * items must be either already written (due to out-of-order delta base)
-        * or a preferred base.  Count those which are neither and complain if any.
-        */
-       for (j = 0; i < nr_objects; i++) {
-               struct object_entry *e = objects + i;
-               j += !e->idx.offset && !e->preferred_base;
-       }
-       if (j)
-               die("wrote %"PRIu32" objects as expected but %"PRIu32
-                       " unwritten", written, j);
 }
 
 static int locate_object_entry_hash(const unsigned char *sha1)
@@ -1255,7 +1235,7 @@ static int delta_cacheable(unsigned long src_size, unsigned long trg_size,
        return 0;
 }
 
-#ifdef THREADED_DELTA_SEARCH
+#ifndef NO_PTHREADS
 
 static pthread_mutex_t read_mutex;
 #define read_lock()            pthread_mutex_lock(&read_mutex)
@@ -1380,7 +1360,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
        /*
         * Handle memory allocation outside of the cache
         * accounting lock.  Compiler will optimize the strangeness
-        * away when THREADED_DELTA_SEARCH is not defined.
+        * away when NO_PTHREADS is defined.
         */
        free(trg_entry->delta_data);
        cache_lock();
@@ -1567,7 +1547,7 @@ static void find_deltas(struct object_entry **list, unsigned *list_size,
        free(array);
 }
 
-#ifdef THREADED_DELTA_SEARCH
+#ifndef NO_PTHREADS
 
 /*
  * The main thread waits on the condition that (at least) one of the workers
@@ -1899,7 +1879,7 @@ static int git_pack_config(const char *k, const char *v, void *cb)
                if (delta_search_threads < 0)
                        die("invalid number of threads specified (%d)",
                            delta_search_threads);
-#ifndef THREADED_DELTA_SEARCH
+#ifdef NO_PTHREADS
                if (delta_search_threads != 1)
                        warning("no threads support, ignoring %s", k);
 #endif
@@ -2138,13 +2118,6 @@ static void get_object_list(int ac, const char **av)
                loosen_unused_packed_objects(&revs);
 }
 
-static int adjust_perm(const char *path, mode_t mode)
-{
-       if (chmod(path, mode))
-               return -1;
-       return adjust_shared_perm(path);
-}
-
 int cmd_pack_objects(int argc, const char **argv, const char *prefix)
 {
        int use_internal_rev_list = 0;
@@ -2203,10 +2176,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;
                }
@@ -2227,7 +2198,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
                        delta_search_threads = strtoul(arg+10, &end, 0);
                        if (!arg[10] || *end || delta_search_threads < 0)
                                usage(pack_usage);
-#ifndef THREADED_DELTA_SEARCH
+#ifdef NO_PTHREADS
                        if (delta_search_threads != 1)
                                warning("no threads support, "
                                        "ignoring %s", arg);
@@ -2346,9 +2317,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.");