log: prepare log/log-tree to reuse the diffopt.close_file attribute
We are about to teach the log-tree machinery to reuse the diffopt.file field to output to a file stream other than stdout, in line with the diff machinery already writing to diffopt.file. However, we might want to write something after the diff in log_tree_commit() (e.g. with the --show-linear-break option), therefore we must not let the diff machinery close the file (as per diffopt.close_file. This means that log_tree_commit() itself must override the diffopt.close_file flag and close the file, and if log_tree_commit() is called in a loop, the caller is responsible to do the same. Note: format-patch has an `--output-directory` option. Due to the fact that format-patch's options are parsed first, and that the parse-options machinery accepts uniquely abbreviated options, the diff options `--output` (and `-o`) are shadowed. Therefore close_file is not set to 1 so that cmd_format_patch() does *not* need to handle the close_file flag differently, even if it calls log_tree_commit() in a loop. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
ab7797dbe9
commit
6ea57703f6
@ -862,11 +862,12 @@ static int log_tree_diff(struct rev_info *opt, struct commit *commit, struct log
|
||||
int log_tree_commit(struct rev_info *opt, struct commit *commit)
|
||||
{
|
||||
struct log_info log;
|
||||
int shown;
|
||||
int shown, close_file = opt->diffopt.close_file;
|
||||
|
||||
log.commit = commit;
|
||||
log.parent = NULL;
|
||||
opt->loginfo = &log;
|
||||
opt->diffopt.close_file = 0;
|
||||
|
||||
if (opt->line_level_traverse)
|
||||
return line_log_print(opt, commit);
|
||||
@ -883,5 +884,7 @@ int log_tree_commit(struct rev_info *opt, struct commit *commit)
|
||||
printf("\n%s\n", opt->break_bar);
|
||||
opt->loginfo = NULL;
|
||||
maybe_flush_or_die(stdout, "stdout");
|
||||
if (close_file)
|
||||
fclose(opt->diffopt.file);
|
||||
return shown;
|
||||
}
|
||||
|
Reference in New Issue
Block a user