• K
    ref-filter: implement an `align` atom · ce592082
    Karthik Nayak 提交于
    Implement an `align` atom which left-, middle-, or right-aligns the
    content between %(align:...) and %(end).
    
    The "align:" is followed by `<width>` and `<position>` in any order
    separated by a comma, where the `<position>` is either left, right or
    middle, default being left and `<width>` is the total length of the
    content with alignment. If the contents length is more than the width
    then no alignment is performed.  e.g. to align a refname atom to the
    middle with a total width of 40 we can do:
    --format="%(align:middle,40)%(refname)%(end)".
    
    We introduce an `at_end` function for each element of the stack which
    is to be called when the `end` atom is encountered. Using this we
    implement end_align_handler() for the `align` atom, this aligns the
    final strbuf by calling `strbuf_utf8_align()` from utf8.c.
    
    Ensure that quote formatting is performed on the whole of
    %(align:...)...%(end) rather than individual atoms inside. We skip
    quote formatting for individual atoms when the current stack element
    is handling an %(align:...) atom and perform quote formatting at the
    end when we encounter the %(end) atom of the second element of then
    stack.
    
    Add documentation and tests for the same.
    Mentored-by: NChristian Couder <christian.couder@gmail.com>
    Mentored-by: NMatthieu Moy <matthieu.moy@grenoble-inp.fr>
    Helped-by: NJunio C Hamano <gitster@pobox.com>
    Signed-off-by: NKarthik Nayak <karthik.188@gmail.com>
    Signed-off-by: NJunio C Hamano <gitster@pobox.com>
    ce592082
t6302-for-each-ref-filter.sh 5.0 KB