Skip to content

Commit

Permalink
Add a Makefile and rename git-playback to git-playback.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
mmozuras committed May 27, 2012
1 parent 81e893c commit e4c5f5f
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 144 deletions.
28 changes: 28 additions & 0 deletions 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)
14 changes: 12 additions & 2 deletions README.md
Expand Up @@ -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.
143 changes: 1 addition & 142 deletions 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="<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<title>Git Playback</title>
<style type='text/css'>${css}</style>
<link rel='stylesheet' href='http://yandex.st/highlightjs/6.2/styles/${style}.min.css' type='text/css'>
</head>
<body>
<div id='playback'>
<div class='container'>"

htmlEnd="</div>
</div>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script src='http://yandex.st/highlightjs/6.2/highlight.min.js'></script>
<script type='text/javascript'>${js}</script>
<script>
jQuery(document).ready(function(){
jQuery('#playback').playback();
hljs.initHighlightingOnLoad();
var background = jQuery('pre code').css('background-color');
jQuery('body').css('background-color', background);
});
</script>
</body>
</html>"


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 '<div><ul>' >> $output_file
for file in ${files[@]}
do
echo '<li><pre><code>' >> $output_file
if [ -f $file ]; then
cat $file >> $output_file
fi
echo '</code></pre></li>' >> $output_file
done
echo '</ul></div>' >> $output_file
fi
}

rm -f $output_file
echo $htmlStart >> $output_file
foreach_git_revision output_to_file
echo $htmlEnd >> $output_file
git-playback.sh
142 changes: 142 additions & 0 deletions 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="<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<title>Git Playback</title>
<style type='text/css'>${css}</style>
<link rel='stylesheet' href='http://yandex.st/highlightjs/6.2/styles/${style}.min.css' type='text/css'>
</head>
<body>
<div id='playback'>
<div class='container'>"

htmlEnd="</div>
</div>
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script src='http://yandex.st/highlightjs/6.2/highlight.min.js'></script>
<script type='text/javascript'>${js}</script>
<script>
jQuery(document).ready(function(){
jQuery('#playback').playback();
hljs.initHighlightingOnLoad();
var background = jQuery('pre code').css('background-color');
jQuery('body').css('background-color', background);
});
</script>
</body>
</html>"


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 '<div><ul>' >> $output_file
for file in ${files[@]}
do
echo '<li><pre><code>' >> $output_file
if [ -f $file ]; then
cat $file >> $output_file
fi
echo '</code></pre></li>' >> $output_file
done
echo '</ul></div>' >> $output_file
fi
}

rm -f $output_file
echo $htmlStart >> $output_file
foreach_git_revision output_to_file
echo $htmlEnd >> $output_file

0 comments on commit e4c5f5f

Please sign in to comment.