Created
June 6, 2014 20:21
-
-
Save rgrannell1/4d9d3b8dbf7707ae6983 to your computer and use it in GitHub Desktop.
git-loc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this script is poorly-written, so use at your own risk. | |
# --------------------------------------------------------------- | |
# | |
# THIS HAS A VERY GOOD CHANCE OF COMPLETELY DESTROYING YOUR REPO; | |
# ONLY RUN THIS ON A COPY OF THE REPO!!! | |
# | |
# ---------------------------------------------------------------- | |
YOUR_REPO_PATH = '/home/ryan/Code/kiwi-nukable' | |
setwd(YOUR_REPO_PATH) | |
# -- grab the ids for each commit in the repo | |
# -- this prints out all commit id's | |
commit_ids <- lapply( | |
strsplit(system('git rev-list --all --pretty=oneline', intern = TRUE), '\n'), function (line) { | |
strsplit(line, ' ')[[1]][1] | |
} | |
) | |
# -- your head will usually be the most recent commit, so checkout most recent commit first. | |
current_HEAD <- commit_ids[[1]] | |
system(paste0('git checkout ', current_HEAD)) | |
# if you have lots of commits or are testing adjust this slice to 1..100 or something similar | |
commit_ids <- commit_ids[1:length(commit_ids)] | |
commit_info <- lapply(commit_ids, function (id) { | |
invisible( system(paste0('git checkout ', id)) ) | |
# -- get information on the version controlled lines of code | |
all_lines <- system('git ls-files | xargs wc -l', intern = TRUE) | |
lines <- strsplit(all_lines, '\n') | |
final_line <- lines[[length(lines)]] | |
# get the number giving the lines of code | |
lines_of_code <- as.numeric(gsub('[^0-9]', '', final_line)) | |
# get the date of the current commit | |
date <- as.numeric( system(paste('git show -s --format=%ct', id), intern = TRUE) ) | |
c(loc = lines_of_code, posix_time = date) | |
}) | |
lines_of_code <- vapply(commit_info, function (x) x[[1]], numeric(1)) | |
posix_time <- vapply(commit_info, function (x) x[[2]], numeric(1)) | |
plot(x = posix_time, y = lines_of_code, type = 'l', ylim = c(0, 1.2 * max(lines_of_code))) | |
system(paste0('git checkout ', current_HEAD)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment