diff options
Diffstat (limited to 'parent-prune-empty-merge')
-rwxr-xr-x | parent-prune-empty-merge | 20 |
1 files changed, 20 insertions, 0 deletions
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(' ') |