Commits

evhan committed 588502a

try to detect repo from tree-entry in tree-entry->object

This allows a tree-entry to be passed to tree-entry->object without an
accompanying repository argument.

Comments (0)

Files changed (2)

            (else
             (git-error 'tree-ref "Invalid key" key))))))
 
-(define (tree-entry->object repo entry)
-  (pointer->object
-   repo
-   (git-tree-entry-to-object
-    (repository->pointer repo)
-    (tree-entry->pointer entry))))
+(define tree-entry->object
+  (case-lambda
+    ((entry)
+     (let ((owner (tree-entry-owner entry)))
+       (if (tree? owner)
+           (tree-entry->object (tree-repository owner) entry)
+           (git-error 'tree-entry->object "Can't determine owning repository" entry))))
+    ((repo entry)
+     (pointer->object
+      repo
+      (git-tree-entry-to-object
+       (repository->pointer repo)
+       (tree-entry->pointer entry))))))
 
 (define (create-tree repo #!optional (index (index-open repo)))
   (pointer->tree
            (test-assert "tree-builder-ref" (tree-builder-ref tb file))
            (test "tree-entry-name" file (tree-entry-name e))
            (test-assert "tree-entry-id" (oid? (tree-entry-id e)))
-           (test-assert "tree-entry->object" (blob? (tree-entry->object repo e)))
+           (test-assert "tree-entry->object (tree-builder, repo)" (blob? (tree-entry->object repo e)))
+           (test-error "tree-entry->object (tree-builder, no repo)" (tree-entry->object e))
            (test "tree-entry-type" 'blob (tree-entry-type e))))
        (drop files 1)
        (drop content 1))
            (test-assert "tree-entry?" (tree-entry? e))
            (test-assert "tree-entry-id" (oid? (tree-entry-id e)))
            (test "tree-entry-name" file (tree-entry-name e))
-           (test-assert "tree-entry->object" (blob? (tree-entry->object repo e)))
+           (test-assert "tree-entry->object (repo)" (blob? (tree-entry->object repo e)))
+           (test-assert "tree-entry->object (no repo)" (blob? (tree-entry->object e)))
            (test "tree-entry-type" 'blob (tree-entry-type e))))
        files
        content))))