Skip to content

Instantly share code, notes, and snippets.

@rgrannell1
Created June 6, 2014 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rgrannell1/4d9d3b8dbf7707ae6983 to your computer and use it in GitHub Desktop.
Save rgrannell1/4d9d3b8dbf7707ae6983 to your computer and use it in GitHub Desktop.
git-loc
# 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