public CommitCommand( int markId, string reference, AuthorCommand author, CommitterCommand committer, DataCommand commitInfo, CommitCommand fromCommit, IList<CommitCommand> mergeCommits, IList<FileCommand> fileCommands) { if (string.IsNullOrEmpty(reference)) throw new InvalidOperationException("The Reference for this commit must be valid."); if (committer == null) throw new InvalidOperationException("A committer must be specified for this commit."); if (commitInfo == null) throw new InvalidOperationException("Commit Information must be specified for this commit."); base.MarkId = markId; this.Reference = reference; this.Author = author; this.Committer = committer; this.CommitInfo = commitInfo; this.FromCommit = fromCommit; this.MergeCommits = (mergeCommits ?? new List<CommitCommand>()).ToList().AsReadOnly(); this.FileCommands = (fileCommands ?? new List<FileCommand>()).ToList().AsReadOnly(); }
public CommitCommand( int markId, string reference, AuthorCommand author, CommitterCommand committer, DataCommand commitInfo, CommitCommand fromCommit, IList <CommitCommand> mergeCommits, IList <FileCommand> fileCommands) { if (string.IsNullOrEmpty(reference)) { throw new InvalidOperationException("The Reference for this commit must be valid."); } if (committer == null) { throw new InvalidOperationException("A committer must be specified for this commit."); } if (commitInfo == null) { throw new InvalidOperationException("Commit Information must be specified for this commit."); } base.MarkId = markId; this.Reference = reference; this.Author = author; this.Committer = committer; this.CommitInfo = commitInfo; this.FromCommit = fromCommit; this.MergeCommits = (mergeCommits ?? new List <CommitCommand>()).ToList().AsReadOnly(); this.FileCommands = (fileCommands ?? new List <FileCommand>()).ToList().AsReadOnly(); }
private CommitCommand DoProcessChangeSet(bool usingStdOut) { // Get userInfo Tuple<string, string> committerInfo = GetUserDisplayNameAndEmail(_ChangeSet.CommitterDisplayName, _ChangeSet.Committer); var committer = new CommitterCommand(committerInfo.Item1, committerInfo.Item2, _ChangeSet.CreationDate); AuthorCommand author = null; if (_ChangeSet.Owner != _ChangeSet.Committer) { Tuple<string, string> authorInfo = GetUserDisplayNameAndEmail(_ChangeSet.OwnerDisplayName, _ChangeSet.Owner); author = new AuthorCommand(authorInfo.Item1, authorInfo.Item2, _ChangeSet.CreationDate); } var orderedChanges = _ChangeSet.Changes .Where(_WhereClause) .Select((x, i) => new { x, i }) .OrderBy(z => z.x.ChangeType) .ThenBy(z => z.i) .Select(z => z.x) .ToList(); var deleteBranch = false; foreach (var change in orderedChanges) { if (!usingStdOut) Console.Write("."); // Show progress var path = GetPath(change.Item.ServerItem); if (path == null) continue; // we delete before we check folders in case we can delete // an entire subdir w/ one command instead of file by file if ((change.ChangeType & ChangeType.Delete) == ChangeType.Delete) { fileCommands.Add(new FileDeleteCommand(path)); if (path == "") { deleteBranch = true; break; } continue; } if (change.Item.ItemType == ItemType.Folder) continue; if ((change.ChangeType & ChangeType.Rename) == ChangeType.Rename) { var vcs = change.Item.VersionControlServer; var history = vcs .QueryHistory( change.Item.ServerItem, new ChangesetVersionSpec(_ChangeSet.ChangesetId), change.Item.DeletionId, RecursionType.None, null, null, new ChangesetVersionSpec(_ChangeSet.ChangesetId), int.MaxValue, true, false) .OfType<Changeset>() .ToList(); var previousChangeset = history[1]; var previousFile = previousChangeset.Changes[0]; var previousPath = GetPath(previousFile.Item.ServerItem); fileCommands.Add(new FileRenameCommand(previousPath, path)); // remove delete commands, since rename will take care of biz fileCommands.RemoveAll(fc => fc is FileDeleteCommand && fc.Path == previousPath); } var blob = GetDataBlob(change.Item); if (blob != null) { fileCommands.Add(new FileModifyCommand(path, blob)); } else { ; // The file that failed is ignored. Do nothing. } if ((change.ChangeType & ChangeType.Branch) == ChangeType.Branch) { var vcs = change.Item.VersionControlServer; var history = vcs.GetBranchHistory(new[] { new ItemSpec(change.Item.ServerItem, RecursionType.None) }, new ChangesetVersionSpec(_ChangeSet.ChangesetId)); if (history.Any() && history[0].Any()) { var itemHistory = history[0][0]; var mergedItem = FindMergedItem(itemHistory, _ChangeSet.ChangesetId); var branchFrom = GetBranch(mergedItem.Relative.BranchFromItem.ServerItem); if (branchFrom != null) { var branchFromInfo = branchFrom.Item2; var previousCommit = branchFromInfo.Item2; if (!merges.Contains(previousCommit)) merges.Add(previousCommit); } else { Console.Error.WriteLine("Unable to find the source of the branch-changeset: {0}, ServerItem: {1}", _ChangeSet.ChangesetId, mergedItem.Relative.BranchFromItem.ServerItem); } } else { Console.Error.WriteLine("Unable to get proper history-info for the branch-changeset: {0}, ServerItem: {1}", _ChangeSet.ChangesetId, change.Item.ServerItem); } } if ((change.ChangeType & ChangeType.Merge) == ChangeType.Merge) { var vcs = change.Item.VersionControlServer; var mergeHistory = vcs.QueryMergesExtended(new ItemSpec(change.Item.ServerItem, RecursionType.None), new ChangesetVersionSpec(_ChangeSet.ChangesetId), null, new ChangesetVersionSpec(_ChangeSet.ChangesetId)).ToList(); foreach (var mh in mergeHistory) { var branchInfo = GetBranch(mh.SourceItem.Item.ServerItem).Item2; var previousCommit = branchInfo.Item2; if (!merges.Contains(previousCommit)) merges.Add(previousCommit); } } } var reference = _Branches[branch]; var commit = new CommitCommand( markId: _ChangeSet.ChangesetId, reference: reference.Item1, committer: committer, author: author, commitInfo: new DataCommand(_ChangeSet.Comment ?? ""), fromCommit: reference.Item2, mergeCommits: merges, fileCommands: fileCommands); _Commits[_ChangeSet.ChangesetId] = commit; if (deleteBranch) _Branches.Remove(branch); else _Branches[branch] = Tuple.Create(reference.Item1, commit); return commit; }