gert icon indicating copy to clipboard operation
gert copied to clipboard

Implement --shortstat option for git_log function

Open i2z1 opened this issue 2 years ago • 7 comments

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)

i2z1 avatar Jul 02 '23 15:07 i2z1

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
})

jeroen avatar Jul 02 '23 18:07 jeroen

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?

i2z1 avatar Jul 03 '23 17:07 i2z1

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

jeroen avatar Jul 03 '23 20:07 jeroen

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)

jeroen avatar Jul 03 '23 21:07 jeroen

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 avatar Jul 06 '23 19:07 i2z1

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

i2z1 avatar Jul 06 '23 19:07 i2z1

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.

jeroen avatar Jul 06 '23 21:07 jeroen