public List <SCFile> SearchForCheckIn(SCFolder fld, Wildcard user, Wildcard comment, Wildcard fileNameFilter, SearchCondition search, bool bSearchInHistory, CancelCallbackNotify callback) { QueryHistoryParameters qhp = new QueryHistoryParameters(fld.FolderPath, RecursionType.None); List <SCFile> lstFoundFiles = new List <SCFile>(); IEnumerable <Changeset> changesets = null; int i = 0; foreach (Changeset chgset in changesets) { i++; if (user.IsMatch(chgset.Committer)) { if (callback.DoCallback((double)i / changesets.Count(), chgset.ChangesetId.ToString(), ref lstFoundFiles)) { return(lstFoundFiles); } if (comment.IsMatch(chgset.Comment)) { SCFile file = new SCFile(); file.ChangesetId = chgset.ChangesetId; file.Comment = chgset.Comment.ToString(); file.FilePath = chgset.Committer; SCFile.AddFileToList(file, lstFoundFiles); } } } return(lstFoundFiles); }
public static Changeset QueryLatestChangeset(this VersionControlServer server, string serverPath, bool includeChanges = true) { var p = new QueryHistoryParameters(serverPath, RecursionType.Full); p.MaxResults = 1; p.IncludeChanges = includeChanges; p.SlotMode = false; p.IncludeDownloadInfo = false; p.SortAscending = false; return(server.QueryHistory(p).First()); }
public static IEnumerable <Changeset> QueryHistoryEx(this VersionControlServer server, string serverPath, int sinceThisChangeset, bool includeChanges = true) { var p = new QueryHistoryParameters(serverPath, RecursionType.Full); p.VersionStart = new ChangesetVersionSpec(sinceThisChangeset); p.IncludeChanges = includeChanges; p.SlotMode = false; p.IncludeDownloadInfo = false; p.SortAscending = false; return(server.QueryHistory(p)); }
private Changeset GetLatestChangeset(bool includeChanges = true) { var queryParams = new QueryHistoryParameters(m_serverPath, RecursionType.Full) { MaxResults = 1, IncludeChanges = includeChanges, IncludeDownloadInfo = false, SortAscending = false }; return(m_vcs.QueryHistory(queryParams).FirstOrDefault()); }
public static IEnumerable <Changeset> ReadTFSChangesets(VersionControlServer versionControlServer, ChangesetQuery changesetQuery, string branchMapping, ILogger logger) { if (versionControlServer == null) { return(new List <Changeset>(0)); } try { logger.Information("Querying Changesets from TFS."); if (!changesetQuery.SelectedChangesetAuthors.Any()) { QueryHistoryParameters query = new QueryHistoryParameters(branchMapping, RecursionType.Full) { VersionStart = new DateVersionSpec(changesetQuery.LowDate.Value), VersionEnd = new DateVersionSpec(changesetQuery.HighDate.Value) }; return(versionControlServer .QueryHistory(query) .Select(c => versionControlServer.GetChangeset(c.ChangesetId))); } else { List <Changeset> changesets = new List <Changeset>(); foreach (string author in changesetQuery.SelectedChangesetAuthors) { QueryHistoryParameters query = new QueryHistoryParameters(branchMapping, RecursionType.Full) { VersionStart = new DateVersionSpec(changesetQuery.LowDate.Value), VersionEnd = new DateVersionSpec(changesetQuery.HighDate.Value), Author = author }; changesets.AddRange(versionControlServer .QueryHistory(query) .Select(c => versionControlServer.GetChangeset(c.ChangesetId))); } return(changesets.OrderByDescending(c => c.CreationDate)); } } catch (Exception e) { logger.Error(e.Message); return(null); } }
private void GetChangeset(TfsDashboardSummary summary) { var watch = Stopwatch.StartNew(); _projectCollection.EnsureAuthenticated(); var versionControl = _projectCollection.GetService <VersionControlServer>(); var queryParams = new QueryHistoryParameters(_settings.VersionControlPath, RecursionType.Full) { Item = _settings.VersionControlPath, IncludeDownloadInfo = false, IncludeChanges = false, VersionStart = GetDateVSpec(DateTime.Today.AddDays(-75)) }; var query = versionControl.QueryHistory(queryParams); var results = query.ToList(); summary.LastCheckins = results.Take(15).Select(x => new TfsCheckinSummary { Comment = x.Comment, Committer = x.CommitterDisplayName, Username = x.Committer, CreationDate = x.CreationDate, TimeElapsed = x.CreationDate }).ToList(); var allDays = Enumerable.Range(0, 75).Select(x => new TfsCheckinStatistic { Day = DateTime.Today.AddDays(-x), Count = 0 }); var checkins = results.GroupBy(x => x.CreationDate.Date).Select(x => new TfsCheckinStatistic { Day = x.Key, Count = x.Count() }).ToList(); checkins = checkins.Union(allDays.Where(x => checkins.All(y => y.Day != x.Day))).ToList(); summary.CheckinStatistic = checkins.OrderBy(x => x.Day).ToList(); summary.CheckinsToday = results.Count(x => x.CreationDate.Date == DateTime.Today); Trace.WriteLine("GetChangeset: " + watch.Elapsed); }
private IEnumerable <Changeset> FindLatestChanges(int latestChangesetId) { // Before query a new changesets we need to check the new latest changeset to avoid exception "Changeset does not exist" if (GetLatestChangesetId() <= latestChangesetId) { return(null); } var queryParams = new QueryHistoryParameters(m_serverPath, RecursionType.Full) { MaxResults = 10, IncludeChanges = true, IncludeDownloadInfo = false, SortAscending = true, VersionStart = new ChangesetVersionSpec(latestChangesetId + 1), VersionEnd = VersionSpec.Latest }; return(m_vcs.QueryHistory(queryParams)); }
public IEnumerable <Changeset> GetMyChangesets() { try { VersionControlServer vcs = GetTFS().GetService <VersionControlServer>(); QueryHistoryParameters parameters = new QueryHistoryParameters("$/", RecursionType.Full); parameters.Author = vcs.AuthorizedUser; parameters.MaxResults = 5; parameters.IncludeDownloadInfo = false; parameters.IncludeChanges = false; Helpers.DebugInfo("Trying to get changesets for user: "******"GetMyChangesets exception: " + ex.Message); tfs = null; throw; } }
/// <summary> /// Generates a version part which matches the current change set of the working copy being patched /// </summary> /// <param name="currentPartValue">The current value of the version part - this value is not used by this /// generator</param> /// <param name="ctx">The version part generation context</param> /// <returns>The TFS change set number for the current working copy being patched</returns> public int Generate(int currentPartValue, VersionPartPatchingContext ctx) { // The workspace info for the provided path var wsInfo = Workstation.Current.GetLocalWorkspaceInfo(ctx.SolutionRootPath); if(wsInfo == null) throw new InvalidOperationException(string.Format("The target solution and project must be a TFS working copy - {0}", ctx)); // Get the TeamProjectCollection and VersionControl server associated with the // WorkspaceInfo var tpc = new TfsTeamProjectCollection(wsInfo.ServerUri); var vcServer = tpc.GetService<VersionControlServer>(); // Now get the actual Workspace OM object var ws = vcServer.GetWorkspace(wsInfo); // We are interested in the current version of the workspace var versionSpec = new WorkspaceVersionSpec(ws); var historyParams = new QueryHistoryParameters(ctx.SolutionRootPath, RecursionType.Full) { ItemVersion = versionSpec, VersionEnd = versionSpec, MaxResults = 1 }; // return changeset var changeset = vcServer.QueryHistory(historyParams).FirstOrDefault(); if (changeset != null) return changeset.ChangesetId; // no changeset found. throw new InvalidOperationException(string.Format("Could not find changeset values for solution path \"{0}\"", ctx.SolutionRootPath)); }
/// <summary> /// Find the SHA1 which was last sync'd to this workspace. /// </summary> private static ObjectId FindLastMirroredSha(VersionControlServer vcServer, string path, int maxResults = 100) { var itemSpec = new ItemSpec(path, RecursionType.Full); var parameters = new QueryHistoryParameters(itemSpec); try { foreach (var changeset in vcServer.QueryHistory(itemSpec, maxResults)) { var comment = changeset.Comment; var match = s_checkinShaRegex.Match(comment); if (match.Success) { return(new ObjectId(match.Groups[1].Value)); } } return(null); } catch { return(null); } }
public void QueryHistory() { QueryHistoryParameters queryHistoryParameter = new QueryHistoryParameters(FilePath, RecursionType.Full); queryHistoryParameter.MaxResults = NumDisplay; if (!NoMinVersion) { queryHistoryParameter.VersionStart = VersionSpec.ParseSingleSpec(VersionMin, null); } if (!GetLatestVersion) { queryHistoryParameter.VersionEnd = VersionSpec.ParseSingleSpec(VersionMax, null); } // Query history if we are not already querying // if (!queryHistoryWorker.IsBusy) { Status = "Querying History"; queryHistoryWorker.RunWorkerAsync(queryHistoryParameter); } }
/* This function queries the selected TFS project for recent changesets and writes * the results, including full, untruncated comments in a .csv file. */ private static void ExportChangesetsWithFullComments(string author, bool sortAscending) { const int maxChangesets = 10000; Uri defaultCollectionURI = new Uri(ConfigurationManager.AppSettings["defaultCollectionURI"]); TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false); var defaultCollection = new TfsTeamProjectCollection(defaultCollectionURI); tpp.SelectedTeamProjectCollection = defaultCollection; tpp.SelectedProjects = GetDefaultProjectInfo(defaultCollection); var dlgResult = tpp.ShowDialog(); if (dlgResult != System.Windows.Forms.DialogResult.OK) { return; } string input = Microsoft.VisualBasic.Interaction.InputBox("Enter a positive integer:", "Number of Days Past", "30", -1, -1); if (string.IsNullOrEmpty(input)) { return; } int numDays = 0; bool isSuccessful = Int32.TryParse(input, out numDays); if (!isSuccessful || numDays <= 0) { return; } DateTime earliest = DateTime.Today.AddDays(-numDays); var tpc = tpp.SelectedTeamProjectCollection; var projectName = tpp.SelectedProjects[0].Name; VersionControlServer versionControl = tpc.GetService <VersionControlServer>(); var tp = versionControl.GetTeamProject(projectName); var path = tp.ServerItem; var queryHistoryParameters = new QueryHistoryParameters(path, RecursionType.Full) { ItemVersion = VersionSpec.Latest, DeletionId = 0, Author = author, VersionStart = new DateVersionSpec(earliest), VersionEnd = null, MaxResults = maxChangesets, IncludeChanges = false, SlotMode = true, IncludeDownloadInfo = false, SortAscending = sortAscending }; var q = versionControl.QueryHistory(queryHistoryParameters); int rowsReturned = 0; // Write the query results to a new file named "[ProjectName] Changesets with full comments [timestamp].csv". var outputFileName = string.Format("{0} Changesets with full comments {1:yyyy-MM-dd hhmm tt}.csv", projectName, DateTime.Now); string defaultOutputFolder = ConfigurationManager.AppSettings["outputFolder"]; var outputPath = Path.Combine(defaultOutputFolder, outputFileName); using (StreamWriter outputFile = new StreamWriter(outputPath)) { outputFile.WriteLine("Changeset,User,Date,Comment"); foreach (Changeset cs in q) { var comment = cs.Comment; // Replace double quotes with single quotes to make it simpler for Excel // to parse the .csv file. comment = comment.Replace("\"", "'"); // Wrap the comment in double quotes. outputFile.WriteLine(string.Format(@"{0},""{1}"",{2},""{3}""", cs.ChangesetId, cs.OwnerDisplayName, cs.CreationDate, comment)); ++rowsReturned; } } Console.WriteLine("{0:N0} rows written to {1}\r\n", rowsReturned, outputPath); }
private void GetData() { var parameters = new QueryHistoryParameters(this.pathTextBox.Text, this.pickerFrom.SelectedDate.Value, this.pickerTo.SelectedDate.Value); parameters.FileExtension = ".cs"; var fileChanges = this.provider.QueryHistory(parameters); this.testData = this.infoProvider.GetTestMethodData(fileChanges).OrderByDescending(i => i.TestCountChage).ToList(); this.groupedData = this.testData .GroupBy(i => i.Comitter) .Select(g => new GroupedTestData() { Comitter = g.Key, TestCountDelta = g.Sum(h => h.TestCountChage) }) .OrderBy(v => v.TestCountDelta) .ToList(); }
private static Changeset GetChangeset(IBuildDetail buildDetail, Workspace workspace, IBuildAgent buildAgent) { var workspaceSourcePath = Path.Combine(buildAgent.GetExpandedBuildDirectory(buildDetail.BuildDefinition), "Sources"); var versionSpec = new WorkspaceVersionSpec(workspace); var historyParams = new QueryHistoryParameters(workspaceSourcePath, RecursionType.Full) { ItemVersion = versionSpec, VersionEnd = versionSpec, MaxResults = 1 }; var changeset = workspace.VersionControlServer.QueryHistory(historyParams).FirstOrDefault(); return changeset; }
public override void ExportHistory(string branchPath, DateTime dateFrom, DateTime dateTo, string path) { Logger.Info($"{this.GetType()} fetching changesets"); path = Path.Combine(path, branchPath); var versionService = project.GetService <VersionControlServer>(); var qparms = new QueryHistoryParameters($"$/{ProjectName}/{branchPath}", RecursionType.Full) { VersionStart = new DateVersionSpec(dateFrom), VersionEnd = new DateVersionSpec(dateTo), SlotMode = false, IncludeChanges = true }; var changesets = versionService.QueryHistory(qparms)?.OrderBy(x => x.CreationDate).ToList(); if (changesets == null) { Logger.Error($"{this.GetType()} unable to get changesets, aborting"); return; } Logger.Info($"{this.GetType()} found {changesets.Count()} changesets"); if (Directory.Exists(path)) { Directory.Delete(path, true); } Logger.Info($"{this.GetType()} creating output folder (deleting of not empty)"); Directory.CreateDirectory(path); foreach (var changeset in changesets) { Logger.Info($"{this.GetType()} fetching details for {changeset.ChangesetId}"); var changeDir = Path.Combine(path, $"{changeset.CreationDate:yyy-MM-dd} - {changeset.ChangesetId}"); Directory.CreateDirectory(changeDir); Thread.Sleep(100); changeset.SaveToFile(Path.Combine(changeDir, changeset.ChangesetId.ToString() + ".xml")); var changes = versionService.GetChangesForChangeset(changeset.ChangesetId, true, Int32.MaxValue, null, null)?.Where(c => c.Item.ItemType == ItemType.File).ToList(); Logger.Info($"{this.GetType()} \tdownloading {changes?.Count() ?? 0} changed file(s) including previous version..."); if (changes == null || changes?.Any() == false) { continue; } Parallel.ForEach(changes, (change) => { var changesetlist = (IEnumerable <Changeset>)versionService.QueryHistory(change.Item.ServerItem, VersionSpec.Latest, 0, RecursionType.None, null, null, new ChangesetVersionSpec(change.Item.ChangesetId), int.MaxValue, true, false); changesetlist = changesetlist.OrderByDescending(x => x.ChangesetId).ToList(); if (!change.Item.ServerItem.Contains(branchPath)) { return; } var filePath = Path.Combine(changeDir, change.Item.ServerItem.CleanFilename(branchPath)); var fileName = Path.GetFileName(filePath); for (var i = 0; i < (changesetlist.Count() > 2 ? 2 : changesetlist.Count()); i++) { var hist = changesetlist.ElementAt(i); var historicChanges = hist.Changes.Where(x => x.Item.ServerItem.Contains(fileName)).ToList(); if (!historicChanges.Any()) { continue; } var historicChange = historicChanges.First(); var historicFilePath = filePath + "." + historicChange.Item.ChangesetId; historicChange.Item.DownloadFile(historicFilePath); } }); } }