From e4c5f5ff49fa4a51ada87b8e167a87495b5cf723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mindaugas=20Moz=C5=ABras?= Date: Sun, 27 May 2012 16:37:53 +0300 Subject: [PATCH] Add a Makefile and rename git-playback to git-playback.sh --- Makefile | 28 ++++++++++ README.md | 14 ++++- git-playback | 143 +----------------------------------------------- git-playback.sh | 142 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 183 insertions(+), 144 deletions(-) create mode 100644 Makefile create mode 100755 git-playback.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..df89f11 --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +prefix ?= /usr/local +gitdir ?= $(shell git --exec-path) + +gitver ?= $(word 3,$(shell git --version)) + +INSTALL ?= install +INSTALL_DATA = $(INSTALL) -c -m 0644 +INSTALL_EXE = $(INSTALL) -c -m 0755 +INSTALL_DIR = $(INSTALL) -c -d -m 0755 + +default: + @echo "git-playback doesn't need to be built." + @echo "Just copy it (including playback.css and playback.js) somewhere on your PATH, like /usr/local/bin." + @false + +install: install-exe install-js install-css + +install-exe: git-playback.sh + $(INSTALL_DIR) $(DESTDIR)/$(gitdir) + $(INSTALL_EXE) $< $(DESTDIR)/$(gitdir)/git-playback + +install-js: playback.js + $(INSTALL_DIR) $(DESTDIR)/$(gitdir) + $(INSTALL_DATA) $< $(DESTDIR)/$(gitdir) + +install-css: playback.css + $(INSTALL_DIR) $(DESTDIR)/$(gitdir) + $(INSTALL_DATA) $< $(DESTDIR)/$(gitdir) diff --git a/README.md b/README.md index 8f669bd..13a2dd9 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,17 @@ git-playback is a bash script that creates a visual playback of git commits. Use git clone git://github.com/mmozuras/git-playback.git cd /repository/you/want/to/playback - sh /path/to/git-playback/git-playback file1 file2 + sh /path/to/git-playback/git-playback.sh file1 file2 open playback.html -git-playback automatically uses the branch you're currently on. Output will be written to playback.html. +Output will be written to playback.html. Use left and right arrows to navigate. + +To see a list of available options run git-playback with --help. + +# Installing + +You can also install git-playback to make it work like every other git command. Simply copy git-playback.sh to where the rest of the git scripts are stored. There's also a make command for that: + + make install + +This will make 'git playback' command available. diff --git a/git-playback b/git-playback index f3eea7f..f2bb4b9 100755 --- a/git-playback +++ b/git-playback @@ -1,142 +1 @@ -#!/bin/bash - -set -e - -if [ $# -eq 0 ]; then - set -- -h -fi - -OPTS_SPEC="\ -git playback file1 file2 ... --- -h,help show the help -s,start= specify start revision -e,end= specify end revision -t,style= specify style to be used in output -l,stylelist list all available styles -" -eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)" - -get_git_branch() { - git branch 2>/dev/null | grep -e ^* | tr -d \* -} - -get_root_commit() { - git rev-list --max-parents=0 HEAD 2>/dev/null | tr -d \* -} - -files=() -output_file='playback.html' -start_revision=`get_root_commit` -end_revision=`get_git_branch` -style='default' -available_styles=(default dark far idea sunburst zenburn vs ascetic magula github googlecode brown_paper school_book ir_black solarized_dark solarized_light arta monokai) - -while [ $# -gt 0 ]; do - opt="$1" - shift - case "$opt" in - -s) start_revision="$1"; shift;; - -e) end_revision="$1"; shift;; - -t) style="$1"; shift;; - -l) echo ${available_styles[@]}; exit;; - *) files+=("$1") ;; - esac -done - -is_style_available() { - for i in ${available_styles[@]}; do - if [ $i == $1 ]; then - return 1 - fi - done - return 0 -} - -if is_style_available $style; then - echo "Style is not available: ${style}. You can list available styles with --stylelist." - exit 1 -fi - -source_file="${BASH_SOURCE[0]}" -while [ -h "$source_file" ]; do - source_file="$(readlink "$source_file")"; -done -script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd -P "$(dirname "$source_file")" && pwd)" -unset source_file - -js=`cat ${script_dir}/playback.js` -css=`cat ${script_dir}/playback.css` -htmlStart=" - - - - Git Playback - - - - - -
-
" - -htmlEnd="
-
- - - - - - -" - - -foreach_git_revision() { - command=$1 - - revisions=`git rev-list --reverse ${end_revision} ^${start_revision}` - - for revision in $revisions; do - git checkout --quiet $revision - eval $command - git reset --hard - done - - git checkout --quiet $end_revision -} - -output_to_file() { - no_files=true - for file in ${files[@]} - do - if [ -f $file ] && [ -s $file ]; then - no_files=false - fi - done - - if ! $no_files; then - echo '
' >> $output_file - fi -} - -rm -f $output_file -echo $htmlStart >> $output_file -foreach_git_revision output_to_file -echo $htmlEnd >> $output_file +git-playback.sh diff --git a/git-playback.sh b/git-playback.sh new file mode 100755 index 0000000..2c32606 --- /dev/null +++ b/git-playback.sh @@ -0,0 +1,142 @@ +#!/bin/bash + +set -e + +if [ $# -eq 0 ]; then + set -- -h +fi + +OPTS_SPEC="\ +git playback file1 file2 ... +-- +h,help show the help +s,start= specify start revision. Default: root commit +e,end= specify end revision. Default: current branch +t,style= specify style to be used in output +l,stylelist list all available styles +" +eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)" + +get_git_branch() { + git branch 2>/dev/null | grep -e ^* | tr -d \* +} + +get_root_commit() { + git rev-list --max-parents=0 HEAD 2>/dev/null | tr -d \* +} + +files=() +output_file='playback.html' +start_revision=`get_root_commit` +end_revision=`get_git_branch` +style='default' +available_styles=(default dark far idea sunburst zenburn vs ascetic magula github googlecode brown_paper school_book ir_black solarized_dark solarized_light arta monokai) + +while [ $# -gt 0 ]; do + opt="$1" + shift + case "$opt" in + -s) start_revision="$1"; shift;; + -e) end_revision="$1"; shift;; + -t) style="$1"; shift;; + -l) echo ${available_styles[@]}; exit;; + *) files+=("$1") ;; + esac +done + +is_style_available() { + for i in ${available_styles[@]}; do + if [ $i == $1 ]; then + return 1 + fi + done + return 0 +} + +if is_style_available $style; then + echo "Style is not available: ${style}. You can list available styles with --stylelist." + exit 1 +fi + +source_file="${BASH_SOURCE[0]}" +while [ -h "$source_file" ]; do + source_file="$(readlink "$source_file")"; +done +script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd -P "$(dirname "$source_file")" && pwd)" +unset source_file + +js=`cat ${script_dir}/playback.js` +css=`cat ${script_dir}/playback.css` +htmlStart=" + + + + Git Playback + + + + + +
+
" + +htmlEnd="
+
+ + + + + + +" + + +foreach_git_revision() { + command=$1 + + revisions=`git rev-list --reverse ${end_revision} ^${start_revision}` + + for revision in $revisions; do + git checkout --quiet $revision + eval $command + git reset --hard + done + + git checkout --quiet $end_revision +} + +output_to_file() { + no_files=true + for file in ${files[@]} + do + if [ -f $file ] && [ -s $file ]; then + no_files=false + fi + done + + if ! $no_files; then + echo '
' >> $output_file + fi +} + +rm -f $output_file +echo $htmlStart >> $output_file +foreach_git_revision output_to_file +echo $htmlEnd >> $output_file