@@ -610,23 +610,33 @@ void git_treebuilder_free(git_treebuilder *bld)
610610 git__free (bld );
611611}
612612
613- static int tree_frompath (git_tree * * parent_out , git_tree * root , const char * treeentry_path , int offset )
613+ static int tree_frompath (
614+ git_tree * * parent_out ,
615+ git_tree * root ,
616+ const char * treeentry_path ,
617+ int offset )
614618{
615619 char * slash_pos = NULL ;
616620 const git_tree_entry * entry ;
617621 int error = GIT_SUCCESS ;
618622 git_tree * subtree ;
619623
620624 if (!* (treeentry_path + offset ))
621- return git__rethrow (GIT_EINVALIDPATH , "Invalid relative path to a tree entry '%s'." , treeentry_path );
625+ return git__rethrow (GIT_EINVALIDPATH ,
626+ "Invalid relative path to a tree entry '%s'." , treeentry_path );
622627
623628 slash_pos = (char * )strchr (treeentry_path + offset , '/' );
624629
625630 if (slash_pos == NULL )
626- return git_tree_lookup (parent_out , root -> object .repo , git_object_id ((const git_object * )root ));
631+ return git_tree_lookup (
632+ parent_out ,
633+ root -> object .repo ,
634+ git_object_id ((const git_object * )root )
635+ );
627636
628637 if (slash_pos == treeentry_path + offset )
629- return git__rethrow (GIT_EINVALIDPATH , "Invalid relative path to a tree entry '%s'." , treeentry_path );
638+ return git__rethrow (GIT_EINVALIDPATH ,
639+ "Invalid relative path to a tree entry '%s'." , treeentry_path );
630640
631641 * slash_pos = '\0' ;
632642
@@ -636,28 +646,44 @@ static int tree_frompath(git_tree **parent_out, git_tree *root, const char *tree
636646 * slash_pos = '/' ;
637647
638648 if (entry == NULL )
639- return git__rethrow (GIT_ENOTFOUND , "No tree entry can be found from the given tree and relative path '%s'." , treeentry_path );
649+ return git__rethrow (GIT_ENOTFOUND ,
650+ "No tree entry can be found from "
651+ "the given tree and relative path '%s'." , treeentry_path );
640652
641- if ((error = git_tree_lookup (& subtree , root -> object .repo , & entry -> oid )) < GIT_SUCCESS )
653+
654+ error = git_tree_lookup (& subtree , root -> object .repo , & entry -> oid );
655+ if (error < GIT_SUCCESS )
642656 return error ;
643657
644- error = tree_frompath (parent_out , subtree , treeentry_path , slash_pos - treeentry_path + 1 );
658+ error = tree_frompath (
659+ parent_out ,
660+ subtree ,
661+ treeentry_path ,
662+ slash_pos - treeentry_path + 1
663+ );
645664
646665 git_tree_close (subtree );
647666 return error ;
648667}
649668
650- int git_tree_frompath (git_tree * * parent_out , git_tree * root , const char * treeentry_path )
669+ int git_tree_get_subtree (
670+ git_tree * * subtree ,
671+ git_tree * root ,
672+ const char * subtree_path )
651673{
652674 char buffer [GIT_PATH_MAX ];
653675
654- assert (root && treeentry_path );
676+ assert (subtree && root && subtree_path );
655677
656- strcpy (buffer , treeentry_path );
657- return tree_frompath (parent_out , root , buffer , 0 );
678+ strncpy (buffer , subtree_path , GIT_PATH_MAX );
679+ return tree_frompath (subtree , root , buffer , 0 );
658680}
659681
660- static int tree_walk_post (git_tree * tree , git_treewalk_cb callback , char * root , size_t root_len )
682+ static int tree_walk_post (
683+ git_tree * tree ,
684+ git_treewalk_cb callback ,
685+ char * root ,
686+ size_t root_len )
661687{
662688 int error ;
663689 unsigned int i ;
@@ -673,13 +699,15 @@ static int tree_walk_post(git_tree *tree, git_treewalk_cb callback, char *root,
673699 if (ENTRY_IS_TREE (entry )) {
674700 git_tree * subtree ;
675701
676- if ((error = git_tree_lookup (& subtree , tree -> object .repo , & entry -> oid )) < 0 )
702+ if ((error = git_tree_lookup (
703+ & subtree , tree -> object .repo , & entry -> oid )) < 0 )
677704 return error ;
678705
679706 strcpy (root + root_len , entry -> filename );
680707 root [root_len + entry -> filename_len ] = '/' ;
681708
682- tree_walk_post (subtree , callback , root , root_len + entry -> filename_len + 1 );
709+ tree_walk_post (subtree ,
710+ callback , root , root_len + entry -> filename_len + 1 );
683711
684712 git_tree_close (subtree );
685713 }
0 commit comments