public ViewData() { preferredDowntWay = new Dictionary <string, string>(); preferredUpWay = new Dictionary <string, string>(); ShaDictionary = new Dictionary <string, SnapshotVM>(); IdDictionary = new Dictionary <int, SnapshotVM>(); SeekStatus = new CommitsAnalyzingStatus() { ItemsPerPage = 100 }; }
public void GetCommitsHistory(CommitsAnalyzingStatus status) { if (snapshots == null) { snapshots = new List <Snapshot>(); } visibleSnapshots = new List <Snapshot>(); var commitsRelatedToFile = snapshots.Count(e => e.IsCommitRelatedToFile); using (var repo = new Repository(repositoryPath)) { // TODO: History in different branches status.ItemsTotal = repo.Commits.Count(); // Full seek done if (repo.Commits.Count() <= status.ItemsProcessed) { status.IsSeekCompleted = true; return; } var treeFile = filePath; var processed = 0; foreach (var commit in repo.Commits.Skip(status.ItemsProcessed)) { if (processed >= status.ItemsPerPage && snapshots.Count > 0) { break; } status.ItemsProcessed++; processed++; // Observable commit var snapshot = new Snapshot(commit.Sha) { FilePath = treeFile, Commit = new Model.Commit(commit), IsCommitRelatedToFile = IsFileWasUpdated(commit, treeFile) }; // Skip all commits before first changes if (snapshot.IsCommitRelatedToFile || snapshots.Any()) { snapshots.Add(snapshot); } // TODO: Not working for tree. Should revrite code for files renaming /* * // Check is file was renamed/moved * treeFile = GetPreviousCommitFileName(snapshot, repo.Diff, commit, treeFile); * * // First file mention * if (snapshot.FilePathState == FilePathState.Unknown || snapshot.FilePathState == FilePathState.Added) { * break; * }*/ } // Do nothing in case if no changes found if (!snapshots.Any(e => e.IsCommitRelatedToFile)) { return; } // Do nothing in case if no new changes found if (commitsRelatedToFile == snapshots.Count(e => e.IsCommitRelatedToFile)) { return; } InitializeNewSnapshotsRelations(); RemoveNotExistingParentsAndChilds(snapshots); LinkParentsWithChilds(); UnlinkCommitsWithoutChanges(); FindAllCommitAncestors(); RemoveNotValuableLinks(); GetSnapshotsWithChanges(); if (!visibleSnapshots.Any()) { OnSnapshotsHistoryUpdated.Invoke(MapSnapshotVM(visibleSnapshots)); return; } FindRelatedLines(); AdvancedBranchesArchivation(); FindRelatedLines(); AdvancedBranchesArchivation(); ReadFilesContent(); CountLines(); FindLifeTimeForEachLine(); // TODO: Related only to rendering. Move to other place var lineGroup = visibleSnapshots.GroupBy(e => e.BranchLineId); Parallel.ForEach(lineGroup, (commitsGroup) => { // Find line start/end commitsGroup.First().IsFirstInLine = true; commitsGroup.Last().IsLastInLine = true; }); //SimpleBranchesArchivation(); } OnSnapshotsHistoryUpdated.Invoke(MapSnapshotVM(visibleSnapshots)); }