From 5744b78be0d7ff168dcaf777c2f98818aab3862f Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 23 Feb 2024 00:04:34 -0500 Subject: git helpers should be installed with git, not with the other bin files --- git/.bin/git/git-amend | 13 +++++++++++++ git/.bin/git/git-blame-stats | 37 +++++++++++++++++++++++++++++++++++++ git/.bin/git/git-default-branch | 4 ++++ git/.bin/git/git-file-size | 5 +++++ git/.bin/git/git-pr | 5 +++++ git/.bin/git/git-record | 13 +++++++++++++ git/.bin/git/git-root | 9 +++++++++ 7 files changed, 86 insertions(+) create mode 100755 git/.bin/git/git-amend create mode 100755 git/.bin/git/git-blame-stats create mode 100755 git/.bin/git/git-default-branch create mode 100755 git/.bin/git/git-file-size create mode 100755 git/.bin/git/git-pr create mode 100755 git/.bin/git/git-record create mode 100755 git/.bin/git/git-root (limited to 'git') diff --git a/git/.bin/git/git-amend b/git/.bin/git/git-amend new file mode 100755 index 0000000..3b937ec --- /dev/null +++ b/git/.bin/git/git-amend @@ -0,0 +1,13 @@ +#!/bin/sh +set -eu + +if [ -e "$(git root)/.git/branchless" ]; then + exec git branchless amend "$@" +else + if [ "${1:-}" = "-i" ]; then + git add -p + else + git add -u + fi + git commit --amend +fi diff --git a/git/.bin/git/git-blame-stats b/git/.bin/git/git-blame-stats new file mode 100755 index 0000000..320d755 --- /dev/null +++ b/git/.bin/git/git-blame-stats @@ -0,0 +1,37 @@ +#!/usr/bin/perl + +use Getopt::Long; +use POSIX qw(ceil); +use strict; +Getopt::Long::Configure(qw(bundling)); +my %authors; +my $total; +my $files; +my $rev = shift(@ARGV) || "HEAD"; + +foreach my $file (`git ls-tree --name-only -r $rev`) { + chomp($file); + print STDERR "Processing $file\n"; + foreach my $line (`git blame -M -w $rev -- "$file"`) { + chomp($line); + if (substr($line, 0, 1) eq "^") { + ++$authors{"*initial checkin"}; + } else { + $line =~ s[^.*?\((.*?)\s*\d{4}-\d{2}-\d{2}.*][$1]; + ++$authors{$line}; + } + ++$total; + } +} + +print "Total lines: $total\n"; +my $i = 0; +my $author_ind = ceil(log(scalar(keys %authors)) / log(10)); +my $lines_ind = ceil(log($total) / log(10)); +foreach my $author (sort { $authors{$b} <=> $authors{$a} } keys %authors) { + printf "%${author_ind}s %${lines_ind}u %5.2f%% %s\n", + sprintf("#%u", ++$i), + $authors{$author}, + $authors{$author} * 100 / $total, + $author; +} diff --git a/git/.bin/git/git-default-branch b/git/.bin/git/git-default-branch new file mode 100755 index 0000000..90e225f --- /dev/null +++ b/git/.bin/git/git-default-branch @@ -0,0 +1,4 @@ +#!/bin/sh +set -eu + +git symbolic-ref refs/remotes/origin/HEAD | sed 's/.*\///' diff --git a/git/.bin/git/git-file-size b/git/.bin/git/git-file-size new file mode 100755 index 0000000..0e7d00d --- /dev/null +++ b/git/.bin/git/git-file-size @@ -0,0 +1,5 @@ +#!/bin/sh +set -eu +set -o pipefail + +git ls-files -z | xargs -0 du -b | sum diff --git a/git/.bin/git/git-pr b/git/.bin/git/git-pr new file mode 100755 index 0000000..61346bc --- /dev/null +++ b/git/.bin/git/git-pr @@ -0,0 +1,5 @@ +#!/bin/sh + +pr_num="$1" +upstream="${2-origin}" +git fetch "$upstream" "pull/${pr_num}/head:pull-${pr_num}" diff --git a/git/.bin/git/git-record b/git/.bin/git/git-record new file mode 100755 index 0000000..eaa36c9 --- /dev/null +++ b/git/.bin/git/git-record @@ -0,0 +1,13 @@ +#!/bin/sh +set -eu + +if [ -e "$(git root)/.git/branchless" ]; then + exec git branchless record "$@" +else + if [ "${1:-}" = "-i" ]; then + git add -p + else + git add -u + fi + git commit +fi diff --git a/git/.bin/git/git-root b/git/.bin/git/git-root new file mode 100755 index 0000000..96fb395 --- /dev/null +++ b/git/.bin/git/git-root @@ -0,0 +1,9 @@ +#!/bin/sh +set -eu + +root="$(git rev-parse --show-superproject-working-tree 2>/dev/null)" +if [ -n "$root" ]; then + echo "$root" +else + git rev-parse --show-toplevel +fi -- cgit v1.2.3-54-g00ecf