git: skip recursing into manifest subtrees that are the same
If during manifest comparison we are presented with identical tree objects,
then we are guaranteed that:
1. the contents of these tree objects are the same
2. the contents of any of their children are the same
This speeds up 'hg diff -c <hash>' considerably since unchanged subtrees are
are skipped. For example, a commit that modified the README in the linux
kernel repo (~84k tracked files) now takes 1.1s instead of 15.7s.
--- a/hgext/git/manifest.py Tue Jan 07 17:52:52 2025 -0500
+++ b/hgext/git/manifest.py Sat Jan 04 11:13:15 2025 -0500
@@ -170,6 +170,11 @@
def _iterativediff(t1, t2, subdir):
"""compares two trees and appends new tree nodes to examine to
the stack"""
+ if t1 == t2:
+ # If the trees are the same (git) object, then there are no
+ # differences in this tree or any of its children.
+ return
+
if t1 is None:
t1 = {}
if t2 is None: