Is there a --stat or --numstat like option that'll allow me to have my cake and eat it too?
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Mar 8, 2016, 15:08 UTC
- Message-ID
- <CACBZZX7o+VA1RVvja3xtBQf+rr2bWoByas4D5GKZ_VfQr7H19w@mail.gmail.com>
I maintain a hook for Git that allows you to block binary pushes[1], from other implementations I've seen it's the least stupid thing out there that does that.
Basically on-push it parses this:
git log --pretty=format:%H -M100% --stat=9000,9001 <old_ref>..<new_ref>
The --stat=9000,9001 is there to make sure we still get the filename if it's long[2].
It's important that this is something like "git-log" instead of "git-show for each" for performance (think a push with hundreds of commits). It's also important that it's not "git diff" (think a push that adds/removes a huge binary file within one push). I also don't want to manually parse "git log --numstat -p" or whatever for performance reasons since every push hangs on this.
It's somewhat of a pain to parse that --stat output, because I have to look for /\|\s+Bin / in the output to detect binary changes.
You might be thinking "why don't you use --numstat?". Because while that option does most of what I want it doesn't show the old/new size of the binary file, so I can't have a policy to allow e.g. <=1KB files without doing a second pass with --stat or "git show".
Both formats also have various parsing edge cases, e.g. with -M100% I have to parse out renames like "foo.png => bar.png", but you can also create a file with " => " in the filename and there's no way to disambiguate it.
Both formats also only show lines added/deleted, but --numstat doesn't show the size before/after for binary files, so if I want to also prohibit huge non-binary files I can't without running both --stat and --numstat.
What I really want is something for git-log more like git-for-each-ref, so I could emit the following info for each file being modified delimited by some binary marker:
- file name before
- file name after
- is rename?
- is binary?
- size in bytes before
- size it bytes after
- removed lines
- added linesI think no combination of git-log options or any built-in machinery comes close to giving me all of that without having to do multiple passes with some combination of git-log and git-show, but I'd love to be proven wrong.
1. https://github.com/avar/pre-receive-reject-binaries 2. OVER NINE THOUSAND should be enough for everyone, right?