Skip to content

Commit d8ad63a

Browse files
committed
Merge branch 'lt/pack-sync'
* lt/pack-sync: Remove now unnecessary 'sync()' calls Make pack creation always fsync() the result
2 parents a44a5c0 + 54352bb commit d8ad63a

File tree

11 files changed

+26
-10
lines changed

11 files changed

+26
-10
lines changed

builtin-pack-objects.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,14 @@ static void write_pack_file(void)
514514
* Did we write the wrong # entries in the header?
515515
* If so, rewrite it like in fast-import
516516
*/
517-
if (pack_to_stdout || nr_written == nr_remaining) {
518-
sha1close(f, sha1, 1);
517+
if (pack_to_stdout) {
518+
sha1close(f, sha1, CSUM_CLOSE);
519+
} else if (nr_written == nr_remaining) {
520+
sha1close(f, sha1, CSUM_FSYNC);
519521
} else {
520522
int fd = sha1close(f, NULL, 0);
521523
fixup_pack_header_footer(fd, sha1, pack_tmp_name, nr_written);
524+
fsync_or_die(fd, pack_tmp_name);
522525
close(fd);
523526
}
524527

builtin-prune-packed.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ int cmd_prune_packed(int argc, const char **argv, const char *prefix)
8585
/* Handle arguments here .. */
8686
usage(prune_packed_usage);
8787
}
88-
sync();
8988
prune_packed_objects(opts);
9089
return 0;
9190
}

builtin-prune.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ int cmd_prune(int argc, const char **argv, const char *prefix)
156156
mark_reachable_objects(&revs, 1);
157157
prune_object_dir(get_object_directory());
158158

159-
sync();
160159
prune_packed_objects(show_only);
161160
remove_temporary_files();
162161
return 0;

cache.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ extern ssize_t write_in_full(int fd, const void *buf, size_t count);
761761
extern void write_or_die(int fd, const void *buf, size_t count);
762762
extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg);
763763
extern int write_or_whine_pipe(int fd, const void *buf, size_t count, const char *msg);
764+
extern void fsync_or_die(int fd, const char *);
764765

765766
/* pager.c */
766767
extern void setup_pager(void);

csum-file.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,24 @@ static void sha1flush(struct sha1file *f, unsigned int count)
3232
}
3333
}
3434

35-
int sha1close(struct sha1file *f, unsigned char *result, int final)
35+
int sha1close(struct sha1file *f, unsigned char *result, unsigned int flags)
3636
{
3737
int fd;
3838
unsigned offset = f->offset;
39+
3940
if (offset) {
4041
SHA1_Update(&f->ctx, f->buffer, offset);
4142
sha1flush(f, offset);
4243
f->offset = 0;
4344
}
44-
if (final) {
45+
if (flags & (CSUM_CLOSE | CSUM_FSYNC)) {
4546
/* write checksum and close fd */
4647
SHA1_Final(f->buffer, &f->ctx);
4748
if (result)
4849
hashcpy(result, f->buffer);
4950
sha1flush(f, 20);
51+
if (flags & CSUM_FSYNC)
52+
fsync_or_die(f->fd, f->name);
5053
if (close(f->fd))
5154
die("%s: sha1 file error on close (%s)",
5255
f->name, strerror(errno));

csum-file.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ struct sha1file {
1616
unsigned char buffer[8192];
1717
};
1818

19+
/* sha1close flags */
20+
#define CSUM_CLOSE 1
21+
#define CSUM_FSYNC 2
22+
1923
extern struct sha1file *sha1fd(int fd, const char *name);
2024
extern struct sha1file *sha1fd_throughput(int fd, const char *name, struct progress *tp);
21-
extern int sha1close(struct sha1file *, unsigned char *, int);
25+
extern int sha1close(struct sha1file *, unsigned char *, unsigned int);
2226
extern int sha1write(struct sha1file *, void *, unsigned int);
2327
extern void crc32_begin(struct sha1file *);
2428
extern uint32_t crc32_end(struct sha1file *);

fast-import.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ static char *create_index(void)
890890
SHA1_Update(&ctx, (*c)->sha1, 20);
891891
}
892892
sha1write(f, pack_data->sha1, sizeof(pack_data->sha1));
893-
sha1close(f, NULL, 1);
893+
sha1close(f, NULL, CSUM_FSYNC);
894894
free(idx);
895895
SHA1_Final(pack_data->sha1, &ctx);
896896
return tmpfile;

git-repack.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ then
125125
# We know $existing are all redundant.
126126
if [ -n "$existing" ]
127127
then
128-
sync
129128
( cd "$PACKDIR" &&
130129
for e in $existing
131130
do

index-pack.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
694694
if (!from_stdin) {
695695
close(input_fd);
696696
} else {
697+
fsync_or_die(output_fd, curr_pack_name);
697698
err = close(output_fd);
698699
if (err)
699700
die("error while closing pack file: %s", strerror(errno));

pack-write.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ char *write_idx_file(char *index_name, struct pack_idx_entry **objects,
139139
}
140140

141141
sha1write(f, sha1, 20);
142-
sha1close(f, NULL, 1);
142+
sha1close(f, NULL, CSUM_FSYNC);
143143
SHA1_Final(sha1, &ctx);
144144
return index_name;
145145
}

0 commit comments

Comments
 (0)