summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2008-06-01 23:43:21 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2008-06-01 23:43:21 -0700
commitd8ad63aff0c494898f95aefb12fef25514ba7413 (patch)
tree62bcd0e4ae2cfcf04709da069bb9b5d65043bda1
parentMerge branch 'np/pack-check' (diff)
parentRemove now unnecessary 'sync()' calls (diff)
downloadtgif-d8ad63aff0c494898f95aefb12fef25514ba7413.tar.xz
Merge branch 'lt/pack-sync'
* lt/pack-sync: Remove now unnecessary 'sync()' calls Make pack creation always fsync() the result
-rw-r--r--builtin-pack-objects.c7
-rw-r--r--builtin-prune-packed.c1
-rw-r--r--builtin-prune.c1
-rw-r--r--cache.h1
-rw-r--r--csum-file.c7
-rw-r--r--csum-file.h6
-rw-r--r--fast-import.c2
-rwxr-xr-xgit-repack.sh1
-rw-r--r--index-pack.c1
-rw-r--r--pack-write.c2
-rw-r--r--write_or_die.c7
11 files changed, 26 insertions, 10 deletions
diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index 70d2f5d416..447d492dbb 100644
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
@@ -514,11 +514,14 @@ static void write_pack_file(void)
* Did we write the wrong # entries in the header?
* If so, rewrite it like in fast-import
*/
- if (pack_to_stdout || nr_written == nr_remaining) {
- sha1close(f, sha1, 1);
+ if (pack_to_stdout) {
+ sha1close(f, sha1, CSUM_CLOSE);
+ } else if (nr_written == nr_remaining) {
+ sha1close(f, sha1, CSUM_FSYNC);
} else {
int fd = sha1close(f, NULL, 0);
fixup_pack_header_footer(fd, sha1, pack_tmp_name, nr_written);
+ fsync_or_die(fd, pack_tmp_name);
close(fd);
}
diff --git a/builtin-prune-packed.c b/builtin-prune-packed.c
index 23faf3129f..241afbbab5 100644
--- a/builtin-prune-packed.c
+++ b/builtin-prune-packed.c
@@ -85,7 +85,6 @@ int cmd_prune_packed(int argc, const char **argv, const char *prefix)
/* Handle arguments here .. */
usage(prune_packed_usage);
}
- sync();
prune_packed_objects(opts);
return 0;
}
diff --git a/builtin-prune.c b/builtin-prune.c
index 25f9304b82..bd3d2f67f3 100644
--- a/builtin-prune.c
+++ b/builtin-prune.c
@@ -156,7 +156,6 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
mark_reachable_objects(&revs, 1);
prune_object_dir(get_object_directory());
- sync();
prune_packed_objects(show_only);
remove_temporary_files();
return 0;
diff --git a/cache.h b/cache.h
index eab1a172fe..092a997b07 100644
--- a/cache.h
+++ b/cache.h
@@ -761,6 +761,7 @@ extern ssize_t write_in_full(int fd, const void *buf, size_t count);
extern void write_or_die(int fd, const void *buf, size_t count);
extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg);
extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg);
+extern void fsync_or_die(int fd, const char *);
/* pager.c */
extern void setup_pager(void);
diff --git a/csum-file.c b/csum-file.c
index 9728a99541..ace64f165e 100644
--- a/csum-file.c
+++ b/csum-file.c
@@ -32,21 +32,24 @@ static void sha1flush(struct sha1file *f, unsigned int count)
}
}
-int sha1close(struct sha1file *f, unsigned char *result, int final)
+int sha1close(struct sha1file *f, unsigned char *result, unsigned int flags)
{
int fd;
unsigned offset = f->offset;
+
if (offset) {
SHA1_Update(&f->ctx, f->buffer, offset);
sha1flush(f, offset);
f->offset = 0;
}
- if (final) {
+ if (flags & (CSUM_CLOSE | CSUM_FSYNC)) {
/* write checksum and close fd */
SHA1_Final(f->buffer, &f->ctx);
if (result)
hashcpy(result, f->buffer);
sha1flush(f, 20);
+ if (flags & CSUM_FSYNC)
+ fsync_or_die(f->fd, f->name);
if (close(f->fd))
die("%s: sha1 file error on close (%s)",
f->name, strerror(errno));
diff --git a/csum-file.h b/csum-file.h
index 1af76562f3..72c9487f4f 100644
--- a/csum-file.h
+++ b/csum-file.h
@@ -16,9 +16,13 @@ struct sha1file {
unsigned char buffer[8192];
};
+/* sha1close flags */
+#define CSUM_CLOSE 1
+#define CSUM_FSYNC 2
+
extern struct sha1file *sha1fd(int fd, const char *name);
extern struct sha1file *sha1fd_throughput(int fd, const char *name, struct progress *tp);
-extern int sha1close(struct sha1file *, unsigned char *, int);
+extern int sha1close(struct sha1file *, unsigned char *, unsigned int);
extern int sha1write(struct sha1file *, void *, unsigned int);
extern void crc32_begin(struct sha1file *);
extern uint32_t crc32_end(struct sha1file *);
diff --git a/fast-import.c b/fast-import.c
index 93119bbd94..e72b286794 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -890,7 +890,7 @@ static char *create_index(void)
SHA1_Update(&ctx, (*c)->sha1, 20);
}
sha1write(f, pack_data->sha1, sizeof(pack_data->sha1));
- sha1close(f, NULL, 1);
+ sha1close(f, NULL, CSUM_FSYNC);
free(idx);
SHA1_Final(pack_data->sha1, &ctx);
return tmpfile;
diff --git a/git-repack.sh b/git-repack.sh
index 10f735cff5..072d1b40f7 100755
--- a/git-repack.sh
+++ b/git-repack.sh
@@ -125,7 +125,6 @@ then
# We know $existing are all redundant.
if [ -n "$existing" ]
then
- sync
( cd "$PACKDIR" &&
for e in $existing
do
diff --git a/index-pack.c b/index-pack.c
index aaba9443cc..5ac91baf98 100644
--- a/index-pack.c
+++ b/index-pack.c
@@ -694,6 +694,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
if (!from_stdin) {
close(input_fd);
} else {
+ fsync_or_die(output_fd, curr_pack_name);
err = close(output_fd);
if (err)
die("error while closing pack file: %s", strerror(errno));
diff --git a/pack-write.c b/pack-write.c
index c66c8af725..f52cabe838 100644
--- a/pack-write.c
+++ b/pack-write.c
@@ -139,7 +139,7 @@ char *write_idx_file(char *index_name, struct pack_idx_entry **objects,
}
sha1write(f, sha1, 20);
- sha1close(f, NULL, 1);
+ sha1close(f, NULL, CSUM_FSYNC);
SHA1_Final(sha1, &ctx);
return index_name;
}
diff --git a/write_or_die.c b/write_or_die.c
index 32f9914020..630be4cb94 100644
--- a/write_or_die.c
+++ b/write_or_die.c
@@ -78,6 +78,13 @@ ssize_t write_in_full(int fd, const void *buf, size_t count)
return total;
}
+void fsync_or_die(int fd, const char *msg)
+{
+ if (fsync(fd) < 0) {
+ die("%s: fsync error (%s)", msg, strerror(errno));
+ }
+}
+
void write_or_die(int fd, const void *buf, size_t count)
{
if (write_in_full(fd, buf, count) < 0) {