summaryrefslogtreecommitdiff
path: root/convert.c
diff options
context:
space:
mode:
authorJohannes Sixt <johannes.sixt@telecom.at>2007-10-19 19:48:05 (GMT)
committerShawn O. Pearce <spearce@spearce.org>2007-10-21 05:30:42 (GMT)
commit7683b6e81fa0f1f55d4974d69fb87c7c7b6b394e (patch)
tree84ad5197c3affed0a06bb51c3dd1ae115bbde0ca /convert.c
parenta0ae35ae2d92cc706f902227cb0f34e2a2f0fd50 (diff)
downloadgit-7683b6e81fa0f1f55d4974d69fb87c7c7b6b394e.zip
git-7683b6e81fa0f1f55d4974d69fb87c7c7b6b394e.tar.gz
git-7683b6e81fa0f1f55d4974d69fb87c7c7b6b394e.tar.bz2
Avoid a dup2(2) in apply_filter() - start_command() can do it for us.
When apply_filter() runs the external (clean or smudge) filter program, it needs to pass the writable end of a pipe as its stdout. For this purpose, it used to dup2(2) the file descriptor explicitly to stdout. Now we use the facilities of start_command() to do it for us. Furthermore, the path argument of a subordinate function, filter_buffer(), was not used, so here we replace it to pass the fd instead. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'convert.c')
-rw-r--r--convert.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/convert.c b/convert.c
index d83c2fc..8dc9965 100644
--- a/convert.c
+++ b/convert.c
@@ -192,7 +192,7 @@ static int crlf_to_worktree(const char *path, const char *src, size_t len,
return 1;
}
-static int filter_buffer(const char *path, const char *src,
+static int filter_buffer(int fd, const char *src,
unsigned long size, const char *cmd)
{
/*
@@ -205,6 +205,7 @@ static int filter_buffer(const char *path, const char *src,
memset(&child_process, 0, sizeof(child_process));
child_process.argv = argv;
child_process.in = -1;
+ child_process.out = fd;
if (start_command(&child_process))
return error("cannot fork to run external filter %s", cmd);
@@ -254,10 +255,8 @@ static int apply_filter(const char *path, const char *src, size_t len,
return 0;
}
if (!child_process.pid) {
- dup2(pipe_feed[1], 1);
close(pipe_feed[0]);
- close(pipe_feed[1]);
- exit(filter_buffer(path, src, len, cmd));
+ exit(filter_buffer(pipe_feed[1], src, len, cmd));
}
close(pipe_feed[1]);