private void UpdateSingleFile(string file) { TreeEntry treeEntry = null; var commit = Repository.Head.CurrentCommit; _tree = commit != null ? commit.Tree : null; if (_tree != null) treeEntry = _tree.FindBlobMember (file); _index = Repository.Index.GitIndex; _index.RereadIfNecessary(); GitIndex.Entry indexEntry = _index.GetEntry (file); TreeEntry wdirEntry = null; FileInfo fileInfo = new FileInfo (Path.Combine (Repository.WorkingDirectory, file.Replace ('/', Path.DirectorySeparatorChar))); if (fileInfo.Exists && !IgnoreHandler.IsIgnored(file)) { var tree = new Core.Tree(Repository._internal_repo); wdirEntry = tree.AddFile (file); } OnVisitEntry (treeEntry, wdirEntry, indexEntry, fileInfo); }
private void UpdateDirectoryNotRecursive(string path) { _index = Repository.Index.GitIndex; // Tree that will hold the working dir file entries var wtree = new Core.Tree(Repository._internal_repo); // Get a list of a leaves in the path Tree commitTree = null; var commit = Repository.Head.CurrentCommit; commitTree = commit != null ? commit.Tree : null; if (commitTree != null) commitTree = commitTree[path] as Tree; Dictionary<string,Leaf> commitEntries; if (commitTree != null) commitEntries = commitTree.Leaves.ToDictionary (l => l.Path); else commitEntries = new Dictionary<string, Leaf> (); HashSet<string> visited = new HashSet<string> (); // Compare commited files and working tree files DirectoryInfo dir = new DirectoryInfo (Repository.FromGitPath (path)); if (dir.Exists) { foreach (FileInfo fileInfo in dir.GetFiles ()) { string file = path + "/" + fileInfo.Name; Leaf lf; if (commitEntries.TryGetValue (file, out lf)) { // Remove from the collection. At the end of the loop, entries still remaining in the // collection will be processed as not having a corresponding working dir file commitEntries.Remove (file); } TreeEntry wdirEntry = null; if (!IgnoreHandler.IsIgnored (file) && fileInfo.Exists) wdirEntry = wtree.AddFile (file); GitIndex.Entry indexEntry = _index.GetEntry (file); OnVisitEntry (lf != null ? lf.InternalEntry : null, wdirEntry, indexEntry, fileInfo); visited.Add (file); } } // Now visit entries for which a working dir file was not found foreach (var lf in commitEntries) { string file = lf.Key; FileInfo fileInfo = new FileInfo (Repository.FromGitPath (file)); GitIndex.Entry indexEntry = _index.GetEntry (file); OnVisitEntry (lf.Value.InternalEntry, null, indexEntry, fileInfo); visited.Add (file); } // Finally, visit remaining index entries which are not in the working dir nor in the commit foreach (var ie in _index.Members) { string file = ie.Name; // Exclude entries in subdirectories of _root_path int i = file.LastIndexOf ('/'); string fdir = i != -1 ? file.Substring (0, i) : string.Empty; if (fdir == _root_path && !visited.Contains (file)) OnVisitEntry (null, null, ie, new FileInfo (Repository.FromGitPath (file))); } }