Skip to content

Commit e3395e6

Browse files
committed
Merge branch 'racy-dissociate'
This topic branch replaces the previous patch and will be submitted to the Git mailing list soon, as reply to: http://thread.gmane.org/gmane.comp.version-control.git/278746 Signed-off-by: Johannes Schindelin <[email protected]>
2 parents bdc552b + b4dc11b commit e3395e6

File tree

4 files changed

+59
-23
lines changed

4 files changed

+59
-23
lines changed

builtin/clone.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,8 +1066,10 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
10661066
transport_unlock_pack(transport);
10671067
transport_disconnect(transport);
10681068

1069-
if (option_dissociate)
1069+
if (option_dissociate) {
1070+
close_all_packs();
10701071
dissociate_from_references();
1072+
}
10711073

10721074
junk_mode = JUNK_LEAVE_REPO;
10731075
err = checkout();

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,7 @@ extern void close_pack_index(struct packed_git *);
12861286

12871287
extern unsigned char *use_pack(struct packed_git *, struct pack_window **, off_t, unsigned long *);
12881288
extern void close_pack_windows(struct packed_git *);
1289+
extern void close_all_packs(void);
12891290
extern void unuse_pack(struct pack_window **);
12901291
extern void free_pack_by_name(const char *);
12911292
extern void clear_delta_base_cache(void);

sha1_file.c

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,34 @@ void close_pack_windows(struct packed_git *p)
786786
}
787787
}
788788

789+
static int close_pack_fd(struct packed_git *p)
790+
{
791+
if (p->pack_fd < 0)
792+
return 0;
793+
794+
close(p->pack_fd);
795+
pack_open_fds--;
796+
p->pack_fd = -1;
797+
798+
return 1;
799+
}
800+
801+
static void close_pack(struct packed_git *p)
802+
{
803+
close_pack_windows(p);
804+
close_pack_fd(p);
805+
close_pack_index(p);
806+
}
807+
808+
void close_all_packs(void)
809+
{
810+
struct packed_git *p;
811+
812+
for (p = packed_git; p; p = p->next)
813+
close_pack(p);
814+
}
815+
816+
789817
/*
790818
* The LRU pack is the one with the oldest MRU window, preferring packs
791819
* with no used windows, or the oldest mtime if it has no windows allocated.
@@ -853,12 +881,8 @@ static int close_one_pack(void)
853881
find_lru_pack(p, &lru_p, &mru_w, &accept_windows_inuse);
854882
}
855883

856-
if (lru_p) {
857-
close(lru_p->pack_fd);
858-
pack_open_fds--;
859-
lru_p->pack_fd = -1;
860-
return 1;
861-
}
884+
if (lru_p)
885+
return close_pack_fd(lru_p);
862886

863887
return 0;
864888
}
@@ -898,12 +922,7 @@ void free_pack_by_name(const char *pack_name)
898922
p = *pp;
899923
if (strcmp(pack_name, p->pack_name) == 0) {
900924
clear_delta_base_cache();
901-
close_pack_windows(p);
902-
if (p->pack_fd != -1) {
903-
close(p->pack_fd);
904-
pack_open_fds--;
905-
}
906-
close_pack_index(p);
925+
close_pack(p);
907926
free(p->bad_object_sha1);
908927
*pp = p->next;
909928
if (last_found_pack == p)
@@ -1037,11 +1056,7 @@ static int open_packed_git(struct packed_git *p)
10371056
{
10381057
if (!open_packed_git_1(p))
10391058
return 0;
1040-
if (p->pack_fd != -1) {
1041-
close(p->pack_fd);
1042-
pack_open_fds--;
1043-
p->pack_fd = -1;
1044-
}
1059+
close_pack_fd(p);
10451060
return -1;
10461061
}
10471062

@@ -1107,11 +1122,8 @@ unsigned char *use_pack(struct packed_git *p,
11071122
p->pack_name,
11081123
strerror(errno));
11091124
if (!win->offset && win->len == p->pack_size
1110-
&& !p->do_not_close) {
1111-
close(p->pack_fd);
1112-
pack_open_fds--;
1113-
p->pack_fd = -1;
1114-
}
1125+
&& !p->do_not_close)
1126+
close_pack_fd(p);
11151127
pack_mmap_calls++;
11161128
pack_open_windows++;
11171129
if (pack_mapped > peak_pack_mapped)

t/t5700-clone-reference.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,5 +188,26 @@ test_expect_success 'clone and dissociate from reference' '
188188
test_must_fail git -C R fsck &&
189189
git -C S fsck
190190
'
191+
test_expect_success 'clone, dissociate from partial reference and repack' '
192+
rm -fr P Q R &&
193+
git init P &&
194+
(
195+
cd P &&
196+
test_commit one &&
197+
git repack &&
198+
test_commit two &&
199+
git repack
200+
) &&
201+
git clone --bare P Q &&
202+
(
203+
cd P &&
204+
git checkout -b second &&
205+
test_commit three &&
206+
git repack
207+
) &&
208+
git clone --bare --dissociate --reference=P Q R &&
209+
ls R/objects/pack/*.pack >packs.txt &&
210+
test_line_count = 1 packs.txt
211+
'
191212

192213
test_done

0 commit comments

Comments
 (0)