summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohsuke Kawaguchi <kk@kohsuke.org>2011-09-08 09:25:16 -0700
committerKohsuke Kawaguchi <kk@kohsuke.org>2011-09-08 09:25:16 -0700
commit5256259f8475a8cd28b9d0ad65e348c7a2261010 (patch)
tree224bda162161ba79312200d348f5a72f19d7bb92
initial version
-rwxr-xr-xrecord-original-commit.sh4
-rwxr-xr-xremove-pointless-commit.rb52
2 files changed, 56 insertions, 0 deletions
diff --git a/record-original-commit.sh b/record-original-commit.sh
new file mode 100755
index 0000000..cbb96e1
--- /dev/null
+++ b/record-original-commit.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+# commit message filter used with git-filter-branch to record the original commit ID
+cat
+echo "\nOriginally-Committed-As: $GIT_COMMIT"
diff --git a/remove-pointless-commit.rb b/remove-pointless-commit.rb
new file mode 100755
index 0000000..ba33522
--- /dev/null
+++ b/remove-pointless-commit.rb
@@ -0,0 +1,52 @@
+#!/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 "<tree> [ -p <parent> ]*" and is the same as git commit-tree
+
+# system "echo executing #{ARGV.join(' ')} >> /tmp/log"
+
+# extract parents
+parents=[]
+i=2
+while i<ARGV.size do
+ parents << ARGV[i]
+ i+=2
+end
+parents=parents.uniq
+
+tree=ARGV[0]
+
+# is the commit 'c' already an ancestor of any of the commits given in 'commits'?
+def subsumed_by(c,commits)
+ commits.find do |c2|
+ c!=c2 && c==`git merge-base #{c} #{c2}`.chomp()
+ end
+end
+
+# only keep commits that are not subsumed by others
+# subsumed parents are pointless merge
+parents = parents.select do |p|
+ !subsumed_by(p,parents)
+end
+
+# does any parent has a different tree?
+non_empty_commit = parents.find do |p|
+ tree != `git rev-parse #{p}^{tree}`.chomp()
+end
+
+if non_empty_commit!=nil || parents.size==0 then
+ # if a commit has non-empty diff, make a commit
+ args = []
+ args << tree
+ parents.each{ |c| args << "-p"; args << c; }
+ # system "echo git commit-tree #{args.join(' ')} >> /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
+
+