Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d0c36a0

Browse files
committed
Merge pull request libgit2#1678 from arthurschreiber/unbreak-local-ls-after-disconnect
Unbreak git_remote_ls on a local transport after disconnecting.
2 parents 22ef0c2 + 9728cfd commit d0c36a0

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

src/transports/local.c

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,24 @@ static int add_ref(transport_local *t, const char *name)
119119

120120
static int store_refs(transport_local *t)
121121
{
122-
unsigned int i;
122+
size_t i;
123+
git_remote_head *head;
123124
git_strarray ref_names = {0};
124125

125126
assert(t);
126127

127-
if (git_reference_list(&ref_names, t->repo) < 0 ||
128-
git_vector_init(&t->refs, ref_names.count, NULL) < 0)
128+
if (git_reference_list(&ref_names, t->repo) < 0)
129129
goto on_error;
130130

131+
/* Clear all heads we might have fetched in a previous connect */
132+
git_vector_foreach(&t->refs, i, head) {
133+
git__free(head->name);
134+
git__free(head);
135+
}
136+
137+
/* Clear the vector so we can reuse it */
138+
git_vector_clear(&t->refs);
139+
131140
/* Sort the references first */
132141
git__tsort((void **)ref_names.strings, ref_names.count, &git__strcmp_cb);
133142

@@ -571,8 +580,6 @@ static void local_cancel(git_transport *transport)
571580
static int local_close(git_transport *transport)
572581
{
573582
transport_local *t = (transport_local *)transport;
574-
size_t i;
575-
git_remote_head *head;
576583

577584
t->connected = 0;
578585

@@ -586,19 +593,21 @@ static int local_close(git_transport *transport)
586593
t->url = NULL;
587594
}
588595

589-
git_vector_foreach(&t->refs, i, head) {
590-
git__free(head->name);
591-
git__free(head);
592-
}
593-
594-
git_vector_free(&t->refs);
595-
596596
return 0;
597597
}
598598

599599
static void local_free(git_transport *transport)
600600
{
601601
transport_local *t = (transport_local *)transport;
602+
size_t i;
603+
git_remote_head *head;
604+
605+
git_vector_foreach(&t->refs, i, head) {
606+
git__free(head->name);
607+
git__free(head);
608+
}
609+
610+
git_vector_free(&t->refs);
602611

603612
/* Close the transport, if it's still open. */
604613
local_close(transport);
@@ -632,6 +641,7 @@ int git_transport_local(git_transport **out, git_remote *owner, void *param)
632641
t->parent.read_flags = local_read_flags;
633642
t->parent.cancel = local_cancel;
634643

644+
git_vector_init(&t->refs, 0, NULL);
635645
t->owner = owner;
636646

637647
*out = (git_transport *) t;

tests-clar/network/remote/local.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ void test_network_remote_local__retrieve_advertised_references(void)
7575
cl_assert_equal_i(how_many_refs, 28);
7676
}
7777

78+
void test_network_remote_local__retrieve_advertised_references_after_disconnect(void)
79+
{
80+
int how_many_refs = 0;
81+
82+
connect_to_local_repository(cl_fixture("testrepo.git"));
83+
git_remote_disconnect(remote);
84+
85+
cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
86+
87+
cl_assert_equal_i(how_many_refs, 28);
88+
}
89+
7890
void test_network_remote_local__retrieve_advertised_references_from_spaced_repository(void)
7991
{
8092
int how_many_refs = 0;

0 commit comments

Comments
 (0)