Commit Diff


commit - c683aeaacfbbc2bac3b2e42f576a38d94dca218a
commit + d90389e678229d944617785754abf30f2f31ce80
blob - 8ae4a5d93145b969b9664e6f0476392c7f159c0d
blob + f26d6c96a73198205002c075fbced564d61970bd
--- swh/loader/git/loader.py
+++ swh/loader/git/loader.py
@@ -724,6 +724,8 @@ class GitLoader(BaseGitLoader):
         commits = {}
         commit_edges = []
         missing_objects = []
+        new_trees = []
+        new_blobs = []
         for ref_name, ref_object_hex in self.remote_refs.items():
             if utils.ignore_branch_name(ref_name):
                 continue
@@ -754,10 +756,18 @@ class GitLoader(BaseGitLoader):
                 # Object is missing from pack file.
                 continue
 
-            # TODO: Allow tags pointing at blobs or trees?
+            # Handle refs or tags pointing at blobs or trees...
+            if obj.type_name == b"blob":
+                new_blobs.append(hashutil.bytehex_to_hash(ref_object_hex))
+                continue
+            if obj.type_name == b"tree":
+                new_trees.append(hashutil.bytehex_to_hash(ref_object_hex))
+                continue
+
+            # From here on out, we handle commits only
             if obj.type_name != b"commit":
                 logger.debug(
-                    f"  tag {ref_name} resolves to a {obj.type_name}, not a commit"
+                    f"  {ref_name} resolves to a {obj.type_name}, not a commit"
                 )
                 continue
 
@@ -805,6 +815,14 @@ class GitLoader(BaseGitLoader):
             attributes = dict()
             attributes["object_type"] = [object_type for x in new_vertices]
             self._object_graph.add_vertices(new_vertices, attributes=attributes)
+
+        # Add vertices for any directly referenced trees and blobs.
+        if len(new_trees) > 0:
+            add_vertices(new_trees, GitObjectType.TREE)
+            new_trees = []
+        if len(new_blobs) > 0:
+            add_vertices(new_blobs, GitObjectType.BLOB)
+            new_blobs = []
 
         # Add tags, commits and root trees to the graph
         add_vertices(list(tags.keys()), GitObjectType.TAG)
@@ -815,8 +833,6 @@ class GitLoader(BaseGitLoader):
         self._object_graph.add_edges(commit_edges)
 
         # Populate the graph with trees and blobs
-        new_trees = []
-        new_blobs = []
         new_edges = []
         traversed_trees = set()
         seen_blobs = set()