• S
    diff.c: buffer all output if asked to · e6e045f8
    Stefan Beller 提交于
    Introduce a new option 'emitted_symbols' in the struct diff_options which
    controls whether all output is buffered up until all output is available.
    It is set internally in diff.c when necessary.
    
    We'll have a new struct 'emitted_string' in diff.c which will be used to
    buffer each line.  The emitted_string will duplicate the memory of the
    line to buffer as that is easiest to reason about for now. In a future
    patch we may want to decrease the memory usage by not duplicating all
    output for buffering but rather we may want to store offsets into the
    file or in case of hunk descriptions such as the similarity score, we
    could just store the relevant number and reproduce the text later on.
    
    This approach was chosen as a first step because it is quite simple
    compared to the alternative with less memory footprint.
    
    emit_diff_symbol factors out the emission part and depending on the
    diff_options->emitted_symbols the emission will be performed directly
    when calling emit_diff_symbol or after the whole process is done, i.e.
    by buffering we have add the possibility for a second pass over the
    whole output before doing the actual output.
    
    In 6440d341 (2012-03-14, diff: tweak a _copy_ of diff_options with
    word-diff) we introduced a duplicate diff options struct for word
    emissions as we may have different regex settings in there.
    When buffering the output, we need to operate on just one buffer,
    so we have to copy back the emissions of the word buffer into the
    main buffer.
    
    Unconditionally enable output via buffer in this patch as it yields
    a great opportunity for testing, i.e. all the diff tests from the
    test suite pass without having reordering issues (i.e. only parts
    of the output got buffered, and we forgot to buffer other parts).
    The test suite passes, which gives confidence that we converted all
    functions to use emit_string for output.
    Signed-off-by: NStefan Beller <sbeller@google.com>
    Signed-off-by: NJunio C Hamano <gitster@pobox.com>
    e6e045f8
diff.h 13.8 KB