blob: 55219774addfd1891ed5413236e92be6945b8858 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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'}
# Only 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(' ')
|