• J
    reflog: add for_each_reflog_ent_reverse() API · 98f85ff4
    Junio C Hamano 提交于
    "git checkout -" is a short-hand for "git checkout @{-1}" and the
    "@{nth}" notation for a negative number is to find nth previous
    checkout in the reflog of the HEAD to determine the name of the
    branch the user was on.  We would want to find the nth most recent
    reflog entry that matches "checkout: moving from X to Y" for this.
    
    Unfortunately, reflog is implemented as an append-only file, and the
    API to iterate over its entries, for_each_reflog_ent(), reads the
    file in order, giving the entries from the oldest to newer.  For the
    purpose of finding nth most recent one, this API forces us to record
    the last n entries in a rotating buffer and give the result out only
    after we read everything.  To optimize for a common case of finding
    the nth most recent one for a small value of n, we also have a side
    API for_each_recent_reflog_ent() that starts reading near the end of
    the file, but it still has to read the entries in the "wrong" order.
    The implementation of understanding @{-1} uses this interface.
    
    This all becomes unnecessary if we add an API to let us iterate over
    reflog entries in the reverse order, from the newest to older.
    Signed-off-by: NJunio C Hamano <gitster@pobox.com>
    98f85ff4
refs.h 6.0 KB