Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #!/usr/bin/sh
  2.  
  3. print_usage_and_exit() {
  4. echo "Usage: $0 [-d <date>] [-p <path>]"
  5. echo ""
  6. echo "Searches for DM files never edited since a threshold date."
  7. echo ""
  8. echo "Arguments:"
  9. echo " -d, --date <date> Threshold date to use, defaults to 2013-01-01."
  10. echo " -p, --path <path> Path inside the git repository to search in."
  11. echo " -h, --help Show this help message."
  12.  
  13. exit 0
  14. }
  15.  
  16. # Parse arguments
  17. THRESHOLD_DATE="2013-01-01"
  18. FOLDER_TO_SEARCH="$PWD"
  19.  
  20. while [[ $# > 0 ]]; do
  21. arg="$1"
  22. case $arg in
  23. -d|--date)
  24. THRESHOLD_DATE="$2"
  25. shift
  26. ;;
  27.  
  28. -p|--path)
  29. FOLDER_TO_SEARCH="$2"
  30. shift
  31. ;;
  32.  
  33. -h|--help)
  34. print_usage_and_exit
  35. ;;
  36.  
  37. *) # default
  38. echo "Unknown argument found: $arg"
  39. print_usage_and_exit
  40. ;;
  41. esac
  42. shift
  43. done
  44.  
  45. # Check whether $FOLDER_TO_SEARCH is a git repository and get the root directory
  46. FOLDER_TO_SEARCH=$(git -C "$FOLDER_TO_SEARCH" rev-parse --show-toplevel)
  47. [[ $? -ne 0 ]] && exit 0 # return code is non-zero on failure
  48.  
  49. # Do stuff
  50. TMP_GITLOG=$(mktemp)
  51. TMP_FIND=$(mktemp)
  52.  
  53. git -C "$FOLDER_TO_SEARCH" log --name-only --after="$THRESHOLD_DATE" --pretty='tformat:' | grep -E '\.dm$' | sort | uniq > "$TMP_GITLOG"
  54. ( cd "$FOLDER_TO_SEARCH" && find . -iname '*.dm' -type f ) | sed 's/^\.\///' | sort > "$TMP_FIND"
  55.  
  56. # Supress files only in $TMP_GITLOG (i.e. files that no longer exist) and in both $TMP_GITLOG
  57. # and $TMP_FIND (i.e. changed after $THRESHOLD_DATE)
  58. comm -1 -3 "$TMP_GITLOG" "$TMP_FIND"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement