t9801: check git-p4's branch detection with client spec enabled
[gitweb.git] / pack-write.c
index 605d01b25cbd9d796810f8aa810894a2c198da28..33293ce2a6b8ea51516e42d01001b15a3016ca27 100644 (file)
@@ -288,13 +288,12 @@ char *index_pack_lockfile(int ip_out)
         * case, we need it to remove the corresponding .keep file
         * later on.  If we don't get that then tough luck with it.
         */
-       if (read_in_full(ip_out, packname, 46) == 46 && packname[45] == '\n' &&
-           memcmp(packname, "keep\t", 5) == 0) {
-               char path[PATH_MAX];
+       if (read_in_full(ip_out, packname, 46) == 46 && packname[45] == '\n') {
+               const char *name;
                packname[45] = 0;
-               snprintf(path, sizeof(path), "%s/pack/pack-%s.keep",
-                        get_object_directory(), packname + 5);
-               return xstrdup(path);
+               if (skip_prefix(packname, "keep\t", &name))
+                       return xstrfmt("%s/pack/pack-%s.keep",
+                                      get_object_directory(), name);
        }
        return NULL;
 }
@@ -336,7 +335,7 @@ struct sha1file *create_tmp_packfile(char **pack_tmp_name)
        return sha1fd(fd, *pack_tmp_name);
 }
 
-void finish_tmp_packfile(char *name_buffer,
+void finish_tmp_packfile(struct strbuf *name_buffer,
                         const char *pack_tmp_name,
                         struct pack_idx_entry **written_list,
                         uint32_t nr_written,
@@ -344,7 +343,7 @@ void finish_tmp_packfile(char *name_buffer,
                         unsigned char sha1[])
 {
        const char *idx_tmp_name;
-       char *end_of_name_prefix = strrchr(name_buffer, 0);
+       int basename_len = name_buffer->len;
 
        if (adjust_shared_perm(pack_tmp_name))
                die_errno("unable to make temporary pack file readable");
@@ -354,15 +353,19 @@ void finish_tmp_packfile(char *name_buffer,
        if (adjust_shared_perm(idx_tmp_name))
                die_errno("unable to make temporary index file readable");
 
-       sprintf(end_of_name_prefix, "%s.pack", sha1_to_hex(sha1));
-       free_pack_by_name(name_buffer);
+       strbuf_addf(name_buffer, "%s.pack", sha1_to_hex(sha1));
+       free_pack_by_name(name_buffer->buf);
 
-       if (rename(pack_tmp_name, name_buffer))
+       if (rename(pack_tmp_name, name_buffer->buf))
                die_errno("unable to rename temporary pack file");
 
-       sprintf(end_of_name_prefix, "%s.idx", sha1_to_hex(sha1));
-       if (rename(idx_tmp_name, name_buffer))
+       strbuf_setlen(name_buffer, basename_len);
+
+       strbuf_addf(name_buffer, "%s.idx", sha1_to_hex(sha1));
+       if (rename(idx_tmp_name, name_buffer->buf))
                die_errno("unable to rename temporary index file");
 
+       strbuf_setlen(name_buffer, basename_len);
+
        free((void *)idx_tmp_name);
 }