//private Encoding LookupEncoding(string encoding) //{ // if(encoding == null) // return null; // throw new NotImplementedException("Need to implement encoding lookup for " + encoding); //} private void WithCommitHeaderEnv(LogEntry logEntry, Action action) { WithTemporaryEnvironment(action, new Dictionary<string, string> { {"GIT_AUTHOR_NAME", logEntry.AuthorName}, {"GIT_AUTHOR_EMAIL", logEntry.AuthorEmail}, {"GIT_AUTHOR_DATE", logEntry.Date.FormatForGit()}, {"GIT_COMMITTER_DATE", logEntry.Date.FormatForGit()}, {"GIT_COMMITTER_NAME", logEntry.CommitterName ?? logEntry.AuthorName}, {"GIT_COMMITTER_EMAIL", logEntry.CommitterEmail ?? logEntry.AuthorEmail} }); }
private string WriteCommit(LogEntry logEntry) { // TODO (maybe): encode logEntry.Log according to 'git config --get i18n.commitencoding', if specified //var commitEncoding = Repository.CommandOneline("config", "i18n.commitencoding"); //var encoding = LookupEncoding(commitEncoding) ?? Encoding.UTF8; string commitHash = null; Repository.CommandInputOutputPipe((procIn, procOut) => { procIn.WriteLine(logEntry.Log); procIn.WriteLine(GitTfsConstants.TfsCommitInfoFormat, TfsUrl, TfsRepositoryPath, logEntry.ChangesetId); procIn.Close(); commitHash = ParseCommitInfo(procOut.ReadToEnd()); }, BuildCommitCommand(logEntry)); return commitHash; }
private string[] BuildCommitCommand(LogEntry logEntry) { var tree = logEntry.Tree ?? GetTemporaryIndexTreeSha(); tree.AssertValidSha(); var commitCommand = new List<string> { "commit-tree", tree }; foreach (var parent in logEntry.CommitParents) { commitCommand.Add("-p"); commitCommand.Add(parent); } return commitCommand.ToArray(); }
private string Commit(LogEntry logEntry) { string commitHash = null; WithCommitHeaderEnv(logEntry, () => commitHash = WriteCommit(logEntry)); // TODO (maybe): StoreChangesetMetadata(commitInfo); return commitHash; }
private string ProcessChangeset(ITfsChangeset changeset, LogEntry log) { if (ExportMetadatas) { if (changeset.Summary.Workitems.Any()) { var workItemIds = TranslateWorkItems(changeset.Summary.Workitems.Select(wi => wi.Id.ToString())); if (workItemIds != null) { log.Log += "\nwork-items: " + string.Join(", ", workItemIds.Select(s => "#" + s)); } } if (!string.IsNullOrWhiteSpace(changeset.Summary.PolicyOverrideComment)) log.Log += "\n" + GitTfsConstants.GitTfsPolicyOverrideCommentPrefix + changeset.Summary.PolicyOverrideComment; if (!string.IsNullOrWhiteSpace(changeset.Summary.CodeReviewer)) log.Log += "\n" + GitTfsConstants.GitTfsCodeReviewerPrefix + changeset.Summary.CodeReviewer; if (!string.IsNullOrWhiteSpace(changeset.Summary.SecurityReviewer)) log.Log += "\n" + GitTfsConstants.GitTfsSecurityReviewerPrefix + changeset.Summary.SecurityReviewer; if (!string.IsNullOrWhiteSpace(changeset.Summary.PerformanceReviewer)) log.Log += "\n" + GitTfsConstants.GitTfsPerformanceReviewerPrefix + changeset.Summary.PerformanceReviewer; } var commitSha = Commit(log); UpdateTfsHead(commitSha, changeset.Summary.ChangesetId); StringBuilder metadatas = new StringBuilder(); if (changeset.Summary.Workitems.Any()) { string workitemNote = "Workitems:\n"; foreach (var workitem in changeset.Summary.Workitems) { var workitemId = workitem.Id.ToString(); var workitemUrl = workitem.Url; if (ExportMetadatas && ExportWorkitemsMapping.Count != 0) { if (ExportWorkitemsMapping.ContainsKey(workitemId)) { var oldWorkitemId = workitemId; workitemId = ExportWorkitemsMapping[workitemId]; workitemUrl = workitemUrl.Replace(oldWorkitemId, workitemId); } } workitemNote += String.Format("[{0}] {1}\n {2}\n", workitemId, workitem.Title, workitemUrl); } metadatas.Append(workitemNote); } if (!string.IsNullOrWhiteSpace(changeset.Summary.PolicyOverrideComment)) metadatas.Append("\nPolicy Override Comment:" + changeset.Summary.PolicyOverrideComment); if (!string.IsNullOrWhiteSpace(changeset.Summary.CodeReviewer)) metadatas.Append("\nCode Reviewer:" + changeset.Summary.CodeReviewer); if (!string.IsNullOrWhiteSpace(changeset.Summary.SecurityReviewer)) metadatas.Append("\nSecurity Reviewer:" + changeset.Summary.SecurityReviewer); if (!string.IsNullOrWhiteSpace(changeset.Summary.PerformanceReviewer)) metadatas.Append("\nPerformance Reviewer:" + changeset.Summary.PerformanceReviewer); if (!string.IsNullOrWhiteSpace(changeset.OmittedParentBranch)) metadatas.Append("\nOmitted parent branch: " + changeset.OmittedParentBranch); if (metadatas.Length != 0) Repository.CreateNote(commitSha, metadatas.ToString(), log.AuthorName, log.AuthorEmail, log.Date); return commitSha; }
private string Commit(LogEntry logEntry) { logEntry.Log = BuildCommitMessage(logEntry.Log, logEntry.ChangesetId); return Repository.Commit(logEntry).Sha; }
private string WriteCommit(LogEntry logEntry) { // TODO (maybe): encode logEntry.Log according to 'git config --get i18n.commitencoding', if specified //var commitEncoding = Repository.CommandOneline("config", "i18n.commitencoding"); //var encoding = LookupEncoding(commitEncoding) ?? Encoding.UTF8; string commitHash = null; //the remote to be associated with the commit might be a subtree, if it's null then it's not from a subtree. var remote = logEntry.Remote ?? this; Repository.CommandInputOutputPipe((procIn, procOut) => { procIn.WriteLine(logEntry.Log); procIn.WriteLine(GitTfsConstants.TfsCommitInfoFormat, remote.TfsUrl, remote.TfsRepositoryPath, logEntry.ChangesetId); procIn.Close(); commitHash = ParseCommitInfo(procOut.ReadToEnd()); }, BuildCommitCommand(logEntry)); return commitHash; }
private LogEntry MakeNewLogEntry(IChangeset changesetToLog) { var log = new LogEntry(); var identity = tfs.GetIdentity(changesetToLog.Committer); log.CommitterName = log.AuthorName = null != identity ? identity.DisplayName ?? "Unknown TFS user" : changesetToLog.Committer ?? "Unknown TFS user"; log.CommitterEmail = log.AuthorEmail = null != identity ? identity.MailAddress ?? changesetToLog.Committer : changesetToLog.Committer; log.Date = changesetToLog.CreationDate; log.Log = changesetToLog.Comment + Environment.NewLine; log.ChangesetId = changesetToLog.ChangesetId; return log; }
private string[] BuildCommitCommand(LogEntry logEntry) { var commitCommand = new List<string> { "commit-tree", logEntry.Tree }; foreach (var parent in logEntry.CommitParents) { commitCommand.Add("-p"); commitCommand.Add(parent); } return commitCommand.ToArray(); }