Example #1
0
 //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}
                                          });
 }
Example #2
0
 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;
 }
Example #3
0
 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();
 }
Example #4
0
 private string Commit(LogEntry logEntry)
 {
     string commitHash = null;
     WithCommitHeaderEnv(logEntry, () => commitHash = WriteCommit(logEntry));
     // TODO (maybe): StoreChangesetMetadata(commitInfo);
     return commitHash;
 }
Example #5
0
        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;
        }
Example #6
0
 private string Commit(LogEntry logEntry)
 {
     logEntry.Log = BuildCommitMessage(logEntry.Log, logEntry.ChangesetId);
     return Repository.Commit(logEntry).Sha;
 }
Example #7
0
        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;
        }
Example #8
0
 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;
 }
Example #9
0
 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();
 }