transport: store the refs in a common area Instad of each transport having its own function and logic to get to its refs, store them directly in transport. Leverage the new gitno_buffer to make the parsing and storing of the refs use common code and get rid of the git_protocol struct.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840
diff --git a/src/fetch.c b/src/fetch.c
index 0de0c62..26fa396 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -71,7 +71,7 @@ static int filter_wants(git_remote *remote)
if (git_repository_odb__weakptr(&p.odb, remote->repo) < 0)
return -1;
- return remote->transport->ls(remote->transport, &filter_ref__cb, &p);
+ return git_remote_ls(remote, filter_ref__cb, &p);
}
/* Wait until we get an ack from the */
diff --git a/src/protocol.c b/src/protocol.c
index d8512fd..20d6e23 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -9,38 +9,36 @@
#include "pkt.h"
#include "buffer.h"
-int git_protocol_store_refs(git_protocol *p, const char *data, size_t len)
+int git_protocol_store_refs(git_transport *t, int flushes)
{
- git_buf *buf = &p->buf;
- git_vector *refs = p->refs;
- int error;
- const char *line_end, *ptr;
-
- if (len == 0) { /* EOF */
- if (git_buf_len(buf) != 0) {
- giterr_set(GITERR_NET, "Unexpected EOF");
- return p->error = -1;
- } else {
- return 0;
- }
- }
-
- git_buf_put(buf, data, len);
- ptr = buf->ptr;
- while (1) {
- git_pkt *pkt;
+ gitno_buffer *buf = &t->buffer;
+ git_vector *refs = &t->refs;
+ int error, flush = 0, recvd;
+ const char *line_end;
+ git_pkt *pkt;
+
+ do {
+ if (buf->offset > 0)
+ error = git_pkt_parse_line(&pkt, buf->data, &line_end, buf->offset);
+ else
+ error = GIT_EBUFS;
+
+ if (error < 0 && error != GIT_EBUFS)
+ return -1;
- if (git_buf_len(buf) == 0)
- return 0;
+ if (error == GIT_EBUFS) {
+ if ((recvd = gitno_recv(buf)) < 0)
+ return -1;
- error = git_pkt_parse_line(&pkt, ptr, &line_end, git_buf_len(buf));
- if (error == GIT_EBUFS)
- return 0; /* Ask for more */
- if (error < 0)
- return p->error = -1;
+ if (recvd == 0 && !flush) {
+ giterr_set(GITERR_NET, "Early EOF");
+ return -1;
+ }
- git_buf_consume(buf, line_end);
+ continue;
+ }
+ gitno_consume(buf, line_end);
if (pkt->type == GIT_PKT_ERR) {
giterr_set(GITERR_NET, "Remote error: %s", ((git_pkt_err *)pkt)->error);
git__free(pkt);
@@ -48,13 +46,13 @@ int git_protocol_store_refs(git_protocol *p, const char *data, size_t len)
}
if (git_vector_insert(refs, pkt) < 0)
- return p->error = -1;
+ return -1;
if (pkt->type == GIT_PKT_FLUSH)
- p->flush = 1;
- }
+ flush++;
+ } while (flush < flushes);
- return 0;
+ return flush;
}
int git_protocol_detect_caps(git_pkt_ref *pkt, git_transport_caps *caps)
diff --git a/src/protocol.h b/src/protocol.h
index 9d53480..615be8d 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -11,15 +11,7 @@
#include "buffer.h"
#include "pkt.h"
-typedef struct {
- git_transport *transport;
- git_vector *refs;
- git_buf buf;
- int error;
- unsigned int flush :1;
-} git_protocol;
-
-int git_protocol_store_refs(git_protocol *p, const char *data, size_t len);
+int git_protocol_store_refs(git_transport *t, int flushes);
int git_protocol_detect_caps(git_pkt_ref *pkt, git_transport_caps *caps);
#endif
diff --git a/src/remote.c b/src/remote.c
index c2bfb09..948da12 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -14,6 +14,7 @@
#include "remote.h"
#include "fetch.h"
#include "refs.h"
+#include "pkt.h"
#include <regex.h>
@@ -401,6 +402,10 @@ on_error:
int git_remote_ls(git_remote *remote, git_headlist_cb list_cb, void *payload)
{
+ git_vector *refs = &remote->transport->refs;
+ unsigned int i;
+ git_pkt *p = NULL;
+
assert(remote);
if (!remote->transport || !remote->transport->connected) {
@@ -408,7 +413,21 @@ int git_remote_ls(git_remote *remote, git_headlist_cb list_cb, void *payload)
return -1;
}
- return remote->transport->ls(remote->transport, list_cb, payload);
+ git_vector_foreach(refs, i, p) {
+ git_pkt_ref *pkt = NULL;
+
+ if (p->type != GIT_PKT_REF)
+ continue;
+
+ pkt = (git_pkt_ref *)p;
+
+ if (list_cb(&pkt->head, payload) < 0) {
+ giterr_set(GITERR_NET, "User callback returned error");
+ return -1;
+ }
+ }
+
+ return 0;
}
int git_remote_download(git_remote *remote, git_off_t *bytes, git_indexer_stats *stats)
diff --git a/src/transport.h b/src/transport.h
index 0adc037..bb0b041 100644
--- a/src/transport.h
+++ b/src/transport.h
@@ -79,6 +79,7 @@ struct git_transport {
#ifdef GIT_SSL
struct gitno_ssl ssl;
#endif
+ git_vector refs;
git_vector common;
gitno_buffer buffer;
GIT_SOCKET socket;
@@ -92,10 +93,6 @@ struct git_transport {
*/
int (*negotiation_step)(struct git_transport *transport, void *data, size_t len);
/**
- * Give a list of references, useful for ls-remote
- */
- int (*ls)(struct git_transport *transport, git_headlist_cb list_cb, void *opaque);
- /**
* Push the changes over
*/
int (*push)(struct git_transport *transport);
@@ -109,10 +106,6 @@ struct git_transport {
*/
int (*download_pack)(struct git_transport *transport, git_repository *repo, git_off_t *bytes, git_indexer_stats *stats);
/**
- * Fetch the changes
- */
- int (*fetch)(struct git_transport *transport);
- /**
* Close the connection
*/
int (*close)(struct git_transport *transport);
diff --git a/src/transports/git.c b/src/transports/git.c
index ccd9755..7a65718 100644
--- a/src/transports/git.c
+++ b/src/transports/git.c
@@ -24,9 +24,6 @@
typedef struct {
git_transport parent;
- git_protocol proto;
- git_vector refs;
- git_remote_head **heads;
char buff[1024];
#ifdef GIT_WIN32
WSADATA wsd;
@@ -125,38 +122,6 @@ on_error:
}
/*
- * Read from the socket and store the references in the vector
- */
-static int store_refs(transport_git *t)
-{
- gitno_buffer *buf = &t->parent.buffer;
- int ret = 0;
-
- while (1) {
- if ((ret = gitno_recv(buf)) < 0)
- return -1;
- if (ret == 0) /* Orderly shutdown, so exit */
- return 0;
-
- ret = git_protocol_store_refs(&t->proto, buf->data, buf->offset);
- if (ret == GIT_EBUFS) {
- gitno_consume_n(buf, buf->len);
- continue;
- }
-
- if (ret < 0)
- return ret;
-
- gitno_consume_n(buf, buf->offset);
-
- if (t->proto.flush) { /* No more refs */
- t->proto.flush = 0;
- return 0;
- }
- }
-}
-
-/*
* Since this is a network connection, we need to parse and store the
* pkt-lines at this stage and keep them there.
*/
@@ -170,48 +135,19 @@ static int git_connect(git_transport *transport, int direction)
}
t->parent.direction = direction;
- if (git_vector_init(&t->refs, 16, NULL) < 0)
- return -1;
/* Connect and ask for the refs */
if (do_connect(t, transport->url) < 0)
- goto cleanup;
+ return -1;
gitno_buffer_setup(transport, &transport->buffer, t->buff, sizeof(t->buff));
t->parent.connected = 1;
- if (store_refs(t) < 0)
- goto cleanup;
-
- if (git_protocol_detect_caps(git_vector_get(&t->refs, 0), &transport->caps) < 0)
- goto cleanup;
-
- return 0;
-cleanup:
- git_vector_free(&t->refs);
- return -1;
-}
-
-static int git_ls(git_transport *transport, git_headlist_cb list_cb, void *opaque)
-{
- transport_git *t = (transport_git *) transport;
- git_vector *refs = &t->refs;
- unsigned int i;
- git_pkt *p = NULL;
-
- git_vector_foreach(refs, i, p) {
- git_pkt_ref *pkt = NULL;
-
- if (p->type != GIT_PKT_REF)
- continue;
-
- pkt = (git_pkt_ref *)p;
+ if (git_protocol_store_refs(transport, 1) < 0)
+ return -1;
- if (list_cb(&pkt->head, opaque) < 0) {
- giterr_set(GITERR_NET, "User callback returned error");
- return -1;
- }
- }
+ if (git_protocol_detect_caps(git_vector_get(&transport->refs, 0), &transport->caps) < 0)
+ return -1;
return 0;
}
@@ -229,6 +165,7 @@ static int git_close(git_transport *t)
return -1;
/* Can't do anything if there's an error, so don't bother checking */
gitno_send(t, buf.ptr, buf.size, 0);
+ git_buf_free(&buf);
if (gitno_close(t->socket) < 0) {
giterr_set(GITERR_NET, "Failed to close socket");
@@ -247,17 +184,22 @@ static int git_close(git_transport *t)
static void git_free(git_transport *transport)
{
transport_git *t = (transport_git *) transport;
- git_vector *refs = &t->refs;
+ git_vector *refs = &transport->refs;
unsigned int i;
for (i = 0; i < refs->length; ++i) {
git_pkt *p = git_vector_get(refs, i);
git_pkt_free(p);
}
+ git_vector_free(refs);
+ refs = &transport->common;
+ for (i = 0; i < refs->length; ++i) {
+ git_pkt *p = git_vector_get(refs, i);
+ git_pkt_free(p);
+ }
git_vector_free(refs);
- git__free(t->heads);
- git_buf_free(&t->proto.buf);
+
git__free(t->parent.url);
git__free(t);
}
@@ -273,18 +215,16 @@ int git_transport_git(git_transport **out)
GITERR_CHECK_ALLOC(t);
memset(t, 0x0, sizeof(transport_git));
- if (git_vector_init(&t->parent.common, 8, NULL)) {
- git__free(t);
- return -1;
- }
+ if (git_vector_init(&t->parent.common, 8, NULL))
+ goto on_error;
+
+ if (git_vector_init(&t->parent.refs, 16, NULL) < 0)
+ goto on_error;
t->parent.connect = git_connect;
t->parent.negotiation_step = git_negotiation_step;
- t->parent.ls = git_ls;
t->parent.close = git_close;
t->parent.free = git_free;
- t->proto.refs = &t->refs;
- t->proto.transport = (git_transport *) t;
*out = (git_transport *) t;
@@ -298,4 +238,8 @@ int git_transport_git(git_transport **out)
#endif
return 0;
+
+on_error:
+ git__free(t);
+ return -1;
}
diff --git a/src/transports/http.c b/src/transports/http.c
index 25db802..c29ed9a 100644
--- a/src/transports/http.c
+++ b/src/transports/http.c
@@ -29,11 +29,8 @@ enum last_cb {
typedef struct {
git_transport parent;
- git_protocol proto;
- git_vector refs;
http_parser_settings settings;
git_buf buf;
- git_remote_head **heads;
int error;
int transfer_finished :1,
ct_found :1,
@@ -183,17 +180,6 @@ static int on_headers_complete(http_parser *parser)
return 0;
}
-static int on_body_store_refs(http_parser *parser, const char *str, size_t len)
-{
- transport_http *t = (transport_http *) parser->data;
-
- if (parser->status_code == 404) {
- return git_buf_put(&t->buf, str, len);
- }
-
- return git_protocol_store_refs(&t->proto, str, len);
-}
-
static int on_message_complete(http_parser *parser)
{
transport_http *t = (transport_http *) parser->data;
@@ -208,57 +194,64 @@ static int on_message_complete(http_parser *parser)
return 0;
}
-static int store_refs(transport_http *t)
+static int on_body_fill_buffer(http_parser *parser, const char *str, size_t len)
{
- git_transport *transport = (git_transport *) t;
- http_parser_settings settings;
- char buffer[1024];
- gitno_buffer buf;
- git_pkt *pkt;
- int ret;
+ git_transport *transport = (git_transport *) parser->data;
+ transport_http *t = (transport_http *) parser->data;
+ gitno_buffer *buf = &transport->buffer;
- http_parser_init(&t->parser, HTTP_RESPONSE);
- t->parser.data = t;
- memset(&settings, 0x0, sizeof(http_parser_settings));
- settings.on_header_field = on_header_field;
- settings.on_header_value = on_header_value;
- settings.on_headers_complete = on_headers_complete;
- settings.on_body = on_body_store_refs;
- settings.on_message_complete = on_message_complete;
+ if (buf->len - buf->offset < len) {
+ giterr_set(GITERR_NET, "Can't fit data in the buffer");
+ return t->error = -1;
+ }
- gitno_buffer_setup((git_transport *)t, &buf, buffer, sizeof(buffer));
+ memcpy(buf->data + buf->offset, str, len);
+ buf->offset += len;
- while(1) {
- size_t parsed;
+ return 0;
+}
- if ((ret = gitno_recv(&buf)) < 0)
- return -1;
+static int http_recv_cb(gitno_buffer *buf)
+{
+ git_transport *transport = (git_transport *) buf->cb_data;
+ transport_http *t = (transport_http *) transport;
+ size_t old_len;
+ gitno_buffer inner;
+ char buffer[2048];
+ int error;
- parsed = http_parser_execute(&t->parser, &settings, buf.data, buf.offset);
- /* Both should happen at the same time */
- if (parsed != buf.offset || t->error < 0)
- return t->error;
+ if (t->transfer_finished)
+ return 0;
- gitno_consume_n(&buf, parsed);
+ gitno_buffer_setup(transport, &inner, buffer, sizeof(buffer));
- if (ret == 0 || t->transfer_finished)
- break;
- }
+ if ((error = gitno_recv(&inner)) < 0)
+ return -1;
- pkt = git_vector_get(&t->refs, 0);
- if (pkt == NULL || pkt->type != GIT_PKT_COMMENT) {
- giterr_set(GITERR_NET, "Invalid HTTP response");
- return t->error = -1;
- } else {
- /* Remove the comment and flush pkts */
- git_vector_remove(&t->refs, 0);
- git_vector_remove(&t->refs, 0);
- }
+ old_len = buf->offset;
+ http_parser_execute(&t->parser, &t->settings, inner.data, inner.offset);
+ if (t->error < 0)
+ return t->error;
- if (git_protocol_detect_caps(git_vector_get(&t->refs, 0), &transport->caps) < 0)
- return t->error = -1;
+ return buf->offset - old_len;
+}
- return 0;
+/* Set up the gitno_buffer so calling gitno_recv() grabs data from the HTTP response */
+static void setup_gitno_buffer(git_transport *transport)
+{
+ transport_http *t = (transport_http *) transport;
+
+ http_parser_init(&t->parser, HTTP_RESPONSE);
+ t->parser.data = t;
+ t->transfer_finished = 0;
+ memset(&t->settings, 0x0, sizeof(http_parser_settings));
+ t->settings.on_header_field = on_header_field;
+ t->settings.on_header_value = on_header_value;
+ t->settings.on_headers_complete = on_headers_complete;
+ t->settings.on_body = on_body_fill_buffer;
+ t->settings.on_message_complete = on_message_complete;
+
+ gitno_buffer_setup_callback(transport, &transport->buffer, t->buffer, sizeof(t->buffer), http_recv_cb, t);
}
static int http_connect(git_transport *transport, int direction)
@@ -269,6 +262,7 @@ static int http_connect(git_transport *transport, int direction)
const char *service = "upload-pack";
const char *url = t->parent.url, *prefix_http = "http://", *prefix_https = "https://";
const char *default_port;
+ git_pkt *pkt;
if (direction == GIT_DIR_PUSH) {
giterr_set(GITERR_NET, "Pushing over HTTP is not implemented");
@@ -276,8 +270,6 @@ static int http_connect(git_transport *transport, int direction)
}
t->parent.direction = direction;
- if (git_vector_init(&t->refs, 16, NULL) < 0)
- return -1;
if (!git__prefixcmp(url, prefix_http)) {
url = t->parent.url + strlen(prefix_http);
@@ -310,75 +302,31 @@ static int http_connect(git_transport *transport, int direction)
if (gitno_send(transport, request.ptr, request.size, 0) < 0)
goto cleanup;
- ret = store_refs(t);
-
-cleanup:
- git_buf_free(&request);
- git_buf_clear(&t->buf);
-
- return ret;
-}
-
-static int http_ls(git_transport *transport, git_headlist_cb list_cb, void *opaque)
-{
- transport_http *t = (transport_http *) transport;
- git_vector *refs = &t->refs;
- unsigned int i;
- git_pkt_ref *p;
-
- git_vector_foreach(refs, i, p) {
- if (p->type != GIT_PKT_REF)
- continue;
-
- if (list_cb(&p->head, opaque) < 0) {
- giterr_set(GITERR_NET, "The user callback returned error");
- return -1;
- }
- }
-
- return 0;
-}
-
-static int on_body_fill_buffer(http_parser *parser, const char *str, size_t len)
-{
- git_transport *transport = (git_transport *) parser->data;
- transport_http *t = (transport_http *) parser->data;
- gitno_buffer *buf = &transport->buffer;
+ setup_gitno_buffer(transport);
+ if ((ret = git_protocol_store_refs(transport, 2)) < 0)
+ goto cleanup;
- if (buf->len - buf->offset < len) {
- giterr_set(GITERR_NET, "Can't fit data in the buffer");
+ pkt = git_vector_get(&transport->refs, 0);
+ if (pkt == NULL || pkt->type != GIT_PKT_COMMENT) {
+ giterr_set(GITERR_NET, "Invalid HTTP response");
return t->error = -1;
+ } else {
+ /* Remove the comment and flush pkts */
+ git_vector_remove(&transport->refs, 0);
+ git__free(pkt);
+ pkt = git_vector_get(&transport->refs, 0);
+ git_vector_remove(&transport->refs, 0);
+ git__free(pkt);
}
- memcpy(buf->data + buf->offset, str, len);
- buf->offset += len;
-
- return 0;
-}
-
-static int http_recv_cb(gitno_buffer *buf)
-{
- git_transport *transport = (git_transport *) buf->cb_data;
- transport_http *t = (transport_http *) transport;
- size_t parsed, old_len;
- gitno_buffer inner;
- char buffer[2048];
- int error;
-
- if (t->transfer_finished)
- return 0;
-
- gitno_buffer_setup(transport, &inner, buffer, sizeof(buffer));
-
- if ((error = gitno_recv(&inner)) < 0)
- return -1;
+ if (git_protocol_detect_caps(git_vector_get(&transport->refs, 0), &transport->caps) < 0)
+ return t->error = -1;
- old_len = buf->offset;
- parsed = http_parser_execute(&t->parser, &t->settings, inner.data, inner.offset);
- if (t->error < 0)
- return t->error;
+cleanup:
+ git_buf_free(&request);
+ git_buf_clear(&t->buf);
- return buf->offset - old_len;
+ return ret;
}
static int http_negotiation_step(struct git_transport *transport, void *data, size_t len)
@@ -403,17 +351,7 @@ static int http_negotiation_step(struct git_transport *transport, void *data, si
git_buf_free(&request);
/* Then we need to set up the buffer to grab data from the HTTP response */
- http_parser_init(&t->parser, HTTP_RESPONSE);
- t->parser.data = t;
- t->transfer_finished = 0;
- memset(&t->settings, 0x0, sizeof(http_parser_settings));
- t->settings.on_header_field = on_header_field;
- t->settings.on_header_value = on_header_value;
- t->settings.on_headers_complete = on_headers_complete;
- t->settings.on_body = on_body_fill_buffer;
- t->settings.on_message_complete = on_message_complete;
-
- gitno_buffer_setup_callback(transport, &transport->buffer, t->buffer, sizeof(t->buffer), http_recv_cb, t);
+ setup_gitno_buffer(transport);
return 0;
@@ -441,7 +379,7 @@ static int http_close(git_transport *transport)
static void http_free(git_transport *transport)
{
transport_http *t = (transport_http *) transport;
- git_vector *refs = &t->refs;
+ git_vector *refs = &transport->refs;
git_vector *common = &transport->common;
unsigned int i;
git_pkt *p;
@@ -463,8 +401,6 @@ static void http_free(git_transport *transport)
}
git_vector_free(common);
git_buf_free(&t->buf);
- git_buf_free(&t->proto.buf);
- git__free(t->heads);
git__free(t->content_type);
git__free(t->host);
git__free(t->port);
@@ -483,13 +419,15 @@ int git_transport_http(git_transport **out)
memset(t, 0x0, sizeof(transport_http));
t->parent.connect = http_connect;
- t->parent.ls = http_ls;
t->parent.negotiation_step = http_negotiation_step;
t->parent.close = http_close;
t->parent.free = http_free;
t->parent.rpc = 1;
- t->proto.refs = &t->refs;
- t->proto.transport = (git_transport *) t;
+
+ if (git_vector_init(&t->parent.refs, 16, NULL) < 0) {
+ git__free(t);
+ return -1;
+ }
#ifdef GIT_WIN32
/* on win32, the WSA context needs to be initialized
diff --git a/src/transports/local.c b/src/transports/local.c
index 0e1ae37..561c84f 100644
--- a/src/transports/local.c
+++ b/src/transports/local.c
@@ -15,11 +15,11 @@
#include "posix.h"
#include "path.h"
#include "buffer.h"
+#include "pkt.h"
typedef struct {
git_transport parent;
git_repository *repo;
- git_vector refs;
} transport_local;
static int add_ref(transport_local *t, const char *name)
@@ -27,19 +27,32 @@ static int add_ref(transport_local *t, const char *name)
const char peeled[] = "^{}";
git_remote_head *head;
git_object *obj = NULL, *target = NULL;
+ git_transport *transport = (git_transport *) t;
git_buf buf = GIT_BUF_INIT;
+ git_pkt_ref *pkt;
head = git__malloc(sizeof(git_remote_head));
GITERR_CHECK_ALLOC(head);
+ pkt = git__malloc(sizeof(git_pkt_ref));
+ GITERR_CHECK_ALLOC(pkt);
head->name = git__strdup(name);
GITERR_CHECK_ALLOC(head->name);
- if (git_reference_name_to_oid(&head->oid, t->repo, name) < 0 ||
- git_vector_insert(&t->refs, head) < 0)
- {
- git__free(head->name);
+ if (git_reference_name_to_oid(&head->oid, t->repo, name) < 0) {
git__free(head);
+ git__free(pkt->head.name);
+ git__free(pkt);
+ }
+
+ pkt->type = GIT_PKT_REF;
+ memcpy(&pkt->head, head, sizeof(git_remote_head));
+ git__free(head);
+
+ if (git_vector_insert(&transport->refs, pkt) < 0)
+ {
+ git__free(pkt->head.name);
+ git__free(pkt);
return -1;
}
@@ -47,7 +60,7 @@ static int add_ref(transport_local *t, const char *name)
if (git__prefixcmp(name, GIT_REFS_TAGS_DIR))
return 0;
- if (git_object_lookup(&obj, t->repo, &head->oid, GIT_OBJ_ANY) < 0)
+ if (git_object_lookup(&obj, t->repo, &pkt->head.oid, GIT_OBJ_ANY) < 0)
return -1;
head = NULL;
@@ -66,14 +79,20 @@ static int add_ref(transport_local *t, const char *name)
head->name = git_buf_detach(&buf);
+ pkt = git__malloc(sizeof(git_pkt_ref));
+ GITERR_CHECK_ALLOC(pkt);
+ pkt->type = GIT_PKT_REF;
+
if (git_tag_peel(&target, (git_tag *) obj) < 0)
goto on_error;
git_oid_cpy(&head->oid, git_object_id(target));
git_object_free(obj);
git_object_free(target);
+ memcpy(&pkt->head, head, sizeof(git_remote_head));
+ git__free(head);
- if (git_vector_insert(&t->refs, head) < 0)
+ if (git_vector_insert(&transport->refs, pkt) < 0)
return -1;
return 0;
@@ -88,11 +107,12 @@ static int store_refs(transport_local *t)
{
unsigned int i;
git_strarray ref_names = {0};
+ git_transport *transport = (git_transport *) t;
assert(t);
if (git_reference_list(&ref_names, t->repo, GIT_REF_LISTALL) < 0 ||
- git_vector_init(&t->refs, (unsigned int)ref_names.count, NULL) < 0)
+ git_vector_init(&transport->refs, (unsigned int)ref_names.count, NULL) < 0)
goto on_error;
/* Sort the references first */
@@ -111,28 +131,11 @@ static int store_refs(transport_local *t)
return 0;
on_error:
- git_vector_free(&t->refs);
+ git_vector_free(&transport->refs);
git_strarray_free(&ref_names);
return -1;
}
-static int local_ls(git_transport *transport, git_headlist_cb list_cb, void *payload)
-{
- transport_local *t = (transport_local *) transport;
- git_vector *refs = &t->refs;
- unsigned int i;
- git_remote_head *h;
-
- assert(transport && transport->connected);
-
- git_vector_foreach(refs, i, h) {
- if (list_cb(h, payload) < 0)
- return -1;
- }
-
- return 0;
-}
-
/*
* Try to open the url as a git directory. The direction doesn't
* matter in this case because we're calulating the heads ourselves.
@@ -201,14 +204,14 @@ static void local_free(git_transport *transport)
{
unsigned int i;
transport_local *t = (transport_local *) transport;
- git_vector *vec = &t->refs;
- git_remote_head *h;
+ git_vector *vec = &transport->refs;
+ git_pkt_ref *pkt;
assert(transport);
- git_vector_foreach (vec, i, h) {
- git__free(h->name);
- git__free(h);
+ git_vector_foreach (vec, i, pkt) {
+ git__free(pkt->head.name);
+ git__free(pkt);
}
git_vector_free(vec);
@@ -229,8 +232,8 @@ int git_transport_local(git_transport **out)
memset(t, 0x0, sizeof(transport_local));
+ t->parent.own_logic = 1;
t->parent.connect = local_connect;
- t->parent.ls = local_ls;
t->parent.negotiate_fetch = local_negotiate_fetch;
t->parent.close = local_close;
t->parent.free = local_free;