From: Junio C Hamano <junkio@cox.net>
To: Nicolas Pitre <nico@cam.org>
Cc: git@vger.kernel.org
Subject: [PATCH] send-pack --keep: do not explode into loose objects on the receiving end.
Date: Sun, 29 Oct 2006 00:47:56 -0700 [thread overview]
Message-ID: <7vwt6j4l77.fsf@assigned-by-dhcp.cox.net> (raw)
In-Reply-To: <Pine.LNX.4.64.0610252333540.12418@xanadu.home> (Nicolas Pitre's message of "Wed, 25 Oct 2006 23:44:12 -0400 (EDT)")
This adds "keep-pack" extension to send-pack vs receive pack protocol,
and makes the receiver invoke "index-pack --stdin --fix-thin".
With this, you can ask send-pack not to explode the result into
loose objects on the receiving end.
I've patched has_sha1_file() to re-check for added packs just
like is done in read_sha1_file() for now, but I think the static
"re-prepare" interface for packs was a mistake. Creation of a
new pack inside a process that needs to read objects in them
back ought to be a rare event, so we are better off making the
callers (such as receive-pack that calls "index-pack --stdin
--fix-thin") explicitly call re-prepare. That way we do not
have to penalize ordinary users of read_sha1_file() and
has_sha1_file().
We would need to fix this someday.
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
receive-pack.c | 19 ++++++++++++++++---
send-pack.c | 23 ++++++++++++++++++-----
sha1_file.c | 7 +++++--
t/t5400-send-pack.sh | 9 +++++++++
4 files changed, 48 insertions(+), 10 deletions(-)
diff --git a/receive-pack.c b/receive-pack.c
index ea2dbd4..ef50226 100644
--- a/receive-pack.c
+++ b/receive-pack.c
@@ -8,10 +8,14 @@
static const char receive_pack_usage[] = "git-receive-pack <git-dir>";
static const char *unpacker[] = { "unpack-objects", NULL };
+static const char *keep_packer[] = {
+ "index-pack", "--stdin", "--fix-thin", NULL
+};
static int report_status;
+static int keep_pack;
-static char capabilities[] = "report-status";
+static char capabilities[] = "report-status keep-pack";
static int capabilities_sent;
static int show_ref(const char *path, const unsigned char *sha1)
@@ -261,6 +265,8 @@ static void read_head_info(void)
if (reflen + 82 < len) {
if (strstr(refname + reflen + 1, "report-status"))
report_status = 1;
+ if (strstr(refname + reflen + 1, "keep-pack"))
+ keep_pack = 1;
}
cmd = xmalloc(sizeof(struct command) + len - 80);
hashcpy(cmd->old_sha1, old_sha1);
@@ -275,7 +281,14 @@ static void read_head_info(void)
static const char *unpack(int *error_code)
{
- int code = run_command_v_opt(1, unpacker, RUN_GIT_CMD);
+ int code;
+
+ if (keep_pack)
+ code = run_command_v_opt(ARRAY_SIZE(keep_packer) - 1,
+ keep_packer, RUN_GIT_CMD);
+ else
+ code = run_command_v_opt(ARRAY_SIZE(unpacker) - 1,
+ unpacker, RUN_GIT_CMD);
*error_code = 0;
switch (code) {
@@ -335,7 +348,7 @@ int main(int argc, char **argv)
if (!dir)
usage(receive_pack_usage);
- if(!enter_repo(dir, 0))
+ if (!enter_repo(dir, 0))
die("'%s': unable to chdir or not a git archive", dir);
write_head_info();
diff --git a/send-pack.c b/send-pack.c
index 5bb123a..54d218c 100644
--- a/send-pack.c
+++ b/send-pack.c
@@ -6,13 +6,14 @@
#include "exec_cmd.h"
static const char send_pack_usage[] =
-"git-send-pack [--all] [--exec=git-receive-pack] <remote> [<head>...]\n"
+"git-send-pack [--all] [--keep] [--exec=git-receive-pack] <remote> [<head>...]\n"
" --all and explicit <head> specification are mutually exclusive.";
static const char *exec = "git-receive-pack";
static int verbose;
static int send_all;
static int force_update;
static int use_thin_pack;
+static int keep_pack;
static int is_zero_sha1(const unsigned char *sha1)
{
@@ -270,6 +271,7 @@ static int send_pack(int in, int out, in
int new_refs;
int ret = 0;
int ask_for_status_report = 0;
+ int ask_to_keep_pack = 0;
int expect_status_report = 0;
/* No funny business with the matcher */
@@ -279,6 +281,8 @@ static int send_pack(int in, int out, in
/* Does the other end support the reporting? */
if (server_supports("report-status"))
ask_for_status_report = 1;
+ if (server_supports("keep-pack") && keep_pack)
+ ask_to_keep_pack = 1;
/* match them up */
if (!remote_tail)
@@ -355,12 +359,17 @@ static int send_pack(int in, int out, in
strcpy(old_hex, sha1_to_hex(ref->old_sha1));
new_hex = sha1_to_hex(ref->new_sha1);
- if (ask_for_status_report) {
- packet_write(out, "%s %s %s%c%s",
+ if (ask_for_status_report || ask_to_keep_pack) {
+ packet_write(out, "%s %s %s%c%s%s",
old_hex, new_hex, ref->name, 0,
- "report-status");
+ ask_for_status_report
+ ? " report-status" : "",
+ ask_to_keep_pack
+ ? " keep-pack" : "");
+ if (ask_for_status_report)
+ expect_status_report = 1;
ask_for_status_report = 0;
- expect_status_report = 1;
+ ask_to_keep_pack = 0;
}
else
packet_write(out, "%s %s %s",
@@ -419,6 +428,10 @@ int main(int argc, char **argv)
verbose = 1;
continue;
}
+ if (!strcmp(arg, "--keep")) {
+ keep_pack = 1;
+ continue;
+ }
if (!strcmp(arg, "--thin")) {
use_thin_pack = 1;
continue;
diff --git a/sha1_file.c b/sha1_file.c
index e89d24c..278ba2f 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1292,7 +1292,7 @@ static void *read_packed_sha1(const unsi
return unpack_entry(&e, type, size);
}
-void * read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size)
+void *read_sha1_file(const unsigned char *sha1, char *type, unsigned long *size)
{
unsigned long mapsize;
void *map, *buf;
@@ -1757,7 +1757,10 @@ int has_sha1_file(const unsigned char *s
if (find_pack_entry(sha1, &e, NULL))
return 1;
- return find_sha1_file(sha1, &st) ? 1 : 0;
+ if (find_sha1_file(sha1, &st))
+ return 1;
+ reprepare_packed_git();
+ return find_pack_entry(sha1, &e, NULL);
}
/*
diff --git a/t/t5400-send-pack.sh b/t/t5400-send-pack.sh
index 8afb899..d831f8d 100755
--- a/t/t5400-send-pack.sh
+++ b/t/t5400-send-pack.sh
@@ -78,4 +78,13 @@ test_expect_success \
! diff -u .git/refs/heads/master victim/.git/refs/heads/master
'
+test_expect_success 'push with --keep' '
+ t=`cd victim && git-rev-parse --verify refs/heads/master` &&
+ git-update-ref refs/heads/master $t &&
+ : > foo &&
+ git add foo &&
+ git commit -m "one more" &&
+ git-send-pack --keep ./victim/.git/ master
+'
+
test_done
--
1.4.3.3.g7d63
next prev parent reply other threads:[~2006-10-29 7:48 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-26 3:44 fetching packs and storing them as packs Nicolas Pitre
2006-10-26 14:45 ` Eran Tromer
[not found] ` <Pine.LNX.4.64.0610261105200.12418@xanadu.home>
2006-10-26 22:09 ` Eran Tromer
2006-10-27 0:50 ` Nicolas Pitre
2006-10-27 1:42 ` Shawn Pearce
2006-10-27 2:38 ` Sean
2006-10-27 6:57 ` Junio C Hamano
2006-10-27 17:23 ` Nicolas Pitre
2006-10-27 2:41 ` Nicolas Pitre
2006-10-27 2:42 ` Eran Tromer
2006-10-27 3:00 ` Shawn Pearce
2006-10-27 3:13 ` Sean
2006-10-27 3:20 ` Jakub Narebski
2006-10-27 3:27 ` Sean
2006-10-27 4:03 ` Eran Tromer
2006-10-27 4:42 ` Shawn Pearce
2006-10-27 7:42 ` Alex Riesen
2006-10-27 7:52 ` Shawn Pearce
2006-10-27 8:08 ` Alex Riesen
2006-10-27 8:13 ` Shawn Pearce
2006-10-27 14:27 ` Nicolas Pitre
2006-10-27 14:38 ` Petr Baudis
2006-10-27 14:48 ` J. Bruce Fields
2006-10-27 15:03 ` Petr Baudis
2006-10-27 16:04 ` J. Bruce Fields
2006-10-27 16:05 ` J. Bruce Fields
2006-10-27 18:56 ` Junio C Hamano
2006-10-27 20:22 ` Linus Torvalds
2006-10-27 21:53 ` Junio C Hamano
2006-10-28 3:42 ` Shawn Pearce
2006-10-28 4:09 ` Junio C Hamano
2006-10-28 4:18 ` Linus Torvalds
2006-10-28 5:42 ` Junio C Hamano
2006-10-28 7:21 ` Shawn Pearce
2006-10-28 8:40 ` Shawn Pearce
2006-10-28 19:15 ` Junio C Hamano
2006-10-29 3:50 ` Shawn Pearce
2006-10-29 4:29 ` Junio C Hamano
2006-10-29 4:38 ` Shawn Pearce
2006-10-29 5:16 ` Junio C Hamano
2006-10-29 5:21 ` Shawn Pearce
2006-10-28 17:59 ` Linus Torvalds
2006-10-28 18:34 ` Junio C Hamano
2006-10-28 22:31 ` Eran Tromer
2006-10-29 3:38 ` Shawn Pearce
2006-10-29 3:48 ` Jakub Narebski
2006-10-29 3:52 ` Shawn Pearce
2006-10-29 7:47 ` Junio C Hamano [this message]
2006-10-29 7:56 ` [PATCH] send-pack --keep: do not explode into loose objects on the receiving end Shawn Pearce
2006-10-29 8:05 ` Junio C Hamano
2006-10-30 1:44 ` Nicolas Pitre
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=7vwt6j4l77.fsf@assigned-by-dhcp.cox.net \
--to=junkio@cox.net \
--cc=git@vger.kernel.org \
--cc=nico@cam.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).