|
1 | 1 | #include "cache.h"
|
2 | 2 | #include "config.h"
|
| 3 | +#include "dir.h" |
3 | 4 | #include "git-compat-util.h"
|
4 | 5 | #include "lockfile.h"
|
5 | 6 | #include "pack.h"
|
@@ -640,7 +641,6 @@ void write_commit_graph(const char *obj_dir,
|
640 | 641 | struct hashfile *f;
|
641 | 642 | uint32_t i, count_distinct = 0;
|
642 | 643 | char *graph_name;
|
643 |
| - int fd; |
644 | 644 | struct lock_file lk = LOCK_INIT;
|
645 | 645 | uint32_t chunk_ids[5];
|
646 | 646 | uint64_t chunk_offsets[5];
|
@@ -754,23 +754,11 @@ void write_commit_graph(const char *obj_dir,
|
754 | 754 | compute_generation_numbers(&commits);
|
755 | 755 |
|
756 | 756 | graph_name = get_commit_graph_filename(obj_dir);
|
757 |
| - fd = hold_lock_file_for_update(&lk, graph_name, 0); |
758 |
| - |
759 |
| - if (fd < 0) { |
760 |
| - struct strbuf folder = STRBUF_INIT; |
761 |
| - strbuf_addstr(&folder, graph_name); |
762 |
| - strbuf_setlen(&folder, strrchr(folder.buf, '/') - folder.buf); |
763 |
| - |
764 |
| - if (mkdir(folder.buf, 0777) < 0) |
765 |
| - die_errno(_("cannot mkdir %s"), folder.buf); |
766 |
| - strbuf_release(&folder); |
767 |
| - |
768 |
| - fd = hold_lock_file_for_update(&lk, graph_name, LOCK_DIE_ON_ERROR); |
769 |
| - |
770 |
| - if (fd < 0) |
771 |
| - die_errno("unable to create '%s'", graph_name); |
772 |
| - } |
| 757 | + if (safe_create_leading_directories(graph_name)) |
| 758 | + die_errno(_("unable to create leading directories of %s"), |
| 759 | + graph_name); |
773 | 760 |
|
| 761 | + hold_lock_file_for_update(&lk, graph_name, LOCK_DIE_ON_ERROR); |
774 | 762 | f = hashfd(lk.tempfile->fd, lk.tempfile->filename.buf);
|
775 | 763 |
|
776 | 764 | hashwrite_be32(f, GRAPH_SIGNATURE);
|
|
0 commit comments