From 44cacd6b1cee00c3326d28bffdf18df0356b7204 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 14 Jan 2017 20:34:23 -0500 Subject: Make them my own. --- commit-remove-pointless-commit | 52 ------------------------------------------ msg-record-original-commit | 3 ++- parent-prune-empty-first | 21 +++++++++++++++++ parent-prune-empty-merge | 20 ++++++++++++++++ 4 files changed, 43 insertions(+), 53 deletions(-) delete mode 100755 commit-remove-pointless-commit create mode 100755 parent-prune-empty-first create mode 100755 parent-prune-empty-merge diff --git a/commit-remove-pointless-commit b/commit-remove-pointless-commit deleted file mode 100755 index ba33522..0000000 --- a/commit-remove-pointless-commit +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/ruby -# Executed like the following to trim off pointless commits (including merge commits) -# that doesn't change the tree -# git filter-branch -f --commit-filter '~/ws/jenkins/split2/helper.rb "$@"' HEAD -# -# parameters are " [ -p ]*" and is the same as git commit-tree - -# system "echo executing #{ARGV.join(' ')} >> /tmp/log" - -# extract parents -parents=[] -i=2 -while i> /tmp/log" - exec "git commit-tree #{args.join(' ')}" -else - # system "echo skipping >> /tmp/log" - # otherwise don't create this as a commit - puts parents -end - - diff --git a/msg-record-original-commit b/msg-record-original-commit index cbb96e1..f5a5d00 100755 --- a/msg-record-original-commit +++ b/msg-record-original-commit @@ -1,4 +1,5 @@ #!/bin/sh # commit message filter used with git-filter-branch to record the original commit ID cat -echo "\nOriginally-Committed-As: $GIT_COMMIT" +echo +echo "Originally-Committed-As: $GIT_COMMIT" diff --git a/parent-prune-empty-first b/parent-prune-empty-first new file mode 100755 index 0000000..c9d73df --- /dev/null +++ b/parent-prune-empty-first @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +# Usage: git filter-branch -f --parent-filter ~/git-filters/parent-prune-empty-first HEAD + +has_empty_tree() { + [[ "$(git rev-parse "${1}^{tree}")" == 4b825dc642cb6eb9a060e54bf8d69288fbee4904 ]] +} + +has_parents() { + git rev-parse "${1}^" &>/dev/null +} + +for parent in $(cat); do + if [[ "$parent" == '-p' ]]; then + continue + fi + if has_empty_tree "$parent" && ! has_parents "$parent"; then + continue + fi + printf ' -p %s ' "$parent" +done +echo diff --git a/parent-prune-empty-merge b/parent-prune-empty-merge new file mode 100755 index 0000000..10e9fb8 --- /dev/null +++ b/parent-prune-empty-merge @@ -0,0 +1,20 @@ +#!/usr/bin/env ruby +# Usage: git filter-branch -f --parent-filter ~/git-filters/parent-prune-empty-merge HEAD + +# Function to determine if commit 'c' already an ancestor of any of +# the commits given in 'commits' +def subsumed_by(c,commits) + commits.any? do |c2| + c!=c2 && c==`git merge-base #{c} #{c2}`.chomp() + end +end + +# Get the current list of parents +parents = $stdin.read.split.select{|a|a!='-p'} + +# Pnly keep parents that are not subsumed by other parents. +parents = parents.select do |p| + not subsumed_by(p,parents) +end + +puts parents.uniq.map{|p|"-p #{p}"}.join(' ') -- cgit v1.2.3