Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jez committed Jan 9, 2018
1 parent 418b9bd commit 7de222d
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# git-heatmap

> Display a heatmap for oft-edited files
![screenshot of git heatmap](screenshot.png)

## Install

### Dependencies

You must have the `bars` command on your system first:

```
npm install -g https://github.com/jez/bars.git
```

### Installation

Download `git-heatmap` and put it on your path.

```bash
# Homebrew:
brew install jez/formulae/git-heatmap
```

## Usage

```
❯ git heatmap -h
Heatmap of oft-edited files.
Usage:
git heatmap [options] [<path>...]
Options:
-n <top> Limit to top <n> files. [default: 30]
--width <n> Limit histogram to <n> chars.
-b <branch>, --base <branch> Compare relative to <branch>. If on <branch>,
show heatmap for entire repo. [default: master]
-h Show this message.
```

## License

[![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://jez.io/MIT-LICENSE.txt)
76 changes: 76 additions & 0 deletions git-heatmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env bash

# Build a commit frequency histogram

ccyan="$(echo -ne '\033[0;36m')"
cnone="$(echo -ne '\033[0m')"

argv=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-n)
LIMIT="$2"
shift
shift
;;
-b|--base)
REVIEW_BASE="$2"
shift
shift
;;
-h)
cat <<EOF
Heatmap of oft-edited files.
Usage:
git heatmap [options] [<path>...]
Options:
-n <top> Limit to top <n> files. [default: 30]
-b <branch>, --base <branch> Compare relative to <branch>. If on <branch>,
show heatmap for entire repo. [default: master]
-h Show this message.
EOF
exit
;;
*)
argv+=("$1")
shift
;;
esac
done

LIMIT=${LIMIT:-30}
REVIEW_BASE=${REVIEW_BASE:-master}

files() {
git log --name-status --pretty=format: -- "${argv[@]}" | cut -f 2-
}

color_name() {
# \(.*\/\)\([^/ ]*\)
sed -e "s/\(..*\/\)*\(.[^|]*\) |/\1$ccyan\2$cnone |/"
}

filter() {
sort | \
uniq -c | \
sort -nr | \
tail -n +2 | \
head -n "$LIMIT"
}

if [[ "$(git branch | grep '\*')" =~ $REVIEW_BASE ]]; then
# If on master, show heatmap for whole repo
files | filter | bars --bar █ | color_name
else
MERGE_BASE="$(git merge-base HEAD "$REVIEW_BASE")"
files | \
# If on separate branch, show heatmap for files changed since master
grep -xF -f <(git diff --name-only "$MERGE_BASE") | \
filter | \
bars --bar █ | \
color_name
fi

Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7de222d

Please sign in to comment.