Code

Documentation: receive.denyCurrentBranch defaults to 'refuse'
[git.git] / builtin-pack-objects.c
index dcfe62aa02ca69cad39b4dd681a60f052b20aba5..539e75d56f7a33fdb1971b51ee0681c43e9662b0 100644 (file)
@@ -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);
@@ -468,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;
@@ -505,9 +498,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?
@@ -525,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");
@@ -567,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");
@@ -582,7 +573,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);
@@ -2127,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;