From: Petr Baudis <pasky@suse.cz>
To: Junio C Hamano <junkio@cox.net>
Cc: <git@vger.kernel.org>
Subject: [PATCH 2/4] Make pull() support fetching multiple targets at once
Date: Thu, 27 Jul 2006 23:56:17 +0200 [thread overview]
Message-ID: <20060727215617.24240.4753.stgit@machine> (raw)
In-Reply-To: <20060727215326.24240.20118.stgit@machine>
pull() now takes an array of arguments instead of just one of each kind.
Currently, no users use the new capability, but that'll change.
Signed-off-by: Petr Baudis <pasky@suse.cz>
---
fetch.c | 78 +++++++++++++++++++++++++++++++++------------------------
fetch.h | 2 +
http-fetch.c | 2 +
local-fetch.c | 2 +
ssh-fetch.c | 2 +
5 files changed, 49 insertions(+), 37 deletions(-)
diff --git a/fetch.c b/fetch.c
index 3255cc6..281df61 100644
--- a/fetch.c
+++ b/fetch.c
@@ -210,55 +210,67 @@ static int mark_complete(const char *pat
return 0;
}
-int pull(char *target, const char *write_ref,
+int pull(int targets, char **target, const char **write_ref,
const char *write_ref_log_details)
{
- struct ref_lock *lock = NULL;
- unsigned char sha1[20];
+ struct ref_lock **lock = xcalloc(targets, sizeof(struct ref_lock *));
+ unsigned char *sha1 = xmalloc(targets * 20);
char *msg;
int ret;
+ int i;
save_commit_buffer = 0;
track_object_refs = 0;
- if (write_ref) {
- lock = lock_ref_sha1(write_ref, NULL, 0);
- if (!lock) {
- error("Can't lock ref %s", write_ref);
- return -1;
+
+ for (i = 0; i < targets; i++) {
+ if (!write_ref[i])
+ continue;
+
+ lock[i] = lock_ref_sha1(write_ref[i], NULL, 0);
+ if (!lock[i]) {
+ error("Can't lock ref %s", write_ref[i]);
+ goto unlock_and_fail;
}
}
if (!get_recover)
for_each_ref(mark_complete);
- if (interpret_target(target, sha1)) {
- error("Could not interpret %s as something to pull", target);
- if (lock)
- unlock_ref(lock);
- return -1;
+ for (i = 0; i < targets; i++) {
+ if (interpret_target(target[i], &sha1[20 * i])) {
+ error("Could not interpret %s as something to pull", target[i]);
+ goto unlock_and_fail;
+ }
+ if (process(lookup_unknown_object(&sha1[20 * i])))
+ goto unlock_and_fail;
}
- if (process(lookup_unknown_object(sha1))) {
- if (lock)
- unlock_ref(lock);
- return -1;
+
+ if (loop())
+ goto unlock_and_fail;
+
+ if (write_ref_log_details) {
+ msg = xmalloc(strlen(write_ref_log_details) + 12);
+ sprintf(msg, "fetch from %s", write_ref_log_details);
+ } else {
+ msg = NULL;
}
- if (loop()) {
- if (lock)
- unlock_ref(lock);
- return -1;
+ for (i = 0; i < targets; i++) {
+ if (!write_ref[i])
+ continue;
+ ret = write_ref_sha1(lock[i], &sha1[20 * i], msg ? msg : "fetch (unknown)");
+ lock[i] = NULL;
+ if (ret)
+ goto unlock_and_fail;
}
+ if (msg)
+ free(msg);
- if (write_ref) {
- if (write_ref_log_details) {
- msg = xmalloc(strlen(write_ref_log_details) + 12);
- sprintf(msg, "fetch from %s", write_ref_log_details);
- }
- else
- msg = NULL;
- ret = write_ref_sha1(lock, sha1, msg ? msg : "fetch (unknown)");
- if (msg)
- free(msg);
- return ret;
- }
return 0;
+
+
+unlock_and_fail:
+ for (i = 0; i < targets; i++)
+ if (lock[i])
+ unlock_ref(lock[i]);
+ return -1;
}
diff --git a/fetch.h b/fetch.h
index 7bda355..75e48af 100644
--- a/fetch.h
+++ b/fetch.h
@@ -42,7 +42,7 @@ extern void pull_say(const char *, const
/* If write_ref is set, the ref filename to write the target value to. */
/* If write_ref_log_details is set, additional text will appear in the ref log. */
-extern int pull(char *target, const char *write_ref,
+extern int pull(int targets, char **target, const char **write_ref,
const char *write_ref_log_details);
#endif /* PULL_H */
diff --git a/http-fetch.c b/http-fetch.c
index 963d439..bc67db1 100644
--- a/http-fetch.c
+++ b/http-fetch.c
@@ -1268,7 +1268,7 @@ int main(int argc, char **argv)
alt->path_len = strlen(path);
}
- if (pull(commit_id, write_ref, url))
+ if (pull(1, &commit_id, &write_ref, url))
rc = 1;
http_cleanup();
diff --git a/local-fetch.c b/local-fetch.c
index 308ed00..eb19f1a 100644
--- a/local-fetch.c
+++ b/local-fetch.c
@@ -242,7 +242,7 @@ int main(int argc, char **argv)
commit_id = argv[arg];
path = argv[arg + 1];
- if (pull(commit_id, write_ref, path))
+ if (pull(1, &commit_id, &write_ref, path))
return 1;
return 0;
diff --git a/ssh-fetch.c b/ssh-fetch.c
index aef3aa4..6e16568 100644
--- a/ssh-fetch.c
+++ b/ssh-fetch.c
@@ -167,7 +167,7 @@ int main(int argc, char **argv)
if (get_version())
return 1;
- if (pull(commit_id, write_ref, url))
+ if (pull(1, &commit_id, &write_ref, url))
return 1;
return 0;
next prev parent reply other threads:[~2006-07-27 21:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-27 21:53 [PATCH 0/4] Fetching mass of objects at once Petr Baudis
2006-07-27 21:56 ` [PATCH 1/4] Make pull() take some implicit data as explicit arguments Petr Baudis
2006-07-27 21:56 ` Petr Baudis [this message]
2006-07-27 21:56 ` [PATCH 3/4] Teach git-local-fetch the --stdin switch Petr Baudis
2006-07-28 1:57 ` Petr Baudis
2006-07-27 21:56 ` [PATCH 4/4] Teach git-http-fetch " Petr Baudis
2006-07-27 21:57 ` [PATCH 0/4] Fetching mass of objects at once Petr Baudis
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060727215617.24240.4753.stgit@machine \
--to=pasky@suse.cz \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.