r-lib / gert

Simple git client for R
https://docs.ropensci.org/gert/
Other
146 stars 31 forks source link

Implement --shortstat option for git_log function #201

Open i2z1 opened 1 year ago

i2z1 commented 1 year ago

Implement option to show additions and deletions in commit as we can perform with

git log --shortstat

So with gert it can be done with something like

gert::git_log(repo = ".", shortstat = TRUE)

jeroen commented 1 year ago

Maybe you can create something yourself from looking up the diff/patch for each commit

df <- gert::git_log(max=10)
df$shortstat <- lapply(df$commit, function(id){
  patch <- gert::git_diff_patch(id)
  # do something with stats
})
i2z1 commented 1 year ago

Yes, it is working walkaround for problem, but is there libgit2 limitations? This walkaround recipe needs further parsing for diff output. Or is it package architecture decision?

jeroen commented 1 year ago

We could probably do it using libgit2, but it adds more overhead. What do you need this for?

jeroen commented 1 year ago

I have added a new function git_commit_stats for you: https://github.com/r-lib/gert/commit/d4b28083f07eecebda3a395a4c582c93d5caa663. You can install the new version from https://ropensci.r-universe.dev/gert

So you can do e.g.:


library(gert)
logs <- git_log(max=10)
stats <- lapply(logs$commit, git_commit_stats)
i2z1 commented 1 year ago

Thanks a lot!!! I am trying to analyze commits, who are just fixing typos in comments and who are writing code but maybe without any comments etc...

i2z1 commented 1 year ago

One more question -- is it possible to get all commits from all branches like git log --all with gert::git_log() function?

jeroen commented 1 year ago

One more question -- is it possible to get all commits from all branches like git log --all with gert::git_log() function?

No not yet, we just recursively walk to the parent commits right now, without considering branches. It's been on the todo list to implement something better but I haven't gotten to it.