* [PATCH 4/4] Add support for URLs to git-apply
From: Mike Hommey @ 2007-12-09 17:05 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
In-Reply-To: <1197219900-19334-3-git-send-email-mh@glandium.org>
Instead of doing several "wget -O - url | git-apply -" in a raw, you now
can just git-apply url1 url2 ...
Signed-off-by: Mike Hommey <mh@glandium.org>
---
Documentation/git-apply.txt | 3 +-
builtin-apply.c | 58 ++++++++++++++++++++++++++++++++++++------
2 files changed, 51 insertions(+), 10 deletions(-)
diff --git a/Documentation/git-apply.txt b/Documentation/git-apply.txt
index bae3e7b..2d5d725 100644
--- a/Documentation/git-apply.txt
+++ b/Documentation/git-apply.txt
@@ -25,7 +25,8 @@ OPTIONS
-------
<patch>...::
The files to read patch from. '-' can be used to read
- from the standard input.
+ from the standard input. They can also be http, https or
+ ftp URLs.
--stat::
Instead of applying the patch, output diffstat for the
diff --git a/builtin-apply.c b/builtin-apply.c
index 8c8162a..59834f0 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -12,6 +12,9 @@
#include "blob.h"
#include "delta.h"
#include "builtin.h"
+#ifndef NO_CURL
+#include "http.h"
+#endif
/*
* --check turns on checking that the working tree matches the
@@ -182,12 +185,47 @@ static void say_patch_name(FILE *output, const char *pre,
#define CHUNKSIZE (8192)
#define SLOP (16)
-static void read_patch_file(struct strbuf *sb, const char *filename)
+#ifndef NO_CURL
+static int used_http;
+
+static void read_patch_url(struct strbuf *sb, const char *url)
+{
+ struct active_request_slot *slot;
+ struct slot_results results;
+
+ if (! used_http) {
+ http_init();
+ used_http = 1;
+ }
+
+ slot = get_active_slot();
+ slot->results = &results;
+ curl_easy_setopt(slot->curl, CURLOPT_FILE, sb);
+ curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
+ curl_easy_setopt(slot->curl, CURLOPT_URL, url);
+ curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL);
+
+ if (start_active_slot(slot)) {
+ run_active_slot(slot);
+ if (results.curl_result != CURLE_OK)
+ die("git-apply: could not open %s", url);
+ }
+}
+#endif
+
+static void read_patch(struct strbuf *sb, const char *filename)
{
int fd;
if (!strcmp(filename, "-")) {
fd = 0;
+#ifndef NO_CURL
+ } else if (!strncmp(filename, "http://", 7) ||
+ !strncmp(filename, "https://", 8) ||
+ !strncmp(filename, "ftp://", 6)) {
+ read_patch_url(sb, filename);
+ return;
+#endif
} else {
fd = open(filename, O_RDONLY);
if (fd < 0)
@@ -199,13 +237,6 @@ static void read_patch_file(struct strbuf *sb, const char *filename)
die("git-apply: read returned %s", strerror(errno));
close(fd);
- /*
- * Make sure that we have some slop in the buffer
- * so that we can do speculative "memcmp" etc, and
- * see to it that it is NUL-filled.
- */
- strbuf_grow(sb, SLOP);
- memset(sb->buf + sb->len, 0, SLOP);
}
static unsigned long linelen(const char *buffer, unsigned long size)
@@ -2726,7 +2757,14 @@ static int apply_patch(const char *filename, int inaccurate_eof)
strbuf_init(&buf, 0);
patch_input_file = filename;
- read_patch_file(&buf, filename);
+ read_patch(&buf, filename);
+ /*
+ * Make sure that we have some slop in the buffer
+ * so that we can do speculative "memcmp" etc, and
+ * see to it that it is NUL-filled.
+ */
+ strbuf_grow(&buf, SLOP);
+ memset(buf.buf + buf.len, 0, SLOP);
offset = 0;
while (offset < buf.len) {
struct patch *patch;
@@ -2926,6 +2964,8 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
set_default_whitespace_mode(whitespace_option);
errs |= apply_patch(arg, inaccurate_eof);
}
+ if (used_http)
+ http_cleanup();
set_default_whitespace_mode(whitespace_option);
if (read_stdin)
errs |= apply_patch("-", inaccurate_eof);
--
1.5.3.7
^ permalink raw reply related
* [PATCH 1/4] Cleanup variables in http.[ch]
From: Mike Hommey @ 2007-12-09 17:04 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
Quite some variables defined as extern in http.h are only used in http.c,
and some others, only defined in http.c, were not static. Cleanup that.
Signed-off-by: Mike Hommey <mh@glandium.org>
---
http.c | 28 ++++++++++++++--------------
http.h | 18 ------------------
2 files changed, 14 insertions(+), 32 deletions(-)
diff --git a/http.c b/http.c
index e4aa9c1..146f626 100644
--- a/http.c
+++ b/http.c
@@ -4,31 +4,31 @@ int data_received;
int active_requests = 0;
#ifdef USE_CURL_MULTI
-int max_requests = -1;
-CURLM *curlm;
+static int max_requests = -1;
+static CURLM *curlm;
#endif
#ifndef NO_CURL_EASY_DUPHANDLE
-CURL *curl_default;
+static CURL *curl_default;
#endif
char curl_errorstr[CURL_ERROR_SIZE];
-int curl_ssl_verify = -1;
-char *ssl_cert = NULL;
+static int curl_ssl_verify = -1;
+static char *ssl_cert = NULL;
#if LIBCURL_VERSION_NUM >= 0x070902
-char *ssl_key = NULL;
+static char *ssl_key = NULL;
#endif
#if LIBCURL_VERSION_NUM >= 0x070908
-char *ssl_capath = NULL;
+static char *ssl_capath = NULL;
#endif
-char *ssl_cainfo = NULL;
-long curl_low_speed_limit = -1;
-long curl_low_speed_time = -1;
-int curl_ftp_no_epsv = 0;
-char *curl_http_proxy = NULL;
+static char *ssl_cainfo = NULL;
+static long curl_low_speed_limit = -1;
+static long curl_low_speed_time = -1;
+static int curl_ftp_no_epsv = 0;
+static char *curl_http_proxy = NULL;
-struct curl_slist *pragma_header;
+static struct curl_slist *pragma_header;
-struct active_request_slot *active_queue_head = NULL;
+static struct active_request_slot *active_queue_head = NULL;
size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb,
struct buffer *buffer)
diff --git a/http.h b/http.h
index 72abac2..fe1b0d1 100644
--- a/http.h
+++ b/http.h
@@ -80,24 +80,6 @@ extern void http_cleanup(void);
extern int data_received;
extern int active_requests;
-#ifndef NO_CURL_EASY_DUPHANDLE
-extern CURL *curl_default;
-#endif
extern char curl_errorstr[CURL_ERROR_SIZE];
-extern int curl_ssl_verify;
-extern char *ssl_cert;
-#if LIBCURL_VERSION_NUM >= 0x070902
-extern char *ssl_key;
-#endif
-#if LIBCURL_VERSION_NUM >= 0x070908
-extern char *ssl_capath;
-#endif
-extern char *ssl_cainfo;
-extern long curl_low_speed_limit;
-extern long curl_low_speed_time;
-
-extern struct curl_slist *pragma_header;
-extern struct curl_slist *no_range_header;
-
#endif /* HTTP_H */
--
1.5.3.7
^ permalink raw reply related
* [PATCH 2/4] Use strbuf in http code
From: Mike Hommey @ 2007-12-09 17:04 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
In-Reply-To: <1197219900-19334-1-git-send-email-mh@glandium.org>
Also, replace whitespaces with tabs in some places
Signed-off-by: Mike Hommey <mh@glandium.org>
---
While testing this, I noticed 3 things:
- CURL_MULTI makes the code very racy
- a lot of the code doesn't do anything useful without CURL_MULTI
- the code is redundant
So, if I have some time soon, I'll try to refactor all that.
http-push.c | 186 ++++++++++++++++++--------------------------------------
http-walker.c | 59 +++++++------------
http.c | 34 ++++------
http.h | 11 ++--
transport.c | 18 ++----
5 files changed, 107 insertions(+), 201 deletions(-)
diff --git a/http-push.c b/http-push.c
index 78283b4..e01b3a9 100644
--- a/http-push.c
+++ b/http-push.c
@@ -495,10 +495,10 @@ static void start_put(struct transfer_request *request)
memset(&stream, 0, sizeof(stream));
deflateInit(&stream, zlib_compression_level);
size = deflateBound(&stream, len + hdrlen);
- request->buffer.buffer = xmalloc(size);
+ strbuf_init(&request->buffer.buf, size);
/* Compress it */
- stream.next_out = request->buffer.buffer;
+ stream.next_out = (unsigned char *)request->buffer.buf.buf;
stream.avail_out = size;
/* First header.. */
@@ -515,8 +515,7 @@ static void start_put(struct transfer_request *request)
deflateEnd(&stream);
free(unpacked);
- request->buffer.size = stream.total_out;
- request->buffer.posn = 0;
+ request->buffer.buf.len = stream.total_out;
request->url = xmalloc(strlen(remote->url) +
strlen(request->lock->token) + 51);
@@ -538,7 +537,7 @@ static void start_put(struct transfer_request *request)
slot->callback_func = process_response;
slot->callback_data = request;
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &request->buffer);
- curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, request->buffer.size);
+ curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, request->buffer.buf.len);
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
@@ -1003,18 +1002,13 @@ static int fetch_indices(void)
{
unsigned char sha1[20];
char *url;
- struct buffer buffer;
+ struct strbuf buffer = STRBUF_INIT;
char *data;
int i = 0;
struct active_request_slot *slot;
struct slot_results results;
- data = xcalloc(1, 4096);
- buffer.size = 4096;
- buffer.posn = 0;
- buffer.buffer = data;
-
if (push_verbosely)
fprintf(stderr, "Getting pack list\n");
@@ -1030,7 +1024,7 @@ static int fetch_indices(void)
if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.curl_result != CURLE_OK) {
- free(buffer.buffer);
+ strbuf_release(&buffer);
free(url);
if (results.http_code == 404)
return 0;
@@ -1038,18 +1032,18 @@ static int fetch_indices(void)
return error("%s", curl_errorstr);
}
} else {
- free(buffer.buffer);
+ strbuf_release(&buffer);
free(url);
return error("Unable to start request");
}
free(url);
- data = buffer.buffer;
- while (i < buffer.posn) {
+ data = buffer.buf;
+ while (i < buffer.len) {
switch (data[i]) {
case 'P':
i++;
- if (i + 52 < buffer.posn &&
+ if (i + 52 < buffer.len &&
!prefixcmp(data + i, " pack-") &&
!prefixcmp(data + i + 46, ".pack\n")) {
get_sha1_hex(data + i + 6, sha1);
@@ -1064,7 +1058,7 @@ static int fetch_indices(void)
i++;
}
- free(buffer.buffer);
+ strbuf_release(&buffer);
return 0;
}
@@ -1115,16 +1109,11 @@ static char *quote_ref_url(const char *base, const char *ref)
int fetch_ref(char *ref, unsigned char *sha1)
{
- char *url;
- char hex[42];
- struct buffer buffer;
+ char *url;
+ struct strbuf buffer = STRBUF_INIT;
char *base = remote->url;
struct active_request_slot *slot;
struct slot_results results;
- buffer.size = 41;
- buffer.posn = 0;
- buffer.buffer = hex;
- hex[41] = '\0';
url = quote_ref_url(base, ref);
slot = get_active_slot();
@@ -1142,9 +1131,9 @@ int fetch_ref(char *ref, unsigned char *sha1)
return error("Unable to start request");
}
- hex[40] = '\0';
- get_sha1_hex(hex, sha1);
- return 0;
+ buffer.buf[40] = '\0';
+ get_sha1_hex(buffer.buf, sha1);
+ return 0;
}
static void one_remote_object(const char *hex)
@@ -1267,10 +1256,8 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
{
struct active_request_slot *slot;
struct slot_results results;
- struct buffer out_buffer;
- struct buffer in_buffer;
- char *out_data;
- char *in_data;
+ struct buffer out_buffer = { 0, STRBUF_INIT };
+ struct strbuf in_buffer = STRBUF_INIT;
char *url;
char *ep;
char timeout_header[25];
@@ -1312,16 +1299,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
ep = strchr(ep + 1, '/');
}
- out_buffer.size = strlen(LOCK_REQUEST) + strlen(git_default_email) - 2;
- out_data = xmalloc(out_buffer.size + 1);
- snprintf(out_data, out_buffer.size + 1, LOCK_REQUEST, git_default_email);
- out_buffer.posn = 0;
- out_buffer.buffer = out_data;
-
- in_buffer.size = 4096;
- in_data = xmalloc(in_buffer.size);
- in_buffer.posn = 0;
- in_buffer.buffer = in_data;
+ strbuf_addf(&out_buffer.buf, LOCK_REQUEST, git_default_email);
sprintf(timeout_header, "Timeout: Second-%ld", timeout);
dav_headers = curl_slist_append(dav_headers, timeout_header);
@@ -1330,7 +1308,7 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
slot = get_active_slot();
slot->results = &results;
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
- curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.size);
+ curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
@@ -1354,8 +1332,8 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
XML_SetElementHandler(parser, xml_start_tag,
xml_end_tag);
XML_SetCharacterDataHandler(parser, xml_cdata);
- result = XML_Parse(parser, in_buffer.buffer,
- in_buffer.posn, 1);
+ result = XML_Parse(parser, in_buffer.buf,
+ in_buffer.len, 1);
free(ctx.name);
if (result != XML_STATUS_OK) {
fprintf(stderr, "XML error: %s\n",
@@ -1369,8 +1347,8 @@ static struct remote_lock *lock_remote(const char *path, long timeout)
}
curl_slist_free_all(dav_headers);
- free(out_data);
- free(in_data);
+ strbuf_release(&out_buffer.buf);
+ strbuf_release(&in_buffer);
if (lock->token == NULL || lock->timeout <= 0) {
if (lock->token != NULL)
@@ -1521,10 +1499,8 @@ static void remote_ls(const char *path, int flags,
char *url = xmalloc(strlen(remote->url) + strlen(path) + 1);
struct active_request_slot *slot;
struct slot_results results;
- struct buffer in_buffer;
- struct buffer out_buffer;
- char *in_data;
- char *out_data;
+ struct strbuf in_buffer = STRBUF_INIT;
+ struct buffer out_buffer = { 0, STRBUF_INIT };
XML_Parser parser = XML_ParserCreate(NULL);
enum XML_Status result;
struct curl_slist *dav_headers = NULL;
@@ -1540,16 +1516,7 @@ static void remote_ls(const char *path, int flags,
sprintf(url, "%s%s", remote->url, path);
- out_buffer.size = strlen(PROPFIND_ALL_REQUEST);
- out_data = xmalloc(out_buffer.size + 1);
- snprintf(out_data, out_buffer.size + 1, PROPFIND_ALL_REQUEST);
- out_buffer.posn = 0;
- out_buffer.buffer = out_data;
-
- in_buffer.size = 4096;
- in_data = xmalloc(in_buffer.size);
- in_buffer.posn = 0;
- in_buffer.buffer = in_data;
+ strbuf_addf(&out_buffer.buf, PROPFIND_ALL_REQUEST);
dav_headers = curl_slist_append(dav_headers, "Depth: 1");
dav_headers = curl_slist_append(dav_headers, "Content-Type: text/xml");
@@ -1557,7 +1524,7 @@ static void remote_ls(const char *path, int flags,
slot = get_active_slot();
slot->results = &results;
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
- curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.size);
+ curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
@@ -1578,8 +1545,8 @@ static void remote_ls(const char *path, int flags,
XML_SetElementHandler(parser, xml_start_tag,
xml_end_tag);
XML_SetCharacterDataHandler(parser, xml_cdata);
- result = XML_Parse(parser, in_buffer.buffer,
- in_buffer.posn, 1);
+ result = XML_Parse(parser, in_buffer.buf,
+ in_buffer.len, 1);
free(ctx.name);
if (result != XML_STATUS_OK) {
@@ -1594,8 +1561,8 @@ static void remote_ls(const char *path, int flags,
free(ls.path);
free(url);
- free(out_data);
- free(in_buffer.buffer);
+ strbuf_release(&out_buffer.buf);
+ strbuf_release(&in_buffer);
curl_slist_free_all(dav_headers);
}
@@ -1616,29 +1583,15 @@ static int locking_available(void)
{
struct active_request_slot *slot;
struct slot_results results;
- struct buffer in_buffer;
- struct buffer out_buffer;
- char *in_data;
- char *out_data;
+ struct strbuf in_buffer = STRBUF_INIT;
+ struct buffer out_buffer = { 0, STRBUF_INIT };
XML_Parser parser = XML_ParserCreate(NULL);
enum XML_Status result;
struct curl_slist *dav_headers = NULL;
struct xml_ctx ctx;
int lock_flags = 0;
- out_buffer.size =
- strlen(PROPFIND_SUPPORTEDLOCK_REQUEST) +
- strlen(remote->url) - 2;
- out_data = xmalloc(out_buffer.size + 1);
- snprintf(out_data, out_buffer.size + 1,
- PROPFIND_SUPPORTEDLOCK_REQUEST, remote->url);
- out_buffer.posn = 0;
- out_buffer.buffer = out_data;
-
- in_buffer.size = 4096;
- in_data = xmalloc(in_buffer.size);
- in_buffer.posn = 0;
- in_buffer.buffer = in_data;
+ strbuf_addf(&out_buffer.buf, PROPFIND_SUPPORTEDLOCK_REQUEST, remote->url);
dav_headers = curl_slist_append(dav_headers, "Depth: 0");
dav_headers = curl_slist_append(dav_headers, "Content-Type: text/xml");
@@ -1646,7 +1599,7 @@ static int locking_available(void)
slot = get_active_slot();
slot->results = &results;
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
- curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.size);
+ curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
curl_easy_setopt(slot->curl, CURLOPT_FILE, &in_buffer);
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_buffer);
@@ -1666,8 +1619,8 @@ static int locking_available(void)
XML_SetUserData(parser, &ctx);
XML_SetElementHandler(parser, xml_start_tag,
xml_end_tag);
- result = XML_Parse(parser, in_buffer.buffer,
- in_buffer.posn, 1);
+ result = XML_Parse(parser, in_buffer.buf,
+ in_buffer.len, 1);
free(ctx.name);
if (result != XML_STATUS_OK) {
@@ -1681,8 +1634,8 @@ static int locking_available(void)
fprintf(stderr, "Unable to start PROPFIND request\n");
}
- free(out_data);
- free(in_buffer.buffer);
+ strbuf_release(&out_buffer.buf);
+ strbuf_release(&in_buffer);
curl_slist_free_all(dav_headers);
return lock_flags;
@@ -1800,30 +1753,20 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock)
{
struct active_request_slot *slot;
struct slot_results results;
- char *out_data;
char *if_header;
- struct buffer out_buffer;
+ struct buffer out_buffer = { 0, STRBUF_INIT };
struct curl_slist *dav_headers = NULL;
- int i;
if_header = xmalloc(strlen(lock->token) + 25);
sprintf(if_header, "If: (<opaquelocktoken:%s>)", lock->token);
dav_headers = curl_slist_append(dav_headers, if_header);
- out_buffer.size = 41;
- out_data = xmalloc(out_buffer.size + 1);
- i = snprintf(out_data, out_buffer.size + 1, "%s\n", sha1_to_hex(sha1));
- if (i != out_buffer.size) {
- fprintf(stderr, "Unable to initialize PUT request body\n");
- return 0;
- }
- out_buffer.posn = 0;
- out_buffer.buffer = out_data;
+ strbuf_addf(&out_buffer.buf, "%s\n", sha1_to_hex(sha1));
slot = get_active_slot();
slot->results = &results;
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &out_buffer);
- curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.size);
+ curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, out_buffer.buf.len);
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
@@ -1834,7 +1777,7 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock)
if (start_active_slot(slot)) {
run_active_slot(slot);
- free(out_data);
+ strbuf_release(&out_buffer.buf);
free(if_header);
if (results.curl_result != CURLE_OK) {
fprintf(stderr,
@@ -1844,7 +1787,7 @@ static int update_remote(unsigned char *sha1, struct remote_lock *lock)
return 0;
}
} else {
- free(out_data);
+ strbuf_release(&out_buffer.buf);
free(if_header);
fprintf(stderr, "Unable to start PUT request\n");
return 0;
@@ -2001,7 +1944,7 @@ static void mark_edges_uninteresting(struct commit_list *list)
static void add_remote_info_ref(struct remote_ls_ctx *ls)
{
- struct buffer *buf = (struct buffer *)ls->userData;
+ struct strbuf *buf = (struct strbuf *)ls->userData;
unsigned char remote_sha1[20];
struct object *o;
int len;
@@ -2046,17 +1989,14 @@ static void add_remote_info_ref(struct remote_ls_ctx *ls)
static void update_remote_info_refs(struct remote_lock *lock)
{
- struct buffer buffer;
+ struct buffer buffer = { 0, STRBUF_INIT };
struct active_request_slot *slot;
struct slot_results results;
char *if_header;
struct curl_slist *dav_headers = NULL;
- buffer.buffer = xcalloc(1, 4096);
- buffer.size = 4096;
- buffer.posn = 0;
remote_ls("refs/", (PROCESS_FILES | RECURSIVE),
- add_remote_info_ref, &buffer);
+ add_remote_info_ref, &buffer.buf);
if (!aborted) {
if_header = xmalloc(strlen(lock->token) + 25);
sprintf(if_header, "If: (<opaquelocktoken:%s>)", lock->token);
@@ -2065,7 +2005,7 @@ static void update_remote_info_refs(struct remote_lock *lock)
slot = get_active_slot();
slot->results = &results;
curl_easy_setopt(slot->curl, CURLOPT_INFILE, &buffer);
- curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, buffer.posn);
+ curl_easy_setopt(slot->curl, CURLOPT_INFILESIZE, buffer.buf.len);
curl_easy_setopt(slot->curl, CURLOPT_READFUNCTION, fread_buffer);
curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_null);
curl_easy_setopt(slot->curl, CURLOPT_CUSTOMREQUEST, DAV_PUT);
@@ -2074,8 +2014,6 @@ static void update_remote_info_refs(struct remote_lock *lock)
curl_easy_setopt(slot->curl, CURLOPT_PUT, 1);
curl_easy_setopt(slot->curl, CURLOPT_URL, lock->url);
- buffer.posn = 0;
-
if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.curl_result != CURLE_OK) {
@@ -2086,7 +2024,7 @@ static void update_remote_info_refs(struct remote_lock *lock)
}
free(if_header);
}
- free(buffer.buffer);
+ strbuf_release(&buffer.buf);
}
static int remote_exists(const char *path)
@@ -2097,12 +2035,12 @@ static int remote_exists(const char *path)
sprintf(url, "%s%s", remote->url, path);
- slot = get_active_slot();
+ slot = get_active_slot();
slot->results = &results;
- curl_easy_setopt(slot->curl, CURLOPT_URL, url);
- curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 1);
+ curl_easy_setopt(slot->curl, CURLOPT_URL, url);
+ curl_easy_setopt(slot->curl, CURLOPT_NOBODY, 1);
- if (start_active_slot(slot)) {
+ if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.http_code == 404)
return 0;
@@ -2120,17 +2058,13 @@ static int remote_exists(const char *path)
static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
{
char *url;
- struct buffer buffer;
+ struct strbuf buffer = STRBUF_INIT;
struct active_request_slot *slot;
struct slot_results results;
url = xmalloc(strlen(remote->url) + strlen(path) + 1);
sprintf(url, "%s%s", remote->url, path);
- buffer.size = 4096;
- buffer.posn = 0;
- buffer.buffer = xmalloc(buffer.size);
-
slot = get_active_slot();
slot->results = &results;
curl_easy_setopt(slot->curl, CURLOPT_FILE, &buffer);
@@ -2153,17 +2087,17 @@ static void fetch_symref(const char *path, char **symref, unsigned char *sha1)
*symref = NULL;
hashclr(sha1);
- if (buffer.posn == 0)
+ if (buffer.len == 0)
return;
/* If it's a symref, set the refname; otherwise try for a sha1 */
- if (!prefixcmp((char *)buffer.buffer, "ref: ")) {
- *symref = xmemdupz((char *)buffer.buffer + 5, buffer.posn - 6);
+ if (!prefixcmp((char *)buffer.buf, "ref: ")) {
+ *symref = xmemdupz((char *)buffer.buf + 5, buffer.len - 6);
} else {
- get_sha1_hex(buffer.buffer, sha1);
+ get_sha1_hex(buffer.buf, sha1);
}
- free(buffer.buffer);
+ strbuf_release(&buffer);
}
static int verify_merge_base(unsigned char *head_sha1, unsigned char *branch_sha1)
diff --git a/http-walker.c b/http-walker.c
index a3fb596..d925005 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -48,7 +48,7 @@ struct alternates_request {
struct walker *walker;
const char *base;
char *url;
- struct buffer *buffer;
+ struct strbuf *buffer;
struct active_request_slot *slot;
int http_specific;
};
@@ -475,7 +475,7 @@ static void process_alternates_response(void *callback_data)
if (alt_req->http_specific) {
if (slot->curl_result != CURLE_OK ||
- !alt_req->buffer->posn) {
+ !alt_req->buffer->len) {
/* Try reusing the slot to get non-http alternates */
alt_req->http_specific = 0;
@@ -503,12 +503,12 @@ static void process_alternates_response(void *callback_data)
}
fwrite_buffer(&null_byte, 1, 1, alt_req->buffer);
- alt_req->buffer->posn--;
- data = alt_req->buffer->buffer;
+ alt_req->buffer->len--;
+ data = alt_req->buffer->buf;
- while (i < alt_req->buffer->posn) {
+ while (i < alt_req->buffer->len) {
int posn = i;
- while (posn < alt_req->buffer->posn && data[posn] != '\n')
+ while (posn < alt_req->buffer->len && data[posn] != '\n')
posn++;
if (data[posn] == '\n') {
int okay = 0;
@@ -596,9 +596,8 @@ static void process_alternates_response(void *callback_data)
static void fetch_alternates(struct walker *walker, const char *base)
{
- struct buffer buffer;
+ struct strbuf buffer = STRBUF_INIT;
char *url;
- char *data;
struct active_request_slot *slot;
struct alternates_request alt_req;
struct walker_data *cdata = walker->data;
@@ -619,11 +618,6 @@ static void fetch_alternates(struct walker *walker, const char *base)
/* Start the fetch */
cdata->got_alternates = 0;
- data = xmalloc(4096);
- buffer.size = 4096;
- buffer.posn = 0;
- buffer.buffer = data;
-
if (walker->get_verbosely)
fprintf(stderr, "Getting alternates list for %s\n", base);
@@ -652,7 +646,7 @@ static void fetch_alternates(struct walker *walker, const char *base)
else
cdata->got_alternates = -1;
- free(data);
+ strbuf_release(&buffer);
free(url);
}
@@ -660,7 +654,7 @@ static int fetch_indices(struct walker *walker, struct alt_base *repo)
{
unsigned char sha1[20];
char *url;
- struct buffer buffer;
+ struct strbuf buffer = STRBUF_INIT;
char *data;
int i = 0;
@@ -670,11 +664,6 @@ static int fetch_indices(struct walker *walker, struct alt_base *repo)
if (repo->got_indices)
return 0;
- data = xmalloc(4096);
- buffer.size = 4096;
- buffer.posn = 0;
- buffer.buffer = data;
-
if (walker->get_verbosely)
fprintf(stderr, "Getting pack list for %s\n", repo->base);
@@ -690,28 +679,27 @@ static int fetch_indices(struct walker *walker, struct alt_base *repo)
if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.curl_result != CURLE_OK) {
+ strbuf_release(&buffer);
if (missing_target(&results)) {
repo->got_indices = 1;
- free(buffer.buffer);
return 0;
} else {
repo->got_indices = 0;
- free(buffer.buffer);
return error("%s", curl_errorstr);
}
}
} else {
repo->got_indices = 0;
- free(buffer.buffer);
+ strbuf_release(&buffer);
return error("Unable to start request");
}
- data = buffer.buffer;
- while (i < buffer.posn) {
+ data = buffer.buf;
+ while (i < buffer.len) {
switch (data[i]) {
case 'P':
i++;
- if (i + 52 <= buffer.posn &&
+ if (i + 52 <= buffer.len &&
!prefixcmp(data + i, " pack-") &&
!prefixcmp(data + i + 46, ".pack\n")) {
get_sha1_hex(data + i + 6, sha1);
@@ -720,13 +708,13 @@ static int fetch_indices(struct walker *walker, struct alt_base *repo)
break;
}
default:
- while (i < buffer.posn && data[i] != '\n')
+ while (i < buffer.len && data[i] != '\n')
i++;
}
i++;
}
- free(buffer.buffer);
+ strbuf_release(&buffer);
repo->got_indices = 1;
return 0;
}
@@ -958,17 +946,12 @@ static char *quote_ref_url(const char *base, const char *ref)
static int fetch_ref(struct walker *walker, char *ref, unsigned char *sha1)
{
- char *url;
- char hex[42];
- struct buffer buffer;
+ char *url;
+ struct strbuf buffer = STRBUF_INIT;
struct walker_data *data = walker->data;
const char *base = data->alt->base;
struct active_request_slot *slot;
struct slot_results results;
- buffer.size = 41;
- buffer.posn = 0;
- buffer.buffer = hex;
- hex[41] = '\0';
url = quote_ref_url(base, ref);
slot = get_active_slot();
@@ -986,9 +969,9 @@ static int fetch_ref(struct walker *walker, char *ref, unsigned char *sha1)
return error("Unable to start request");
}
- hex[40] = '\0';
- get_sha1_hex(hex, sha1);
- return 0;
+ buffer.buf[40] = '\0';
+ get_sha1_hex(buffer.buf, sha1);
+ return 0;
}
static void cleanup(struct walker *walker)
diff --git a/http.c b/http.c
index 146f626..2d0b46d 100644
--- a/http.c
+++ b/http.c
@@ -34,31 +34,25 @@ size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb,
struct buffer *buffer)
{
size_t size = eltsize * nmemb;
- if (size > buffer->size - buffer->posn)
- size = buffer->size - buffer->posn;
- memcpy(ptr, (char *) buffer->buffer + buffer->posn, size);
+ if (size > buffer->buf.len - buffer->posn)
+ size = buffer->buf.len - buffer->posn;
+ memcpy(ptr, (char *) buffer->buf.buf + buffer->posn, size);
buffer->posn += size;
+
return size;
}
size_t fwrite_buffer(const void *ptr, size_t eltsize,
- size_t nmemb, struct buffer *buffer)
+ size_t nmemb, struct strbuf *buffer)
{
size_t size = eltsize * nmemb;
- if (size > buffer->size - buffer->posn) {
- buffer->size = buffer->size * 3 / 2;
- if (buffer->size < buffer->posn + size)
- buffer->size = buffer->posn + size;
- buffer->buffer = xrealloc(buffer->buffer, buffer->size);
- }
- memcpy((char *) buffer->buffer + buffer->posn, ptr, size);
- buffer->posn += size;
+ strbuf_add(buffer, ptr, size);
data_received++;
return size;
}
size_t fwrite_null(const void *ptr, size_t eltsize,
- size_t nmemb, struct buffer *buffer)
+ size_t nmemb, struct strbuf *buffer)
{
data_received++;
return eltsize * nmemb;
@@ -508,8 +502,8 @@ void run_active_slot(struct active_request_slot *slot)
static void closedown_active_slot(struct active_request_slot *slot)
{
- active_requests--;
- slot->in_use = 0;
+ active_requests--;
+ slot->in_use = 0;
}
void release_active_slot(struct active_request_slot *slot)
@@ -530,7 +524,7 @@ void release_active_slot(struct active_request_slot *slot)
static void finish_active_slot(struct active_request_slot *slot)
{
closedown_active_slot(slot);
- curl_easy_getinfo(slot->curl, CURLINFO_HTTP_CODE, &slot->http_code);
+ curl_easy_getinfo(slot->curl, CURLINFO_HTTP_CODE, &slot->http_code);
if (slot->finished != NULL)
(*slot->finished) = 1;
@@ -541,10 +535,10 @@ static void finish_active_slot(struct active_request_slot *slot)
slot->results->http_code = slot->http_code;
}
- /* Run callback if appropriate */
- if (slot->callback_func != NULL) {
- slot->callback_func(slot->callback_data);
- }
+ /* Run callback if appropriate */
+ if (slot->callback_func != NULL) {
+ slot->callback_func(slot->callback_data);
+ }
}
void finish_all_active_slots(void)
diff --git a/http.h b/http.h
index fe1b0d1..bf3f12c 100644
--- a/http.h
+++ b/http.h
@@ -6,6 +6,8 @@
#include <curl/curl.h>
#include <curl/easy.h>
+#include "strbuf.h"
+
#if LIBCURL_VERSION_NUM >= 0x071000
#define USE_CURL_MULTI
#define DEFAULT_MAX_REQUESTS 5
@@ -48,18 +50,17 @@ struct active_request_slot
struct buffer
{
- size_t posn;
- size_t size;
- void *buffer;
+ struct strbuf buf;
+ size_t posn;
};
/* Curl request read/write callbacks */
extern size_t fread_buffer(void *ptr, size_t eltsize, size_t nmemb,
struct buffer *buffer);
extern size_t fwrite_buffer(const void *ptr, size_t eltsize,
- size_t nmemb, struct buffer *buffer);
+ size_t nmemb, struct strbuf *buffer);
extern size_t fwrite_null(const void *ptr, size_t eltsize,
- size_t nmemb, struct buffer *buffer);
+ size_t nmemb, struct strbuf *buffer);
/* Slot lifecycle functions */
extern struct active_request_slot *get_active_slot(void);
diff --git a/transport.c b/transport.c
index 58e66f6..22234e8 100644
--- a/transport.c
+++ b/transport.c
@@ -441,7 +441,7 @@ static int missing__target(int code, int result)
static struct ref *get_refs_via_curl(struct transport *transport)
{
- struct buffer buffer;
+ struct strbuf buffer = STRBUF_INIT;
char *data, *start, *mid;
char *ref_name;
char *refs_url;
@@ -454,11 +454,6 @@ static struct ref *get_refs_via_curl(struct transport *transport)
struct ref *ref = NULL;
struct ref *last_ref = NULL;
- data = xmalloc(4096);
- buffer.size = 4096;
- buffer.posn = 0;
- buffer.buffer = data;
-
refs_url = xmalloc(strlen(transport->url) + 11);
sprintf(refs_url, "%s/info/refs", transport->url);
@@ -477,27 +472,26 @@ static struct ref *get_refs_via_curl(struct transport *transport)
if (start_active_slot(slot)) {
run_active_slot(slot);
if (results.curl_result != CURLE_OK) {
+ strbuf_release(&buffer);
if (missing_target(&results)) {
- free(buffer.buffer);
return NULL;
} else {
- free(buffer.buffer);
error("%s", curl_errorstr);
return NULL;
}
}
} else {
- free(buffer.buffer);
+ strbuf_release(&buffer);
error("Unable to start request");
return NULL;
}
http_cleanup();
- data = buffer.buffer;
+ data = buffer.buf;
start = NULL;
mid = data;
- while (i < buffer.posn) {
+ while (i < buffer.len) {
if (!start)
start = &data[i];
if (data[i] == '\t')
@@ -520,7 +514,7 @@ static struct ref *get_refs_via_curl(struct transport *transport)
i++;
}
- free(buffer.buffer);
+ strbuf_release(&buffer);
return refs;
}
--
1.5.3.7
^ permalink raw reply related
* [PATCH 3/4] Move the file read logic to read_patch_file() in builtin-apply.c
From: Mike Hommey @ 2007-12-09 17:04 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
In-Reply-To: <1197219900-19334-2-git-send-email-mh@glandium.org>
This will allow to extend the read logic further. We also return a better
error message than usage() when the given filename can't be opened, and
avoid whitespace options not being set when reading from stdin with the
"-" argument as a side effect.
Signed-off-by: Mike Hommey <mh@glandium.org>
---
builtin-apply.c | 32 +++++++++++++++++---------------
1 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/builtin-apply.c b/builtin-apply.c
index f2e9a33..8c8162a 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -182,11 +182,23 @@ static void say_patch_name(FILE *output, const char *pre,
#define CHUNKSIZE (8192)
#define SLOP (16)
-static void read_patch_file(struct strbuf *sb, int fd)
+static void read_patch_file(struct strbuf *sb, const char *filename)
{
+ int fd;
+
+ if (!strcmp(filename, "-")) {
+ fd = 0;
+ } else {
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ die("git-apply: could not open %s: %s", filename,
+ strerror(errno));
+ }
+
if (strbuf_read(sb, fd, 0) < 0)
die("git-apply: read returned %s", strerror(errno));
+ close(fd);
/*
* Make sure that we have some slop in the buffer
* so that we can do speculative "memcmp" etc, and
@@ -2705,7 +2717,7 @@ static void prefix_patches(struct patch *p)
}
}
-static int apply_patch(int fd, const char *filename, int inaccurate_eof)
+static int apply_patch(const char *filename, int inaccurate_eof)
{
size_t offset;
struct strbuf buf;
@@ -2714,7 +2726,7 @@ static int apply_patch(int fd, const char *filename, int inaccurate_eof)
strbuf_init(&buf, 0);
patch_input_file = filename;
- read_patch_file(&buf, fd);
+ read_patch_file(&buf, filename);
offset = 0;
while (offset < buf.len) {
struct patch *patch;
@@ -2807,13 +2819,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
char *end;
- int fd;
- if (!strcmp(arg, "-")) {
- errs |= apply_patch(0, "<stdin>", inaccurate_eof);
- read_stdin = 0;
- continue;
- }
if (!prefixcmp(arg, "--exclude=")) {
struct excludes *x = xmalloc(sizeof(*x));
x->path = arg + 10;
@@ -2916,17 +2922,13 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
if (0 < prefix_length)
arg = prefix_filename(prefix, prefix_length, arg);
- fd = open(arg, O_RDONLY);
- if (fd < 0)
- usage(apply_usage);
read_stdin = 0;
set_default_whitespace_mode(whitespace_option);
- errs |= apply_patch(fd, arg, inaccurate_eof);
- close(fd);
+ errs |= apply_patch(arg, inaccurate_eof);
}
set_default_whitespace_mode(whitespace_option);
if (read_stdin)
- errs |= apply_patch(0, "<stdin>", inaccurate_eof);
+ errs |= apply_patch("-", inaccurate_eof);
if (whitespace_error) {
if (squelch_whitespace_errors &&
squelch_whitespace_errors < whitespace_error) {
--
1.5.3.7
^ permalink raw reply related
* Re: [PATCH 2/2] Add support for URLs to git-apply
From: Mike Hommey @ 2007-12-09 17:02 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
In-Reply-To: <1197194672-28568-2-git-send-email-mh@glandium.org>
On Sun, Dec 09, 2007 at 11:04:32AM +0100, Mike Hommey wrote:
> Instead of doing several "wget -O - url | git-apply -" in a raw, you now
> can just git-apply url1 url2 ...
>
> Signed-off-by: Mike Hommey <mh@glandium.org>
> ---
>
> After spending an afternoon wgetting patches to applying them, I got fed up
> and just added basic url support to git-apply. Note that the fwrite_strbuf
> function should just live in http.c, but until the http api is fully switched
> to use strbufs instead of its struct buffer (which I'm planning to do), it
> can stay like this.
I'm going to resend these 2 patches, with some others that do some changes
to the http code.
Mike
^ permalink raw reply
* Re: [PATCH] don't mention index refreshing side effect in git-status docs
From: Jonathan del Strother @ 2007-12-09 16:16 UTC (permalink / raw)
To: git
In-Reply-To: <20071209082133.GA2257@coredump.intra.peff.net>
On Dec 9, 2007 8:21 AM, Jeff King <peff@peff.net> wrote:
> The tip about speeding up subsequent operations is now
> obsolete; since aecbf914, git-diff now squelches empty diffs
> and performs an automatic refresh.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> This is on top of my other patches to the git-status docs.
>
> I don't see any reason to mention this side effect at all. Those who
> know enough to set diff.autorefreshindex presumably know what they are
> doing, and the removed paragraph is a bit confusing to those who don't.
>
... I wasn't aware the index needed refreshing. This might be
totally unrelated to the present conversation, but the GIT-VERSION-GEN
script occasionally gives me spurious 'dirty' results (eg when a file
timestamp changes despite the content having changed). Should it
perhaps be running "git update-index --refresh" before it runs "git
diff-index --name-only HEAD" ?
^ permalink raw reply
* Re: Where has "git ls-remote" reference pattern matching gone?
From: Eyvind Bernhardsen @ 2007-12-09 15:38 UTC (permalink / raw)
To: Daniel Barkalow; +Cc: Junio C Hamano, git
In-Reply-To: <Pine.LNX.4.64.0712082048570.5349@iabervon.org>
On 9. des.. 2007, at 03.20, Daniel Barkalow wrote:
> On Sat, 8 Dec 2007, Junio C Hamano wrote:
>
>> Eyvind Bernhardsen <eyvind-git@orakel.ntnu.no> writes:
>>
>>> ls-remote was recently made a builtin; was reference filtering
>>> deliberately removed, or was it just lost in translation from the
>>> shell script?
>>
>> I suspect that to be the case. Daniel, I think this is yours.
>
> Ah, sure enough. I didn't see that feature there, I guess. Am I
> right that
> it's supposed to have "git ls-remote origin db/*" return refs of the
> form "*/db/*", interpreted as for globs?
>
> Eyvind: can I get a test case? I haven't ever used this feature, and
> I'm
> not sure I'll implement it correctly.
I've noticed that a fix made it to master already; that's fast work by
you and Junio! Unfortunately, it fails the test case I was going to
suggest, which is the one in the ls-remote manpage (see my response in
the patch thread).
I haven't used the ref matching for anything (yet), so I don't have
any other test cases.
Eyvind Bernhardsen
^ permalink raw reply
* Re: [PATCH] Restore ls-remote reference pattern matching
From: Eyvind Bernhardsen @ 2007-12-09 15:31 UTC (permalink / raw)
To: Sergey Vlasov; +Cc: Junio C Hamano, git
In-Reply-To: <20071209162632.a16bfd6e.vsu@altlinux.ru>
On 9. des.. 2007, at 14.26, Sergey Vlasov wrote:
> This still does not match the behavior of the old shell implementation
> completely - because $pat was not quoted, shell pattern characters in
> $pat worked, and things like "git ls-remote . 'refs/heads/something--
> *'"
> were possible (and used in some of my scripts), so a full fnmatch()
> call is still needed.
The example in the ls-remote manpage ("git ls-remote --tags <remote> v
\*") also fails because of this.
Eyvind Bernhardsen
^ permalink raw reply
* Re: Something is broken in repack
From: Jon Smirl @ 2007-12-09 15:19 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Nicolas Pitre, Git Mailing List
In-Reply-To: <7vprxgs36w.fsf@gitster.siamese.dyndns.org>
On 12/9/07, Junio C Hamano <gitster@pobox.com> wrote:
> Junio C Hamano <gitster@pobox.com> writes:
>
> > Nicolas Pitre <nico@cam.org> writes:
> >
> >> On Fri, 7 Dec 2007, Jon Smirl wrote:
> >>
> >>> Starting with a 2GB pack of the same data my process size only grew to
> >>> 3GB with 2GB of mmaps.
> >>
> >> Which is quite reasonable, even if the same issue might still be there.
> >>
> >> So the problem seems to be related to the pack access code and not the
> >> repack code. And it must have something to do with the number of deltas
> >> being replayed. And because the repack is attempting delta compression
> >> roughly from newest to oldest, and because old objects are typically in
> >> a deeper delta chain, then this might explain the logarithmic slowdown.
> >>
> >> So something must be wrong with the delta cache in sha1_file.c somehow.
> >
> > I was reaching the same conclusion but haven't managed to spot anything
> > blatantly wrong in that area. Will need to dig more.
>
> Does this problem have correlation with the use of threads? Do you see
> the same bloat with or without THREADED_DELTA_SEARCH defined?
>
I just started a non-threaded one. It will be four or five hours
before it finishes.
--
Jon Smirl
jonsmirl@gmail.com
^ permalink raw reply
* Re: [PATCH] Restore ls-remote reference pattern matching
From: Sergey Vlasov @ 2007-12-09 13:26 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Eyvind Bernhardsen
In-Reply-To: <7v8x44tl7q.fsf@gitster.siamese.dyndns.org>
[-- Attachment #1: Type: text/plain, Size: 1414 bytes --]
On Sat, 08 Dec 2007 22:51:05 -0800 Junio C Hamano wrote:
[...]
> for pat
> do
> case "/$path" in
> */$pat )
> match=yes
> break ;;
> esac
> done
[...]
> +/*
> + * pattern is a list of tail-part of accepted refnames. Is there one
> + * among then that is a suffix of the path? Directory boundary must
> + * be honored when doing this match. IOW, patterns "master" and
> + * "sa/master" both match path "refs/hold/sa/master". On the other
> + * hand, path "refs/hold/foosa/master" is matched by "master" but not
> + * by "sa/master".
> + */
> +
> +static int tail_match(const char **pattern, const char *path)
> +{
> + int pathlen;
> + const char *p;
> +
> + if (!*pattern)
> + return 1; /* no restriction */
> +
> + for (pathlen = strlen(path); (p = *pattern); pattern++) {
> + int pfxlen = pathlen - strlen(p);
> + if (pfxlen < 0)
> + continue; /* pattern is longer, will never match */
> + if (strcmp(path + pfxlen, p))
> + continue; /* no tail match */
> + if (!pfxlen || path[pfxlen - 1] == '/')
> + return 1; /* fully match at directory boundary */
> + }
> + return 0;
> +}
This still does not match the behavior of the old shell implementation
completely - because $pat was not quoted, shell pattern characters in
$pat worked, and things like "git ls-remote . 'refs/heads/something--*'"
were possible (and used in some of my scripts), so a full fnmatch()
call is still needed.
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply
* Re: StGit kha/experimental branch updated
From: Karl Hasselström @ 2007-12-09 13:11 UTC (permalink / raw)
To: Catalin Marinas; +Cc: David Kågedal, git
In-Reply-To: <20071130064938.GA19892@diana.vm.bytemark.co.uk>
Even more things polished now, to the point that I think this could be
merged soon (but after 0.14, obviously).
The most recent fixes are:
* Say "current" and "patched" in conflict markers instead of the
trees' sha1s; this was a regression introduced by the conflict
series.
* All the various "top" and "bottom" files are written again, for
backwards compatibility.
Testing would be much appreciated.
---
The following changes since commit e2c86cdeafe3d8e1f58117c16a17b0438e4d64b1:
Catalin Marinas (1):
Allow only certain gitk exit codes as valid
are available in the git repository at:
git://repo.or.cz/stgit/kha.git experimental
David Kågedal (9):
Check bottom and invariants
Remove the 'bottom' field
Remove the 'top' field
Split git.merge into two functions
Leave working dir and index alone after failed (conflicting) push
Added a test case to check what happens when push finds a conflict
Simplify merge_recursive
Use the output from merge-recursive to list conflicts
Ask git about unmerged files
Karl Hasselström (22):
Write removed fields for backwards compatibility
Nicer conflict markers
Better error message if merge fails
Fix "stg resolved" to work with new conflict representation
Refactoring: pass more than one file to resolved()
We keep the different stages of a conflict in the index now
"stg status --reset" is not needed anymore
Remove "stg add"
Remove "stg rm"
Remove "stg cp"
Remove "stg resolved"
New StGit core infrastructure: repository operations
Write metadata files used by the old infrastructure
Upgrade older stacks to newest version
Let "stg clean" use the new infrastructure
Add "stg coalesce"
Let "stg applied" and "stg unapplied" use the new infrastructure
Teach the new infrastructure about the index and worktree
Let "stg clean" use the new transaction primitives
Let "stg goto" use the new infrastructure
Convert "stg uncommit" to the new infrastructure
New infrastructure: Make sure that the branch is initialized
Documentation/stg-cp.txt | 63 -------
Documentation/stg.txt | 2 -
Documentation/tutorial.txt | 31 ++--
contrib/stgit-completion.bash | 4 +-
examples/gitconfig | 19 +--
setup.py | 2 +-
stgit/commands/add.py | 44 -----
stgit/commands/applied.py | 27 ++--
stgit/commands/clean.py | 49 ++----
stgit/commands/coalesce.py | 112 ++++++++++++
stgit/commands/common.py | 39 ++---
stgit/commands/copy.py | 45 -----
stgit/commands/goto.py | 52 ++----
stgit/commands/pick.py | 2 +-
stgit/commands/resolved.py | 94 ----------
stgit/commands/rm.py | 48 -----
stgit/commands/status.py | 31 ++--
stgit/commands/sync.py | 1 -
stgit/commands/unapplied.py | 23 ++--
stgit/commands/uncommit.py | 79 ++++-----
stgit/config.py | 1 -
stgit/git.py | 75 +++++----
stgit/gitmergeonefile.py | 97 +----------
stgit/lib/__init__.py | 18 ++
stgit/lib/git.py | 387 +++++++++++++++++++++++++++++++++++++++++
stgit/lib/stack.py | 176 +++++++++++++++++++
stgit/lib/stackupgrade.py | 98 +++++++++++
stgit/lib/transaction.py | 195 +++++++++++++++++++++
stgit/main.py | 10 +-
stgit/run.py | 3 +
stgit/stack.py | 156 ++++-------------
stgit/utils.py | 24 +++
t/t0002-status.sh | 15 +-
t/t1200-push-modified.sh | 2 +-
t/t1202-push-undo.sh | 6 +-
t/t1203-push-conflict.sh | 70 ++++++++
t/t1204-pop-keep.sh | 2 +-
t/t1205-push-subdir.sh | 8 +-
t/t1300-uncommit.sh | 4 +-
t/t1301-repair.sh | 2 +-
t/t1400-patch-history.sh | 4 +-
t/t1500-float.sh | 14 +-
t/t1600-delete-one.sh | 12 +-
t/t1601-delete-many.sh | 2 +-
t/t1700-goto-top.sh | 2 +-
t/t2000-sync.sh | 12 +-
t/t2100-pull-policy-fetch.sh | 4 +-
t/t2101-pull-policy-pull.sh | 4 +-
t/t2102-pull-policy-rebase.sh | 4 +-
t/t2300-refresh-subdir.sh | 2 +-
t/t2600-coalesce.sh | 31 ++++
51 files changed, 1393 insertions(+), 814 deletions(-)
delete mode 100644 Documentation/stg-cp.txt
delete mode 100644 stgit/commands/add.py
create mode 100644 stgit/commands/coalesce.py
delete mode 100644 stgit/commands/copy.py
delete mode 100644 stgit/commands/resolved.py
delete mode 100644 stgit/commands/rm.py
create mode 100644 stgit/lib/__init__.py
create mode 100644 stgit/lib/git.py
create mode 100644 stgit/lib/stack.py
create mode 100644 stgit/lib/stackupgrade.py
create mode 100644 stgit/lib/transaction.py
create mode 100755 t/t1203-push-conflict.sh
create mode 100755 t/t2600-coalesce.sh
--
Karl Hasselström, kha@treskal.com
www.treskal.com/kalle
^ permalink raw reply
* [PATCH] autoconf: Check autoconf version (ASCIIDOC8)
From: Jakub Narebski @ 2007-12-09 12:57 UTC (permalink / raw)
To: git; +Cc: Jakub Narebski
Check for asciidoc, and if it exists check asciidoc version, setting
ASCIIDOC8 when needed. Currently it just runs asciidoc in asciidoc7
compatibility mode (see: Documentation/Makefile).
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
Hmmm... perhaps ASCIIDOC8 should be called ASCIIDOC7COMPATIBILITY?
We should revisit Makefiles and configure.ac when asciidoc 9 gets
released.
This should be "git portability" portable, even if it is not portable
according to "instanely autoconf-like portable" rules ;-)
config.mak.in | 2 ++
configure.ac | 21 +++++++++++++++++++++
2 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/config.mak.in b/config.mak.in
index 7d5df9b..759470a 100644
--- a/config.mak.in
+++ b/config.mak.in
@@ -7,6 +7,7 @@ AR = @AR@
TAR = @TAR@
#INSTALL = @INSTALL@ # needs install-sh or install.sh in sources
TCLTK_PATH = @TCLTK_PATH@
+ASCIIDOC=@ASCIIDOC@
prefix = @prefix@
exec_prefix = @exec_prefix@
@@ -23,6 +24,7 @@ VPATH = @srcdir@
export exec_prefix mandir
export srcdir VPATH
+ASCIIDOC8=@ASCIIDOC8@
NEEDS_SSL_WITH_CRYPTO=@NEEDS_SSL_WITH_CRYPTO@
NO_OPENSSL=@NO_OPENSSL@
NO_CURL=@NO_CURL@
diff --git a/configure.ac b/configure.ac
index dd4b4eb..6f641e3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -122,6 +122,27 @@ if test -z "$NO_TCLTK"; then
AC_SUBST(TCLTK_PATH)
fi
fi
+AC_CHECK_PROGS(ASCIIDOC, [asciidoc])
+if test -n "$ASCIIDOC"; then
+ AC_MSG_CHECKING([for asciidoc version])
+ asciidoc_version=`$ASCIIDOC --version 2>&1`
+ case "${asciidoc_version}" in
+ asciidoc' '8*)
+ ASCIIDOC8=YesPlease
+ AC_MSG_RESULT([${asciidoc_version} > 7])
+ ;;
+ asciidoc' '7*)
+ ASCIIDOC8=
+ AC_MSG_RESULT([${asciidoc_version}])
+ ;;
+ *)
+ ASCIIDOC8=
+ AC_MSG_RESULT([${asciidoc_version} (unknown)])
+ ;;
+ esac
+fi
+AC_SUBST(ASCIIDOC8)
+
## Checks for libraries.
AC_MSG_NOTICE([CHECKS for libraries])
--
1.5.3.7
^ permalink raw reply related
* [PATCH] Interactive editor tests for commit-msg hook
From: Wincent Colaiuta @ 2007-12-09 12:52 UTC (permalink / raw)
To: git; +Cc: gitster, krh, Wincent Colaiuta
Supplement the existing tests for the commit-msg hook (which all use
"git commit -m") with tests which use an interactive editor (no -m
switch) to ensure that all code paths get tested.
Signed-off-by: Wincent Colaiuta <win@wincent.com>
---
I didn't add similar tests for the pre-commit hook because I don't
think that's an interesting code path; we don't care about the commit
message in that case, only whether the commit is allowed to proceed or
not.
t/t7504-commit-msg-hook.sh | 72 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 72 insertions(+), 0 deletions(-)
diff --git a/t/t7504-commit-msg-hook.sh b/t/t7504-commit-msg-hook.sh
index 17aad7c..e154bab 100755
--- a/t/t7504-commit-msg-hook.sh
+++ b/t/t7504-commit-msg-hook.sh
@@ -9,11 +9,33 @@ test_expect_success "with no hook" \
git add file &&
git commit -m 'first'"
+# set up fake editor for interactive editing
+cat > fake-editor <<'EOF'
+#!/bin/sh
+cp FAKE_MSG "$1"
+exit 0
+EOF
+chmod +x fake-editor
+FAKE_EDITOR="$(pwd)/fake-editor"
+export FAKE_EDITOR
+
+test_expect_success "with no hook (editor)" \
+ "echo 'more foo' >> file &&
+ git add file &&
+ echo 'more foo' > FAKE_MSG &&
+ GIT_EDITOR="$FAKE_EDITOR" git commit"
+
test_expect_success "--no-verify with no hook" \
"echo 'bar' > file &&
git add file &&
git commit --no-verify -m 'bar'"
+test_expect_success "--no-verify with no hook (editor)" \
+ "echo 'more bar' > file &&
+ git add file &&
+ echo 'more bar' > FAKE_MSG &&
+ GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify"
+
# now install hook that always succeeds
HOOKDIR="$(git rev-parse --git-dir)/hooks"
HOOK="$HOOKDIR/commit-msg"
@@ -29,11 +51,23 @@ test_expect_success "with succeeding hook" \
git add file &&
git commit -m 'more'"
+test_expect_success "with succeeding hook (editor)" \
+ "echo 'more more' >> file &&
+ git add file &&
+ echo 'more more' > FAKE_MSG &&
+ GIT_EDITOR="$FAKE_EDITOR" git commit"
+
test_expect_success "--no-verify with succeeding hook" \
"echo 'even more' >> file &&
git add file &&
git commit --no-verify -m 'even more'"
+test_expect_success "--no-verify with succeeding hook (editor)" \
+ "echo 'even more more' >> file &&
+ git add file &&
+ echo 'even more more' > FAKE_MSG &&
+ GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify"
+
# now a hook that fails
cat > "$HOOK" <<EOF
#!/bin/sh
@@ -45,22 +79,46 @@ test_expect_failure "with failing hook" \
git add file &&
git commit -m 'another'"
+test_expect_failure "with failing hook (editor)" \
+ "echo 'more another' >> file &&
+ git add file &&
+ echo 'more another' > FAKE_MSG &&
+ GIT_EDITOR="$FAKE_EDITOR" git commit"
+
test_expect_success "--no-verify with failing hook" \
"echo 'stuff' >> file &&
git add file &&
git commit --no-verify -m 'stuff'"
+test_expect_success "--no-verify with failing hook (editor)" \
+ "echo 'more stuff' >> file &&
+ git add file &&
+ echo 'more stuff' > FAKE_MSG &&
+ GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify"
+
chmod -x "$HOOK"
test_expect_success "with non-executable hook" \
"echo 'content' >> file &&
git add file &&
git commit -m 'content'"
+test_expect_success "with non-executable hook (editor)" \
+ "echo 'content again' >> file &&
+ git add file &&
+ echo 'content again' > FAKE_MSG &&
+ GIT_EDITOR="$FAKE_EDITOR" git commit -m 'content again'"
+
test_expect_success "--no-verify with non-executable hook" \
"echo 'more content' >> file &&
git add file &&
git commit --no-verify -m 'more content'"
+test_expect_success "--no-verify with non-executable hook (editor)" \
+ "echo 'even more content' >> file &&
+ git add file &&
+ echo 'even more content' > FAKE_MSG &&
+ GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify"
+
# now a hook that edits the commit message
cat > "$HOOK" <<'EOF'
#!/bin/sh
@@ -79,10 +137,24 @@ test_expect_success "hook edits commit message" \
git commit -m 'additional' &&
commit_msg_is 'new message'"
+test_expect_success "hook edits commit message (editor)" \
+ "echo 'additional content' >> file &&
+ git add file &&
+ echo 'additional content' > FAKE_MSG &&
+ GIT_EDITOR="$FAKE_EDITOR" git commit &&
+ commit_msg_is 'new message'"
+
test_expect_success "hook doesn't edit commit message" \
"echo 'plus' >> file &&
git add file &&
git commit --no-verify -m 'plus' &&
commit_msg_is 'plus'"
+test_expect_success "hook doesn't edit commit message (editor)" \
+ "echo 'more plus' >> file &&
+ git add file &&
+ echo 'more plus' > FAKE_MSG &&
+ GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify &&
+ commit_msg_is 'more plus'"
+
test_done
--
1.5.3.7.1116.gf11de
^ permalink raw reply related
* Re: [PATCH 3/3] Fix commit-msg hook to allow editing
From: Wincent Colaiuta @ 2007-12-09 12:22 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, krh
In-Reply-To: <7vtzmss58h.fsf@gitster.siamese.dyndns.org>
El 9/12/2007, a las 8:21, Junio C Hamano escribió:
> IOW, how about something like this?
>
> ---
>
> builtin-commit.c | 9 +++++----
> builtin-tag.c | 2 ++
> 2 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/builtin-commit.c b/builtin-commit.c
> index 2032ca3..30a9deb 100644
> --- a/builtin-commit.c
> +++ b/builtin-commit.c
> @@ -787,16 +787,17 @@ int cmd_commit(int argc, const char **argv,
> const char *prefix)
> char index[PATH_MAX];
> const char *env[2] = { index, NULL };
> snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file);
> - launch_editor(git_path(commit_editmsg), &sb, env);
> - } else if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {
> - rollback_index_files();
> - die("could not read commit message");
> + launch_editor(git_path(commit_editmsg), NULL, env);
> }
> if (!no_verify &&
> run_hook(index_file, "commit-msg", git_path(commit_editmsg))) {
> rollback_index_files();
> exit(1);
> }
> + if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {
> + rollback_index_files();
> + die("could not read commit message");
> + }
>
> /* Truncate the message just before the diff, if any. */
> p = strstr(sb.buf, "\ndiff --git a/");
> diff --git a/builtin-tag.c b/builtin-tag.c
> index 729389b..9f966fc 100644
> --- a/builtin-tag.c
> +++ b/builtin-tag.c
> @@ -53,6 +53,8 @@ void launch_editor(const char *path, struct strbuf
> *buffer, const char *const *e
> die("There was a problem with the editor %s.", editor);
> }
>
> + if (!buffer)
> + return;
> if (strbuf_read_file(buffer, path, 0) < 0)
> die("could not read message file '%s': %s",
> path, strerror(errno));
Excellent. Reads much better. I hadn't considered changing the strbuf
API, but looking at the callers of launch_editor this is a safe
change. Ack.
Cheers,
Wincent
^ permalink raw reply
* Re: git-svn capabilities
From: Pedro Melo @ 2007-12-09 11:20 UTC (permalink / raw)
To: Adam Roben; +Cc: git
In-Reply-To: <475BA95F.7040403@apple.com>
Hi,
On Dec 9, 2007, at 8:37 AM, Adam Roben wrote:
> Pedro Melo wrote:
>> I've been following along the gcc/git thread with interest and
>> I've used Harvey Harrison recipe
>>
>> http://article.gmane.org/gmane.comp.version-control.git/67253
>>
>> with success on several svn repos.
>>
>> One thing that I'm not sure yet if it is possible to do is this:
>>
>> can I have a single central git repo that tracks the svn repo,
>> allow several developers to use clone to copy that repo, and each
>> one of them (after proper manual configuration) uses dcommit to
>> push back to svn?
>>
>> All the recipes so far assume that each developer has to go
>> through the initial git-svn fetch and have a copy of the entire
>> SVN repo, and that seems wasteful to me.
>
> The "Basic Examples" section of the git-svn man page describe how
> to do just that (though only for a single branch).
Sorry, missed that completely :)
Best regards,
--
Pedro Melo
Blog: http://www.simplicidade.org/notes/
XMPP ID: melo@simplicidade.org
Use XMPP!
^ permalink raw reply
* Re: How-to combine several separate git repos?
From: Alex Riesen @ 2007-12-09 10:43 UTC (permalink / raw)
To: Wink Saville; +Cc: git
In-Reply-To: <475B8C59.7050707@saville.com>
Wink Saville, Sun, Dec 09, 2007 07:34:01 +0100:
> I've got several git repositories of different projects and was thinking
> I should combine into one repository, but my googling around didn't turn up
> any simple way of doing it.
>
> Any advice?
Should they both be visible in one working tree as directories?
Should these be independent branches?
For instance, you can fetch one into another:
$ cd project1
$ git config remote.project2.url /path/to/project2
$ git config remote.project2.fetch 'refs/heads/*:refs/project2/*'
$ git fetch project
That will give you two (or more) branches, containing history of the
project1 and project2. They are still completely independent, just use
the same object store.
You can merge them, for example:
$ cd project1
$ git merge project2/master
Assuming that there is no filename collisions you'll get a repo with
two merged histories (and two starting points). In case you get
conflicts you can either resolve them by editing or just move the
problematic project in subdirectory:
$ git merge -s ours --no-commit project2/master
Automatic merge went well; stopped before committing as requested
here will be no conflicts. Merge strategy "ours" (-s ours) does not
take anything from the branch to be merged. The coolest strategy ever.
"--no-commit" stops the operation just before committing.
$ git read-tree --prefix=project2/ project2/master
$ git checkout-index -a
$ git commit
That's it. The histories are merged and the files of project2 are
placed in the directory "project2". It is a wee bit harder to browse
the history of the files: you have to give both new and "old" name of
the project2's files, as if you renamed them (that's what read-tree
with --prefix did).
^ permalink raw reply
* What's in git.git (stable)
From: Junio C Hamano @ 2007-12-09 10:32 UTC (permalink / raw)
To: git
In-Reply-To: <7vfxye4yv7.fsf@gitster.siamese.dyndns.org>
One more topic remains in 'next' before 1.5.4-rc0 where "bugfix only"
freeze period begins. We have a handful regression fixes on 'master'
from the fallout from massive C-rewrite during this cycle.
People still following 'next' are requested to switch to 'master', and
spare a bit more time on finding and fixing regressions there instead of
coming up with new topics from now on.
----------------------------------------------------------------
* The 'maint' branch has these fixes since the last announcement.
Jim Meyering (1):
config.c:store_write_pair(): don't read the byte before a malloc'd
buffer.
----------------------------------------------------------------
* The 'master' branch has these since the last announcement
in addition to the above.
Jeff King (3):
wt-status.c:quote_path(): convert empty path to "./"
add status.relativePaths config variable
git-status: documentation improvements
Junio C Hamano (13):
War on whitespace: first, a bit of retreat.
git-diff: complain about >=8 consecutive spaces in initial indent
core.whitespace: add test for diff whitespace error highlighting
builtin-apply: rename "whitespace" variables and fix styles
builtin-apply: teach whitespace_rules
core.whitespace: documentation updates.
Use gitattributes to define per-path whitespace rule
git-bisect visualize: work in non-windowed environments better
mailmap: fix bogus for() loop that happened to be safe by accident
shortlog: code restructuring and clean-up
ls-remote: resurrect pattern limit support
Fix commit-msg hook to allow editing
Re-fix "builtin-commit: fix --signoff"
Nicolas Pitre (3):
pack-objects: fix delta cache size accounting
pack-objects: reverse the delta search sort list
pack-objects: fix threaded load balancing
Pini Reznik (1):
Open external merge tool with original file extensions for all three
files
Sergei Organov (1):
Let git-help prefer man-pages installed with this version of git
Wincent Colaiuta (4):
Teach "git add -i" to colorize whitespace errors
Allow --no-verify to bypass commit-msg hook
Documentation: fix --no-verify documentation for "git commit"
Add tests for pre-commit and commit-msg hooks
^ permalink raw reply
* What's cooking in git.git (topics)
From: Junio C Hamano @ 2007-12-09 10:27 UTC (permalink / raw)
To: git
In-Reply-To: <7vejdy4yuw.fsf@gitster.siamese.dyndns.org>
Here are the topics that have been cooking. Commits prefixed
with '-' are only in 'pu' while commits prefixed with '+' are
in 'next'. Others commits may be stashed in 'offcuts'.
The topics list the commits in reverse chronological order.
----------------------------------------------------------------
[New Topics]
* jc/shortlog-e (Fri Dec 7 17:19:31 2007 -0800) 1 commit
+ git-shortlog -e: show e-mail address as well
I wanted to have a tool to help sanity checking our .mailmap, so I did
this.
----------------------------------------------------------------
[Graduated to 'master']
* pr/mergetool (Wed Dec 5 09:19:13 2007 +0200) 1 commit
* jc/spht (Thu Dec 6 00:14:14 2007 -0800) 7 commits
----------------------------------------------------------------
[Will cook further in 'next' and then merge to 'master' soon]
* cc/help (Wed Dec 5 06:09:40 2007 +0100) 5 commits
+ Documentation: describe -w/--web option to "git-help".
+ Use {web,instaweb,help}.browser config options.
+ git-help: add -w|--web option to display html man page in a
browser.
+ Documentation: describe -i/--info option to "git-help"
+ git-help: add -i|--info option to display info page.
Would be nice to have in v1.5.4. It may make sense to give a custom
info path when "help -i" is run, just like we futz with manpath while
running "help".
----------------------------------------------------------------
[Actively cooking]
* jc/api-doc (Sat Nov 24 23:48:04 2007 -0800) 1 commit
- Start preparing the API documents.
The primary reason of this series is because I think we made the system
a lot less approachable by losing hackability. Although we still have
sample scripts in contrib/example for use of plumbing in scripts, they
will not help aspiring git-hacker-wannabees when our primary attention
has already shifted to moving things to C.
This currently consists of mostly stubs, although I wrote about a few
topics as examples. Nice to have in v1.5.4.
----------------------------------------------------------------
[On hold]
* nd/dashless (Wed Nov 28 23:21:57 2007 +0700) 1 commit
- Move all dashed-form commands to libexecdir
I think this is a sane thing to do in the longer term. Will be in
'next' after v1.5.4. I think "leave porcelain on PATH" might be also a
good thing as a transition measure.
Incidentally, if we do not install dashed form of built-ins anywhere
(which is not this series is about --- this is just moving them out of
user's PATH), "git help -a" will stop showing them. I am not enthused
about removing the hardlinks to built-ins to begin with, but people who
want such a change need to first modify help.c:list_commands() to pick
up builtins without having git-foo hardlinks in gitexecdir. This may
need to happen anyway as mingw fallouts.
----------------------------------------------------------------
[Stalled]
* ns/checkout-push-pop (Wed Dec 5 07:04:06 2007 +0900) 1 commit
- git-checkout --push/--pop
A reasonably cleanly written cute hack, and I do not see this breaking
the normal codepath. But I tend to agree with people that 'push' is
too late for forgetful mortals, and just a single "previous" would be
easier to use.
* js/remote (Wed Dec 5 19:02:15 2007 +0000) 4 commits
- Make git-remote a builtin
- Test "git remote show" and "git remote prune"
- parseopt: add flag to stop on first non option
- path-list: add functions to work with unsorted lists
* js/reflog-delete (Wed Oct 17 02:50:45 2007 +0100) 1 commit
+ Teach "git reflog" a subcommand to delete single entries
* jk/builtin-alias (Fri Nov 30 11:22:58 2007 -0500) 1 commit
+ Support builtin aliases
* jc/nu (Sun Oct 14 22:07:34 2007 -0700) 3 commits
- merge-nu: a new merge backend without using unpack_trees()
- read_tree: take an explicit index structure
- gcc 4.2.1 -Werror -Wall -ansi -pedantic -std=c99: minimum fix
* jc/diff-pathspec (Sun Nov 25 10:03:48 2007 -0800) 1 commit
- Making ce_path_match() more useful by accepting globs
This was to allow "git diff-files -- '*.h'" (currently diff family
knows only the leading directory match and not fileglobs), but was shot
down by Alex. I tend to agree with him.
* jc/diff-relative (Thu Dec 6 09:48:32 2007 -0800) 1 commit
- Make "diff" Porcelain output paths as relative to subdirectory.
* jc/cherry-pick (Tue Nov 13 12:38:51 2007 -0800) 1 commit
. revert/cherry-pick: start refactoring call to merge_recursive
* jc/pathspec (Thu Sep 13 13:38:19 2007 -0700) 3 commits
. pathspec_can_match(): move it from builtin-ls-tree.c to tree.c
. ls-tree.c: refactor show_recursive() and rename it.
. tree-diff.c: split out a function to match a single pattern.
* jc/dashless (Sat Dec 1 22:09:22 2007 -0800) 2 commits
. Prepare execv_git_cmd() for removal of builtins from the
filesystem
. git-shell: accept "git foo" form
We do not plan to remove git-foo form completely from the filesystem at
this point, so these are not strictly necessary.
^ permalink raw reply
* Re: [PATCH] Remove repo version check from setup_git_directory
From: Junio C Hamano @ 2007-12-09 10:24 UTC (permalink / raw)
To: Nguyễn Thái Ngọc Duy; +Cc: git
In-Reply-To: <20071209101439.GA18312@laptop>
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
> setup_git_directory_gently has done the check already.
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> Sorry, somehow I left this line behind. It should have been gone
> from my re-fix patch.
>
> setup.c | 1 -
> 1 files changed, 0 insertions(+), 1 deletions(-)
>
> diff --git a/setup.c b/setup.c
> index e96a316..b59dbe7 100644
> --- a/setup.c
> +++ b/setup.c
> @@ -388,7 +388,6 @@ int check_repository_format(void)
> const char *setup_git_directory(void)
> {
> const char *retval = setup_git_directory_gently(NULL);
> - check_repository_format();
Ah, because the previous line already calls the same repository format
check, this is now unneeded, indeed.
Thanks.
^ permalink raw reply
* [PATCH WIP] Move worktree setup out of setup_git_directory*
From: Nguyễn Thái Ngọc Duy @ 2007-12-09 10:24 UTC (permalink / raw)
To: git, Johannes Schindelin
setup_git_directory* now work as if there is no worktree.
It may set some worktree-related variables but its prefix
(and current directory) should not be affected by worktree
settings.
While at it, put set_work_tree() code into
setup_git_directory_gently() for cleaner code.
Previously only setup_git_directory() takes worktree into
account when calculating prefix (with an exception). This
behaviour possibly gives commands that do only call
setup_git_directory_gently() wrong prefix. The behavior does
not expose often as setup_git_directory_gently() tries to
make correct prefix if both GIT_DIR and GIT_WORK_TREE
are set (the mentioned exception). Only if core.worktree
is used, the defect is summoned. Additional test is added
to catch this.
setup_work_tree() will now take the role of recalculating
prefix when worktree is required.
This also effectively reverts
dd5c8af176bb935a0b01a7dc2d5e022565c3aac3. The problem is IMHO
that git-diff does not setup worktree when it needs it, so
setting up worktree from setup_git_directory_gently() is a fix
in a wrong place.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
Now I'm pretty sure I made it wrong in builtin-diff.c. But I
found no better solution as diff territory is too far from my home.
One more thing, with this change, "git ls-files -c" would show
full path as it does not require a worktree, hence no worktree setup,
NULL prefix or so. Is it bad?
builtin-blame.c | 4 +-
builtin-diff.c | 7 ++++-
builtin-ls-files.c | 10 +++---
builtin-rev-parse.c | 2 +
builtin-rm.c | 2 +-
cache.h | 2 +-
git.c | 2 +-
setup.c | 80 ++++++++++++++++----------------------------------
t/t1501-worktree.sh | 8 ++++-
9 files changed, 51 insertions(+), 66 deletions(-)
diff --git a/builtin-blame.c b/builtin-blame.c
index c158d31..160a1cd 100644
--- a/builtin-blame.c
+++ b/builtin-blame.c
@@ -2280,6 +2280,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
/* (3) */
if (argc <= i)
usage(blame_usage);
+ prefix = setup_work_tree(prefix);
path = add_prefix(prefix, argv[i]);
if (i + 1 == argc - 1) {
final_commit_name = argv[i + 1];
@@ -2295,7 +2296,6 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
else if (i != argc - 1)
usage(blame_usage); /* garbage at end */
- setup_work_tree();
if (!has_path_in_work_tree(path))
die("cannot stat path %s: %s",
path, strerror(errno));
@@ -2343,7 +2343,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
* do not default to HEAD, but use the working tree
* or "--contents".
*/
- setup_work_tree();
+ prefix = setup_work_tree(prefix);
sb.final = fake_working_tree_commit(path, contents_from);
add_pending_object(&revs, &(sb.final->object), ":");
}
diff --git a/builtin-diff.c b/builtin-diff.c
index 1b61599..24c3080 100644
--- a/builtin-diff.c
+++ b/builtin-diff.c
@@ -246,8 +246,13 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
if (!setup_diff_no_index(&rev, argc, argv, nongit, prefix))
argc = 0;
- else
+ else {
+ prefix = setup_work_tree(prefix);
+ /* reinitialize rev as prefix can change */
+ init_revisions(&rev, prefix);
+ rev.diffopt.skip_stat_unmatch = !!diff_auto_refresh_index;
argc = setup_revisions(argc, argv, &rev, NULL);
+ }
if (!rev.diffopt.output_format) {
rev.diffopt.output_format = DIFF_FORMAT_PATCH;
if (diff_setup_done(&rev.diffopt) < 0)
diff --git a/builtin-ls-files.c b/builtin-ls-files.c
index 0f0ab2d..3da6d0c 100644
--- a/builtin-ls-files.c
+++ b/builtin-ls-files.c
@@ -23,7 +23,7 @@ static int show_valid_bit;
static int line_terminator = '\n';
static int prefix_len;
-static int prefix_offset;
+static int prefix_offset = -1;
static const char **pathspec;
static int error_unmatch;
static char *ps_matched;
@@ -433,8 +433,6 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
struct dir_struct dir;
memset(&dir, 0, sizeof(dir));
- if (prefix)
- prefix_offset = strlen(prefix);
git_config(git_default_config);
for (i = 1; i < argc; i++) {
@@ -566,8 +564,10 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
break;
}
- if (require_work_tree && !is_inside_work_tree())
- setup_work_tree();
+ if (require_work_tree)
+ prefix = setup_work_tree(prefix);
+ if (prefix_offset == -1)
+ prefix_offset = prefix ? strlen(prefix) : 0;
pathspec = get_pathspec(prefix, argv + i);
diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index 20d1789..e48c7ea 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -441,6 +441,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
continue;
}
if (!strcmp(arg, "--show-prefix")) {
+ if (is_inside_work_tree())
+ prefix = setup_work_tree(prefix);
if (prefix)
puts(prefix);
continue;
diff --git a/builtin-rm.c b/builtin-rm.c
index a3d25e6..920a18f 100644
--- a/builtin-rm.c
+++ b/builtin-rm.c
@@ -156,7 +156,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
usage_with_options(builtin_rm_usage, builtin_rm_options);
if (!index_only)
- setup_work_tree();
+ prefix = setup_work_tree(prefix);
pathspec = get_pathspec(prefix, argv);
seen = NULL;
diff --git a/cache.h b/cache.h
index b5811ec..08d7bf6 100644
--- a/cache.h
+++ b/cache.h
@@ -229,7 +229,7 @@ extern const char *get_git_work_tree(void);
#define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
extern const char **get_pathspec(const char *prefix, const char **pathspec);
-extern void setup_work_tree(void);
+extern const char *setup_work_tree(const char *prefix);
extern const char *setup_git_directory_gently(int *);
extern const char *setup_git_directory(void);
extern const char *prefix_path(const char *prefix, int len, const char *path);
diff --git a/git.c b/git.c
index c8b7e74..4b3b6b9 100644
--- a/git.c
+++ b/git.c
@@ -259,7 +259,7 @@ static int run_command(struct cmd_struct *p, int argc, const char **argv)
if (p->option & USE_PAGER)
setup_pager();
if (p->option & NEED_WORK_TREE)
- setup_work_tree();
+ prefix = setup_work_tree(prefix);
trace_argv_printf(argv, "trace: built-in: git");
diff --git a/setup.c b/setup.c
index b59dbe7..e23ee8d 100644
--- a/setup.c
+++ b/setup.c
@@ -188,38 +188,25 @@ int is_inside_work_tree(void)
return inside_work_tree;
}
-/*
- * set_work_tree() is only ever called if you set GIT_DIR explicitely.
- * The old behaviour (which we retain here) is to set the work tree root
- * to the cwd, unless overridden by the config, the command line, or
- * GIT_WORK_TREE.
- */
-static const char *set_work_tree(const char *dir)
-{
- char buffer[PATH_MAX + 1];
-
- if (!getcwd(buffer, sizeof(buffer)))
- die ("Could not get the current working directory");
- git_work_tree_cfg = xstrdup(buffer);
- inside_work_tree = 1;
-
- return NULL;
-}
-
-void setup_work_tree(void)
+const char *setup_work_tree(const char *prefix)
{
const char *work_tree, *git_dir;
- static int initialized = 0;
+ static char buffer[PATH_MAX + 1];
+ char *rel;
- if (initialized)
- return;
- work_tree = get_git_work_tree();
git_dir = get_git_dir();
if (!is_absolute_path(git_dir))
set_git_dir(make_absolute_path(git_dir));
- if (!work_tree || chdir(work_tree))
+ work_tree = get_git_work_tree();
+ if (!work_tree)
+ die("This operation must be run in a work tree");
+ if (prefix && chdir(prefix))
+ die ("Could not jump back into original cwd");
+ rel = get_relative_cwd(buffer, PATH_MAX, work_tree);
+ trace_printf("test: worktree = %s\n", rel ? rel : "NULL");
+ if (chdir(work_tree))
die("This operation must be run in a work tree");
- initialized = 1;
+ return rel && *rel ? strcat(rel, "/") : NULL;
}
static int check_repository_format_gently(int *nongit_ok)
@@ -262,24 +249,21 @@ const char *setup_git_directory_gently(int *nongit_ok)
static char buffer[1024 + 1];
const char *retval;
+ /*
+ * The old behaviour (which we retain here) is to set
+ * the work tree root to the cwd, unless overridden by
+ * the config, the command line, or GIT_WORK_TREE.
+ */
if (!work_tree_env) {
- retval = set_work_tree(gitdirenv);
- /* config may override worktree */
- if (check_repository_format_gently(nongit_ok))
- return NULL;
- return retval;
+ char buffer[PATH_MAX + 1];
+
+ if (!getcwd(buffer, sizeof(buffer)))
+ die ("Could not get the current working directory");
+ git_work_tree_cfg = xstrdup(buffer);
+ inside_work_tree = 1;
}
- if (check_repository_format_gently(nongit_ok))
- return NULL;
- retval = get_relative_cwd(buffer, sizeof(buffer) - 1,
- get_git_work_tree());
- if (!retval || !*retval)
- return NULL;
- set_git_dir(make_absolute_path(gitdirenv));
- if (chdir(work_tree_env) < 0)
- die ("Could not chdir to %s", work_tree_env);
- strcat(buffer, "/");
- return retval;
+ check_repository_format_gently(nongit_ok);
+ return NULL;
}
if (nongit_ok) {
*nongit_ok = 1;
@@ -387,17 +371,5 @@ int check_repository_format(void)
const char *setup_git_directory(void)
{
- const char *retval = setup_git_directory_gently(NULL);
-
- /* If the work tree is not the default one, recompute prefix */
- if (inside_work_tree < 0) {
- static char buffer[PATH_MAX + 1];
- char *rel;
- if (retval && chdir(retval))
- die ("Could not jump back into original cwd");
- rel = get_relative_cwd(buffer, PATH_MAX, get_git_work_tree());
- return rel && *rel ? strcat(rel, "/") : NULL;
- }
-
- return retval;
+ return setup_git_directory_gently(NULL);
}
diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
index 7ee3820..3b610ac 100755
--- a/t/t1501-worktree.sh
+++ b/t/t1501-worktree.sh
@@ -58,6 +58,12 @@ cd sub/dir || exit 1
test_rev_parse 'subdirectory' false false true sub/dir/
cd ../../.. || exit 1
+test_expect_success 'setup_work_tree() gives correct prefix' '
+ (cd work/sub && touch untracked &&
+ test "$(git ls-files -o)" = untracked)'
+
+rm work/sub/untracked || exit 1
+
say "GIT_WORK_TREE=relative path (override core.worktree)"
export GIT_DIR=$(pwd)/repo.git
export GIT_CONFIG=$GIT_DIR/config
@@ -103,7 +109,7 @@ test_expect_success 'repo finds its work tree from work tree, too' '
test sub/dir/tracked = "$(git ls-files)")
'
-test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' '
+test_expect_success '"git diff" setup worktree properly' '
cd repo.git/work/sub/dir &&
GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
git diff --exit-code tracked &&
--
1.5.3.7.2155.g4c25
^ permalink raw reply related
* [PATCH] Remove repo version check from setup_git_directory
From: Nguyễn Thái Ngọc Duy @ 2007-12-09 10:14 UTC (permalink / raw)
To: git, Junio C Hamano
setup_git_directory_gently has done the check already.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
Sorry, somehow I left this line behind. It should have been gone
from my re-fix patch.
setup.c | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/setup.c b/setup.c
index e96a316..b59dbe7 100644
--- a/setup.c
+++ b/setup.c
@@ -388,7 +388,6 @@ int check_repository_format(void)
const char *setup_git_directory(void)
{
const char *retval = setup_git_directory_gently(NULL);
- check_repository_format();
/* If the work tree is not the default one, recompute prefix */
if (inside_work_tree < 0) {
--
1.5.3.7.2155.g4c25
^ permalink raw reply related
* Re: [PATCH] gitweb: Teach "a=blob" action to be more lenient about blob/file mime type
From: Jakub Narebski @ 2007-12-09 10:06 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
In-Reply-To: <7vk5notub9.fsf@gitster.siamese.dyndns.org>
Junio C Hamano wrote:
> Jakub Narebski <jnareb@gmail.com> writes:
>> + }
>> + } els
> There is a "Huh?" on the last line, though.
I'm sorry for this wart. Can you correct this, or should I send
amended patch?
>> P.S. BTW is there some plumbing for scripts to help with
>> gitattributes, for example showing all gitattributes (or status of
>> selected attributes) for given path?
>
> $ git grep gitattributes Documentation | grep -i display
Thanks.
But as far as I can see you cannot specify _revision_,
i.e. git-check-attr operates _only_ on working directory, and
can be run only in a work tree. For gitweb I'd like it to run
in bare repository, and check $GIT_DIR/info/attributes and
<revision>:[*/].gitattributes
--
Jakub Narebski
Poland
^ permalink raw reply
* [PATCH 1/2] Move the file read logic to read_patch_file() in builtin-apply.c
From: Mike Hommey @ 2007-12-09 10:04 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
This will allow to extend the read logic further. We also return a better
error message than usage() when the given filename can't be opened, and
avoid whitespace options not being set when reading from stdin with the
"-" argument as a side effect.
Signed-off-by: Mike Hommey <mh@glandium.org>
---
builtin-apply.c | 32 +++++++++++++++++---------------
1 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/builtin-apply.c b/builtin-apply.c
index f2e9a33..8c8162a 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -182,11 +182,23 @@ static void say_patch_name(FILE *output, const char *pre,
#define CHUNKSIZE (8192)
#define SLOP (16)
-static void read_patch_file(struct strbuf *sb, int fd)
+static void read_patch_file(struct strbuf *sb, const char *filename)
{
+ int fd;
+
+ if (!strcmp(filename, "-")) {
+ fd = 0;
+ } else {
+ fd = open(filename, O_RDONLY);
+ if (fd < 0)
+ die("git-apply: could not open %s: %s", filename,
+ strerror(errno));
+ }
+
if (strbuf_read(sb, fd, 0) < 0)
die("git-apply: read returned %s", strerror(errno));
+ close(fd);
/*
* Make sure that we have some slop in the buffer
* so that we can do speculative "memcmp" etc, and
@@ -2705,7 +2717,7 @@ static void prefix_patches(struct patch *p)
}
}
-static int apply_patch(int fd, const char *filename, int inaccurate_eof)
+static int apply_patch(const char *filename, int inaccurate_eof)
{
size_t offset;
struct strbuf buf;
@@ -2714,7 +2726,7 @@ static int apply_patch(int fd, const char *filename, int inaccurate_eof)
strbuf_init(&buf, 0);
patch_input_file = filename;
- read_patch_file(&buf, fd);
+ read_patch_file(&buf, filename);
offset = 0;
while (offset < buf.len) {
struct patch *patch;
@@ -2807,13 +2819,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
char *end;
- int fd;
- if (!strcmp(arg, "-")) {
- errs |= apply_patch(0, "<stdin>", inaccurate_eof);
- read_stdin = 0;
- continue;
- }
if (!prefixcmp(arg, "--exclude=")) {
struct excludes *x = xmalloc(sizeof(*x));
x->path = arg + 10;
@@ -2916,17 +2922,13 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
if (0 < prefix_length)
arg = prefix_filename(prefix, prefix_length, arg);
- fd = open(arg, O_RDONLY);
- if (fd < 0)
- usage(apply_usage);
read_stdin = 0;
set_default_whitespace_mode(whitespace_option);
- errs |= apply_patch(fd, arg, inaccurate_eof);
- close(fd);
+ errs |= apply_patch(arg, inaccurate_eof);
}
set_default_whitespace_mode(whitespace_option);
if (read_stdin)
- errs |= apply_patch(0, "<stdin>", inaccurate_eof);
+ errs |= apply_patch("-", inaccurate_eof);
if (whitespace_error) {
if (squelch_whitespace_errors &&
squelch_whitespace_errors < whitespace_error) {
--
1.5.3.7
^ permalink raw reply related
* [PATCH 2/2] Add support for URLs to git-apply
From: Mike Hommey @ 2007-12-09 10:04 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano
In-Reply-To: <1197194672-28568-1-git-send-email-mh@glandium.org>
Instead of doing several "wget -O - url | git-apply -" in a raw, you now
can just git-apply url1 url2 ...
Signed-off-by: Mike Hommey <mh@glandium.org>
---
After spending an afternoon wgetting patches to applying them, I got fed up
and just added basic url support to git-apply. Note that the fwrite_strbuf
function should just live in http.c, but until the http api is fully switched
to use strbufs instead of its struct buffer (which I'm planning to do), it
can stay like this.
Documentation/git-apply.txt | 3 +-
builtin-apply.c | 66 +++++++++++++++++++++++++++++++++++++------
2 files changed, 59 insertions(+), 10 deletions(-)
diff --git a/Documentation/git-apply.txt b/Documentation/git-apply.txt
index bae3e7b..2d5d725 100644
--- a/Documentation/git-apply.txt
+++ b/Documentation/git-apply.txt
@@ -25,7 +25,8 @@ OPTIONS
-------
<patch>...::
The files to read patch from. '-' can be used to read
- from the standard input.
+ from the standard input. They can also be http, https or
+ ftp URLs.
--stat::
Instead of applying the patch, output diffstat for the
diff --git a/builtin-apply.c b/builtin-apply.c
index 8c8162a..e213bd2 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -12,6 +12,9 @@
#include "blob.h"
#include "delta.h"
#include "builtin.h"
+#ifndef NO_CURL
+#include "http.h"
+#endif
/*
* --check turns on checking that the working tree matches the
@@ -182,12 +185,55 @@ static void say_patch_name(FILE *output, const char *pre,
#define CHUNKSIZE (8192)
#define SLOP (16)
-static void read_patch_file(struct strbuf *sb, const char *filename)
+#ifndef NO_CURL
+static size_t fwrite_strbuf(const void *ptr, size_t eltsize,
+ size_t nmemb, struct strbuf *buffer)
+{
+ size_t size = eltsize * nmemb;
+ strbuf_add(buffer, ptr, size);
+ return size;
+}
+
+static int used_http;
+
+static void read_patch_url(struct strbuf *sb, const char *url)
+{
+ struct active_request_slot *slot;
+ struct slot_results results;
+
+ if (! used_http) {
+ http_init();
+ used_http = 1;
+ }
+
+ slot = get_active_slot();
+ slot->results = &results;
+ curl_easy_setopt(slot->curl, CURLOPT_FILE, sb);
+ curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, fwrite_strbuf);
+ curl_easy_setopt(slot->curl, CURLOPT_URL, url);
+ curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, NULL);
+
+ if (start_active_slot(slot)) {
+ run_active_slot(slot);
+ if (results.curl_result != CURLE_OK)
+ die("git-apply: could not open %s", url);
+ }
+}
+#endif
+
+static void read_patch(struct strbuf *sb, const char *filename)
{
int fd;
if (!strcmp(filename, "-")) {
fd = 0;
+#ifndef NO_CURL
+ } else if (!strncmp(filename, "http://", 7) ||
+ !strncmp(filename, "https://", 8) ||
+ !strncmp(filename, "ftp://", 6)) {
+ read_patch_url(sb, filename);
+ return;
+#endif
} else {
fd = open(filename, O_RDONLY);
if (fd < 0)
@@ -199,13 +245,6 @@ static void read_patch_file(struct strbuf *sb, const char *filename)
die("git-apply: read returned %s", strerror(errno));
close(fd);
- /*
- * Make sure that we have some slop in the buffer
- * so that we can do speculative "memcmp" etc, and
- * see to it that it is NUL-filled.
- */
- strbuf_grow(sb, SLOP);
- memset(sb->buf + sb->len, 0, SLOP);
}
static unsigned long linelen(const char *buffer, unsigned long size)
@@ -2726,7 +2765,14 @@ static int apply_patch(const char *filename, int inaccurate_eof)
strbuf_init(&buf, 0);
patch_input_file = filename;
- read_patch_file(&buf, filename);
+ read_patch(&buf, filename);
+ /*
+ * Make sure that we have some slop in the buffer
+ * so that we can do speculative "memcmp" etc, and
+ * see to it that it is NUL-filled.
+ */
+ strbuf_grow(&buf, SLOP);
+ memset(buf.buf + buf.len, 0, SLOP);
offset = 0;
while (offset < buf.len) {
struct patch *patch;
@@ -2926,6 +2972,8 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
set_default_whitespace_mode(whitespace_option);
errs |= apply_patch(arg, inaccurate_eof);
}
+ if (used_http)
+ http_cleanup();
set_default_whitespace_mode(whitespace_option);
if (read_stdin)
errs |= apply_patch("-", inaccurate_eof);
--
1.5.3.7
^ permalink raw reply related
* Re: [PATCH] don't mention index refreshing side effect in git-status docs
From: Jeff King @ 2007-12-09 8:42 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Steven Grimm, git
In-Reply-To: <7vhciss1ww.fsf@gitster.siamese.dyndns.org>
On Sun, Dec 09, 2007 at 12:33:19AM -0800, Junio C Hamano wrote:
> Jeff King <peff@peff.net> writes:
>
> > If there is some desire to document the side effect, I think we should
> > at least remove the mention of speeding up git-diff (which is just wrong
> > now).
>
> Why is it "just wrong"? Having to squelch the false hits and to run
> auto-refresh are both unnecessary overhead if your index is fresh.
I mean that this is not a useful technique for speeding up git-diff
anymore (assuming you have not tinkered with autorefreshindex, in which
case I assume you know what you are doing and don't need this tip).
Did you think I meant "there is no speedup with autorefreshindex off",
or are you arguing that even with the new diff behavior there is still a
speedup in "git status; git diff" over just "git status"?
-Peff
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox