# (C) 2011-2025 magicant

# Completion script for the "git-log" command.
# Supports Git 2.48.1.

function completion/git-log {
        WORDS=(git log "${WORDS[2,-1]}")
        command -f completion//reexecute
}

function completion/git::log:arg {

        OPTIONS=()
        command -f completion/git::log:getopt

        command -f completion//parseoptions -n
        case $ARGOPT in
                (-)
                        command -f completion//completeoptions
                        ;;
                ('')
                        command -f completion/git::completerefpath range=true
                        ;;
                (*)
                        command -f completion/git::log:compopt
                        ;;
        esac

}

function completion/git::log:getopt {
        OPTIONS=("$OPTIONS" #>#
        "--bisect; show commits between good and bad only"
        "--clear-decorations; decorate with the default set of refs"
        "--decorate::; show ref names of commits"
        "--decorate-refs::; only decorate with refs that match the given pattern"
        "--decorate-refs-exclude::; only decorate with refs that don't match the given pattern"
        "--follow; show history beyond filename renaming"
        "--full-diff; show diffs for all files affected in each commit"
        "L:; specify a range in a file to trace history"
        "--log-size; print its size before printing log messages"
        "--mailmap --use-mailmap; canonicalize authors, committers and emails"
        "--no-decorate; like --decorate=no"
        "--no-mailmap --no-use-mailmap; cancel the --mailmap option"
        "--source; show from which ref each commit was reached"
        "t; show tree objects in the diff"
        ) #<#
        if command -vf completion/git::rev-list:getopt >/dev/null 2>&1 ||
                        . -AL completion/git-rev-list; then
                command -f completion/git::rev-list:getopt
        fi
        if command -vf completion/git::diff-tree:getopt >/dev/null 2>&1 ||
                        . -AL completion/git-diff-tree; then
                command -f completion/git::diff-tree:getopt
        fi
}

function completion/git::log:compopt
        case $ARGOPT in
                (--decorate) #>>#
                        complete -P "$PREFIX" -D "like short, only if outputting to a terminal" auto
                        complete -P "$PREFIX" -D "show full ref names" full
                        complete -P "$PREFIX" -D "show ref names without prefixes" short
                        complete -P "$PREFIX" -D "don't show ref names" no
                        ;; #<<#
                (--decorate-refs*)
                        command -f completion/git::completeref
                        ;;
                (L)
                        case $TARGETWORD in (?*:*)
                                typeset w="${TARGETWORD#?*:}"
                                typeset PREFIX="${TARGETWORD%"$w"}"
                                command -f completion/git::completepath -r
                        esac
                        ;;
                (*)
                        command -f completion/git::rev-list:compopt ||
                        command -f completion/git::diff:compopt
                        ;;
        esac


# vim: set ft=sh ts=8 sts=8 sw=8 et:
