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 +++++++++ local/.bin/git/git-amend | 13 ------------- local/.bin/git/git-blame-stats | 37 ------------------------------------- local/.bin/git/git-default-branch | 4 ---- local/.bin/git/git-file-size | 5 ----- local/.bin/git/git-pr | 5 ----- local/.bin/git/git-record | 13 ------------- local/.bin/git/git-root | 9 --------- 14 files changed, 86 insertions(+), 86 deletions(-) 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 delete mode 100755 local/.bin/git/git-amend delete mode 100755 local/.bin/git/git-blame-stats delete mode 100755 local/.bin/git/git-default-branch delete mode 100755 local/.bin/git/git-file-size delete mode 100755 local/.bin/git/git-pr delete mode 100755 local/.bin/git/git-record delete mode 100755 local/.bin/git/git-root 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 diff --git a/local/.bin/git/git-amend b/local/.bin/git/git-amend deleted file mode 100755 index 3b937ec..0000000 --- a/local/.bin/git/git-amend +++ /dev/null @@ -1,13 +0,0 @@ -#!/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/local/.bin/git/git-blame-stats b/local/.bin/git/git-blame-stats deleted file mode 100755 index 320d755..0000000 --- a/local/.bin/git/git-blame-stats +++ /dev/null @@ -1,37 +0,0 @@ -#!/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/local/.bin/git/git-default-branch b/local/.bin/git/git-default-branch deleted file mode 100755 index 90e225f..0000000 --- a/local/.bin/git/git-default-branch +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -set -eu - -git symbolic-ref refs/remotes/origin/HEAD | sed 's/.*\///' diff --git a/local/.bin/git/git-file-size b/local/.bin/git/git-file-size deleted file mode 100755 index 0e7d00d..0000000 --- a/local/.bin/git/git-file-size +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh -set -eu -set -o pipefail - -git ls-files -z | xargs -0 du -b | sum diff --git a/local/.bin/git/git-pr b/local/.bin/git/git-pr deleted file mode 100755 index 61346bc..0000000 --- a/local/.bin/git/git-pr +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/sh - -pr_num="$1" -upstream="${2-origin}" -git fetch "$upstream" "pull/${pr_num}/head:pull-${pr_num}" diff --git a/local/.bin/git/git-record b/local/.bin/git/git-record deleted file mode 100755 index eaa36c9..0000000 --- a/local/.bin/git/git-record +++ /dev/null @@ -1,13 +0,0 @@ -#!/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/local/.bin/git/git-root b/local/.bin/git/git-root deleted file mode 100755 index 96fb395..0000000 --- a/local/.bin/git/git-root +++ /dev/null @@ -1,9 +0,0 @@ -#!/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