| James Tucker | ec997f1 | 2019-02-01 15:34:13 -0800 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # Copyright 2019 The Fuchsia Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
| 6 | usage() { |
| 7 | cat <<EOF |
| 8 | git follow-log -h |
| 9 | print help |
| 10 | git follow-log <path> [<git-log options>] |
| 11 | produce git-log output for all objects under <path> |
| 12 | additional options for git-log can be provided later. only a subset |
| 13 | of git-log options will work. |
| 14 | EOF |
| 15 | exit 1 |
| 16 | } |
| 17 | |
| 18 | git_follow_log() { |
| 19 | test $# -eq 0 && usage |
| 20 | while [ $# -gt 0 ]; do |
| 21 | arg="$1" |
| 22 | case "$arg" in |
| 23 | -h|--help|help) |
| 24 | usage |
| 25 | ;; |
| 26 | *) |
| 27 | if [ "$have_path" == true ]; then |
| 28 | args+=("$arg") |
| 29 | else |
| 30 | have_path=true |
| 31 | path="$arg" |
| 32 | fi |
| 33 | ;; |
| 34 | esac |
| 35 | shift |
| 36 | done |
| 37 | for p in $(git log --name-only --pretty=format: "$path" | sort -u); do |
| 38 | git --no-pager log --follow --no-abbrev-commit --format=%H -- ":(top)$p" |
| 39 | done | git log --stdin --no-walk=sorted "$@" |
| 40 | } |
| 41 | |
| 42 | git_follow_log "$@" |