Skip to content

Commit fd73ccf

Browse files
dschogitster
authored andcommitted
Cope better with a _lot_ of packs
You might end up with a situation where you have tons of pack files, e.g. when using hg2git. In this situation, all kinds of operations may end up with a "too many files open" error. Let's recover gracefully from that. Signed-off-by: Johannes Schindelin <[email protected]> Looks-right-to-me-by: Shawn O. Pearce <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e64c1b0 commit fd73ccf

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

sha1_file.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,8 @@ static int open_packed_git_1(struct packed_git *p)
720720
return error("packfile %s index unavailable", p->pack_name);
721721

722722
p->pack_fd = open(p->pack_name, O_RDONLY);
723+
while (p->pack_fd < 0 && errno == EMFILE && unuse_one_window(p, -1))
724+
p->pack_fd = open(p->pack_name, O_RDONLY);
723725
if (p->pack_fd < 0 || fstat(p->pack_fd, &st))
724726
return -1;
725727

@@ -937,6 +939,8 @@ static void prepare_packed_git_one(char *objdir, int local)
937939
sprintf(path, "%s/pack", objdir);
938940
len = strlen(path);
939941
dir = opendir(path);
942+
while (!dir && errno == EMFILE && unuse_one_window(packed_git, -1))
943+
dir = opendir(path);
940944
if (!dir) {
941945
if (errno != ENOENT)
942946
error("unable to open object pack directory: %s: %s",
@@ -2339,6 +2343,8 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
23392343

23402344
filename = sha1_file_name(sha1);
23412345
fd = create_tmpfile(tmpfile, sizeof(tmpfile), filename);
2346+
while (fd < 0 && errno == EMFILE && unuse_one_window(packed_git, -1))
2347+
fd = create_tmpfile(tmpfile, sizeof(tmpfile), filename);
23422348
if (fd < 0) {
23432349
if (errno == EACCES)
23442350
return error("insufficient permission for adding an object to repository database %s\n", get_object_directory());

0 commit comments

Comments
 (0)