aboutsummaryrefslogtreecommitdiff
path: root/entry.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2011-05-12 21:36:42 -0700
committerJunio C Hamano <gitster@pobox.com>2011-05-20 18:38:54 -0700
commitfd5db55d8b6668a1ff9583a6636a4d54ad9519f2 (patch)
tree55d092858570a0c35613245e1abca049808fe822 /entry.c
parentf8c8abc5b76ffd763b9c7c5e4fb054358e82ca28 (diff)
downloadgit-fd5db55d8b6668a1ff9583a6636a4d54ad9519f2.tar.gz
git-fd5db55d8b6668a1ff9583a6636a4d54ad9519f2.tar.xz
write_entry(): separate two helper functions out
In the write-out codepath, a block of code determines what file in the working tree to write to, and opens an output file descriptor to it. After writing the contents out to the file, another block of code runs fstat() on the file descriptor when appropriate. Separate these blocks out to open_output_fd() and fstat_output() helper functions. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'entry.c')
-rw-r--r--entry.c43
1 files changed, 26 insertions, 17 deletions
diff --git a/entry.c b/entry.c
index b017167f2..cc6502a54 100644
--- a/entry.c
+++ b/entry.c
@@ -91,6 +91,29 @@ static void *read_blob_entry(struct cache_entry *ce, unsigned long *size)
return NULL;
}
+static int open_output_fd(char *path, struct cache_entry *ce, int to_tempfile)
+{
+ int symlink = (ce->ce_mode & S_IFMT) != S_IFREG;
+ if (to_tempfile) {
+ strcpy(path, symlink
+ ? ".merge_link_XXXXXX" : ".merge_file_XXXXXX");
+ return mkstemp(path);
+ } else {
+ return create_file(path, !symlink ? ce->ce_mode : 0666);
+ }
+}
+
+static int fstat_output(int fd, const struct checkout *state, struct stat *st)
+{
+ /* use fstat() only when path == ce->name */
+ if (fstat_is_reliable() &&
+ state->refresh_cache && !state->base_dir_len) {
+ fstat(fd, st);
+ return 1;
+ }
+ return 0;
+}
+
static int write_entry(struct cache_entry *ce, char *path, const struct checkout *state, int to_tempfile)
{
unsigned int ce_mode_s_ifmt = ce->ce_mode & S_IFMT;
@@ -128,17 +151,7 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout
size = newsize;
}
- if (to_tempfile) {
- if (ce_mode_s_ifmt == S_IFREG)
- strcpy(path, ".merge_file_XXXXXX");
- else
- strcpy(path, ".merge_link_XXXXXX");
- fd = mkstemp(path);
- } else if (ce_mode_s_ifmt == S_IFREG) {
- fd = create_file(path, ce->ce_mode);
- } else {
- fd = create_file(path, 0666);
- }
+ fd = open_output_fd(path, ce, to_tempfile);
if (fd < 0) {
free(new);
return error("unable to create file %s (%s)",
@@ -146,12 +159,8 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout
}
wrote = write_in_full(fd, new, size);
- /* use fstat() only when path == ce->name */
- if (fstat_is_reliable() &&
- state->refresh_cache && !to_tempfile && !state->base_dir_len) {
- fstat(fd, &st);
- fstat_done = 1;
- }
+ if (!to_tempfile)
+ fstat_done = fstat_output(fd, state, &st);
close(fd);
free(new);
if (wrote != size)