@matheusbsbs / matheus-bagliano / commits / d691265880
Fork 0

Even more aggressive commit trimming.

Now we cut out a commit if any of its parents had the same tree; just use that parent in its place. This makes the history look nice, but I don't think it's quite right...

Avery Pennarun committed Apr 24, 2009 at 22:05 UTC d691265880abea4428783beb858683be56f3b340
2 files changed +25 -11
git-subtree.sh
+24 -10
@@ -202,6 +202,29 @@ tree_changed()
202 fi
203 }
204
205 +copy_or_skip()
206 +{
207 + rev="$1"
208 + tree="$2"
209 + newparents="$3"
210 + assert [ -n "$tree" ]
211 +
212 + p=""
213 + for parent in $newparents; do
214 + ptree=$(toptree_for_commit $parent) || exit $?
215 + if [ "$ptree" = "$tree" ]; then
216 + # any identical parent means this commit is unnecessary
217 + echo $parent
218 + return 0
219 + elif [ -n "$ptree" ]; then
220 + # an existing, non-identical parent is important
221 + p="$p -p $parent"
222 + fi
223 + done
224 +
225 + copy_commit $rev $tree "$p" || exit $?
226 +}
227 +
228 cmd_split()
229 {
230 debug "Splitting $dir..."
@@ -238,16 +261,7 @@ cmd_split()
261 debug " tree is: $tree"
262 [ -z $tree ] && continue
263
241 - p=""
242 - for parent in $newparents; do
243 - p="$p -p $parent"
244 - done
245 -
246 - if tree_changed $tree $newparents; then
247 - newrev=$(copy_commit $rev $tree "$p") || exit $?
248 - else
249 - newrev="$newparents"
250 - fi
264 + newrev=$(copy_or_skip "$rev" "$tree" "$newparents") || exit $?
265 debug " newrev is: $newrev"
266 cache_set $rev $newrev
267 cache_set latest_new $newrev
test.sh
+1 -1
@@ -93,4 +93,4 @@ git branch subproj-merge-split3
93 cd ../mainline
94 git fetch ../subproj subproj-merge-split3
95 git branch subproj-merge-split3 FETCH_HEAD
96 -git merge subproj-merge-split3
96 +git merge -s subtree subproj-merge-split3