Beispiel #1
0
 /// <summary>
 /// Create a generator and advance it to the submodule entry at the given
 /// path
 /// </summary>
 /// <param name="repository"></param>
 /// <param name="treeId">
 /// the root of a tree containing both a submodule at the given path
 /// and .gitmodules at the root.
 /// </param>
 /// <param name="path"></param>
 /// <returns>generator at given path, null if no submodule at given path</returns>
 /// <exception cref="System.IO.IOException">System.IO.IOException</exception>
 public static NGit.Submodule.SubmoduleWalk ForPath(Repository repository, AnyObjectId
                                                    treeId, string path)
 {
     NGit.Submodule.SubmoduleWalk generator = new NGit.Submodule.SubmoduleWalk(repository
                                                                               );
     try
     {
         generator.SetTree(treeId);
         PathFilter filter = PathFilter.Create(path);
         generator.SetFilter(filter);
         generator.SetRootTree(treeId);
         while (generator.Next())
         {
             if (filter.IsDone(generator.walk))
             {
                 return(generator);
             }
         }
     }
     catch (IOException e)
     {
         generator.Release();
         throw;
     }
     generator.Release();
     return(null);
 }
Beispiel #2
0
        /// <summary>Open a tree walk and filter to exactly one path.</summary>
        /// <remarks>
        /// Open a tree walk and filter to exactly one path.
        /// <p>
        /// The returned tree walk is already positioned on the requested path, so
        /// the caller should not need to invoke
        /// <see cref="Next()">Next()</see>
        /// unless they are
        /// looking for a possible directory/file name conflict.
        /// </remarks>
        /// <param name="reader">the reader the walker will obtain tree data from.</param>
        /// <param name="path">single path to advance the tree walk instance into.</param>
        /// <param name="trees">one or more trees to walk through, all with the same root.</param>
        /// <returns>
        /// a new tree walk configured for exactly this one path; null if no
        /// path was found in any of the trees.
        /// </returns>
        /// <exception cref="System.IO.IOException">reading a pack file or loose object failed.
        ///     </exception>
        /// <exception cref="NGit.Errors.CorruptObjectException">
        /// an tree object could not be read as its data stream did not
        /// appear to be a tree, or could not be inflated.
        /// </exception>
        /// <exception cref="NGit.Errors.IncorrectObjectTypeException">an object we expected to be a tree was not a tree.
        ///     </exception>
        /// <exception cref="NGit.Errors.MissingObjectException">a tree object was not found.
        ///     </exception>
        public static NGit.Treewalk.TreeWalk ForPath(NGit.ObjectReader reader, string path
                                                     , params AnyObjectId[] trees)
        {
            NGit.Treewalk.TreeWalk tw = new NGit.Treewalk.TreeWalk(reader);
            PathFilter             f  = PathFilter.Create(path);

            tw.Filter = f;
            tw.Reset(trees);
            tw.Recursive = false;
            while (tw.Next())
            {
                if (f.IsDone(tw))
                {
                    return(tw);
                }
                else
                {
                    if (tw.IsSubtree)
                    {
                        tw.EnterSubtree();
                    }
                }
            }
            return(null);
        }
Beispiel #3
0
 /// <summary>
 /// Load the config for this walk from
 /// <code>.gitmodules</code>
 /// .
 /// <p>
 /// Uses the root tree if
 /// <see cref="SetRootTree(NGit.Treewalk.AbstractTreeIterator)">SetRootTree(NGit.Treewalk.AbstractTreeIterator)
 ///     </see>
 /// was
 /// previously called, otherwise uses the working tree.
 /// <p>
 /// If no submodule config is found, loads an empty config.
 /// </summary>
 /// <returns>this generator</returns>
 /// <exception cref="System.IO.IOException">if an error occurred, or if the repository is bare
 ///     </exception>
 /// <exception cref="NGit.Errors.ConfigInvalidException">NGit.Errors.ConfigInvalidException
 ///     </exception>
 public virtual NGit.Submodule.SubmoduleWalk LoadModulesConfig()
 {
     if (rootTree == null)
     {
         FilePath modulesFile = new FilePath(repository.WorkTree, Constants.DOT_GIT_MODULES
                                             );
         FileBasedConfig config = new FileBasedConfig(modulesFile, repository.FileSystem);
         config.Load();
         modulesConfig = config;
     }
     else
     {
         TreeWalk configWalk = new TreeWalk(repository);
         try
         {
             configWalk.AddTree(rootTree);
             // The root tree may be part of the submodule walk, so we need to revert
             // it after this walk.
             int idx;
             for (idx = 0; !rootTree.First; idx++)
             {
                 rootTree.Back(1);
             }
             try
             {
                 configWalk.Recursive = false;
                 PathFilter filter = PathFilter.Create(Constants.DOT_GIT_MODULES);
                 configWalk.Filter = filter;
                 while (configWalk.Next())
                 {
                     if (filter.IsDone(configWalk))
                     {
                         modulesConfig = new BlobBasedConfig(null, repository, configWalk.GetObjectId(0));
                         return(this);
                     }
                 }
                 modulesConfig = new Config();
             }
             finally
             {
                 if (idx > 0)
                 {
                     rootTree.Next(idx);
                 }
             }
         }
         finally
         {
             configWalk.Release();
         }
     }
     return(this);
 }
Beispiel #4
0
 /// <exception cref="System.IO.IOException"></exception>
 private bool Find(RevCommit commit, PathFilter path)
 {
     treeWalk.Filter = path;
     treeWalk.Reset(commit.Tree);
     while (treeWalk.Next())
     {
         if (path.IsDone(treeWalk))
         {
             if (treeWalk.GetFileMode(0).GetObjectType() != Constants.OBJ_BLOB)
             {
                 return(false);
             }
             treeWalk.GetObjectId(idBuf, 0);
             return(true);
         }
         if (treeWalk.IsSubtree)
         {
             treeWalk.EnterSubtree();
         }
     }
     return(false);
 }