summaryrefslogtreecommitdiff
path: root/index-pack.c
diff options
context:
space:
mode:
authorNicolas Pitre <nico@cam.org>2006-11-01 17:06:25 -0500
committerJunio C Hamano <junkio@cox.net>2006-11-03 00:24:07 -0800
commit576162a45f35e157427300066b0ff566ff698a0f (patch)
tree2fdc7abe3ac1688b340b30cffd7d5e086c04998f /index-pack.c
parent9ca4a201eaf0c58dbc7184cb2d5ab01c48cb7447 (diff)
downloadgit-576162a45f35e157427300066b0ff566ff698a0f.tar.gz
remove .keep pack lock files when done with refs update
This makes both git-fetch and git-push (fetch-pack and receive-pack) safe against a possible race with aparallel git-repack -a -d that could prune the new pack while it is not yet referenced, and remove the .keep file after refs have been updated. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'index-pack.c')
-rw-r--r--index-pack.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/index-pack.c b/index-pack.c
index 8d64a883af..042aea8842 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -757,6 +757,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
const char *keep_name, const char *keep_msg,
unsigned char *sha1)
{
+ char *report = "pack";
char name[PATH_MAX];
int err;
@@ -767,18 +768,6 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
if (err)
die("error while closing pack file: %s", strerror(errno));
chmod(curr_pack_name, 0444);
-
- /*
- * Let's just mimic git-unpack-objects here and write
- * the last part of the buffer to stdout.
- */
- while (input_len) {
- err = xwrite(1, input_buffer + input_offset, input_len);
- if (err <= 0)
- break;
- input_len -= err;
- input_offset += err;
- }
}
if (keep_msg) {
@@ -798,6 +787,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
write_or_die(keep_fd, "\n", 1);
}
close(keep_fd);
+ report = "keep";
}
}
@@ -821,6 +811,27 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
if (move_temp_to_file(curr_index_name, final_index_name))
die("cannot store index file");
}
+
+ if (!from_stdin) {
+ printf("%s\n", sha1_to_hex(sha1));
+ } else {
+ char buf[48];
+ int len = snprintf(buf, sizeof(buf), "%s\t%s\n",
+ report, sha1_to_hex(sha1));
+ xwrite(1, buf, len);
+
+ /*
+ * Let's just mimic git-unpack-objects here and write
+ * the last part of the input buffer to stdout.
+ */
+ while (input_len) {
+ err = xwrite(1, input_buffer + input_offset, input_len);
+ if (err <= 0)
+ break;
+ input_len -= err;
+ input_offset += err;
+ }
+ }
}
int main(int argc, char **argv)
@@ -937,8 +948,5 @@ int main(int argc, char **argv)
free(index_name_buf);
free(keep_name_buf);
- if (!from_stdin)
- printf("%s\n", sha1_to_hex(sha1));
-
return 0;
}