From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Subject: [PATCH 13/14] remote-curl: resume interrupted bundle transfers
Date: Thu, 10 Nov 2011 02:53:53 -0500 [thread overview]
Message-ID: <20111110075353.GM27950@sigill.intra.peff.net> (raw)
In-Reply-To: <20111110074330.GA27925@sigill.intra.peff.net>
If we have a bundle file from a previous fetch that matches
this URL, then we should resume the transfer where we left
off.
Signed-off-by: Jeff King <peff@peff.net>
---
The second half of the diff is hard to read because I re-indent a big
chunk. It's much easier to see what's going on with "diff -b".
remote-curl.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 53 insertions(+), 11 deletions(-)
diff --git a/remote-curl.c b/remote-curl.c
index 6b0820e..43ad1b6 100644
--- a/remote-curl.c
+++ b/remote-curl.c
@@ -9,6 +9,7 @@
#include "sideband.h"
#include "bundle.h"
#include "progress.h"
+#include "dir.h"
static struct remote *remote;
static const char *url; /* always ends with a trailing slash */
@@ -171,6 +172,32 @@ static int get_refs_from_url(const char *url, struct strbuf *out, int options,
return ret;
}
+static int resume_bundle(const char *url, const char *tmpname)
+{
+ struct get_refs_cb_data data;
+ int ret;
+
+ data.fh = fopen(tmpname, "ab");
+ if (!data.fh)
+ die_errno("unable to open %s", tmpname);
+
+ data.is_bundle = 1;
+ data.total = ftell(data.fh);
+ if (options.progress) {
+ data.progress = start_progress("Resuming bundle", 0);
+ display_progress(data.progress, 0);
+ display_throughput(data.progress, data.total);
+ }
+
+ ret = http_get_callback(url, get_refs_callback, &data, data.total, 0);
+
+ if (fclose(data.fh))
+ die_errno("unable to write to %s", tmpname);
+ stop_progress(&data.progress);
+
+ return ret;
+}
+
static const char *url_to_bundle_tmpfile(const char *url)
{
struct strbuf buf = STRBUF_INIT;
@@ -210,20 +237,35 @@ static int get_refs_from_url(const char *url, struct strbuf *out, int options,
free_discovery(last);
filename = url_to_bundle_tmpfile(url);
+ if (file_exists(filename)) {
+ struct strbuf trimmed = STRBUF_INIT;
- strbuf_addf(&buffer, "%sinfo/refs", url);
- if (!prefixcmp(url, "http://") || !prefixcmp(url, "https://")) {
- is_http = 1;
- if (!strchr(url, '?'))
- strbuf_addch(&buffer, '?');
- else
- strbuf_addch(&buffer, '&');
- strbuf_addf(&buffer, "service=%s", service);
+ strbuf_addstr(&trimmed, url);
+ while (trimmed.len > 0 && trimmed.buf[trimmed.len-1] == '/')
+ strbuf_setlen(&trimmed, trimmed.len - 1);
+ refs_url = strbuf_detach(&trimmed, NULL);
+
+ http_ret = resume_bundle(refs_url, filename);
+ is_bundle = 1;
}
- refs_url = strbuf_detach(&buffer, NULL);
+ else
+ http_ret = HTTP_MISSING_TARGET;
+
+ if (http_ret != HTTP_OK && http_ret != HTTP_NOAUTH) {
+ strbuf_addf(&buffer, "%sinfo/refs", url);
+ if (!prefixcmp(url, "http://") || !prefixcmp(url, "https://")) {
+ is_http = 1;
+ if (!strchr(url, '?'))
+ strbuf_addch(&buffer, '?');
+ else
+ strbuf_addch(&buffer, '&');
+ strbuf_addf(&buffer, "service=%s", service);
+ }
+ refs_url = strbuf_detach(&buffer, NULL);
- http_ret = get_refs_from_url(refs_url, &buffer, HTTP_NO_CACHE,
- filename, &is_bundle);
+ http_ret = get_refs_from_url(refs_url, &buffer, HTTP_NO_CACHE,
+ filename, &is_bundle);
+ }
/* try again with "plain" url (no ? or & appended) */
if (http_ret != HTTP_OK && http_ret != HTTP_NOAUTH) {
--
1.7.7.2.7.g9f96f
next prev parent reply other threads:[~2011-11-10 7:54 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-10 7:43 [PATCH 0/14] resumable network bundles Jeff King
2011-11-10 7:45 ` Jeff King
2011-11-10 7:46 ` [PATCH 01/14] t/lib-httpd: check for NO_CURL Jeff King
2011-11-10 7:48 ` [PATCH 02/14] http: turn off curl signals Jeff King
2011-11-10 8:43 ` Daniel Stenberg
2011-11-11 20:54 ` Jeff King
2011-11-10 7:48 ` [PATCH 03/14] http: refactor http_request function Jeff King
2011-11-10 7:49 ` [PATCH 04/14] http: add a public function for arbitrary-callback request Jeff King
2011-11-10 7:49 ` [PATCH 05/14] remote-curl: use http callback for requesting refs Jeff King
2011-11-10 7:49 ` [PATCH 06/14] transport: factor out bundle to ref list conversion Jeff King
2011-11-10 7:50 ` [PATCH 07/14] bundle: add is_bundle_buf helper Jeff King
2011-11-10 7:50 ` [PATCH 08/14] remote-curl: free "discovery" object Jeff King
2011-11-10 7:50 ` [PATCH 09/14] remote-curl: auto-detect bundles when fetching refs Jeff King
2011-11-10 7:51 ` [PATCH 10/14] remote-curl: try base $URL after $URL/info/refs Jeff King
2011-11-10 7:53 ` [PATCH 11/14] progress: allow pure-throughput progress meters Jeff King
2011-11-10 7:53 ` [PATCH 12/14] remote-curl: show progress for bundle downloads Jeff King
2011-11-10 7:53 ` Jeff King [this message]
2011-11-10 7:56 ` [PATCH 14/14] clone: give advice on how to resume a failed clone Jeff King
2011-11-10 21:21 ` Junio C Hamano
2011-11-11 20:52 ` Jeff King
2011-11-11 13:13 ` [PATCH 0/14] resumable network bundles David Michael Barr
2011-11-12 16:11 ` Tay Ray Chuan
2011-11-12 17:58 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20111110075353.GM27950@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).