Example #1
0
        /// <summary>
        /// Gets the commit info for submodule.
        /// </summary>
        public static void UpdateCommitMessage(CommitData data, GitModule module, string sha1, ref string error)
        {
            if (module == null)
                throw new ArgumentNullException("module");
            if (sha1 == null)
                throw new ArgumentNullException("sha1");

            //Do not cache this command, since notes can be added
            string arguments = string.Format(CultureInfo.InvariantCulture,
                    "log -1 --pretty=\"format:" + ShortLogFormat + "\" {0}", sha1);
            var info = module.RunGitCmd(arguments, GitModule.LosslessEncoding);

            if (info.Trim().StartsWith("fatal"))
            {
                error = "Cannot find commit " + sha1;
                return;
            }

            int index = info.IndexOf(sha1) + sha1.Length;

            if (index < 0)
            {
                error = "Cannot find commit " + sha1;
                return;
            }
            if (index >= info.Length)
            {
                error = info;
                return;
            }

            UpdateBodyInCommitData(data, info, module);
        }
        /// <summary>
        /// Gets the commit info from CommitData.
        /// </summary>
        /// <returns></returns>
        public static CommitInformation GetCommitInfo(CommitData data)
        {
            if (data == null)
                throw new ArgumentNullException("data");

            string header = data.GetHeader();
            string body = "\n" + WebUtility.HtmlEncode(data.Body.Trim());

            return new CommitInformation(header, body);
        }
Example #3
0
        public SubmoduleStatus CheckSubmoduleStatus(string commit, string oldCommit, CommitData data, CommitData olddata, bool loaddata = false)
        {
            if (!IsValidGitWorkingDir() || oldCommit == null)
                return SubmoduleStatus.NewSubmodule;

            if (commit == null || commit == oldCommit)
                return SubmoduleStatus.Unknown;

            string baseCommit = GetMergeBase(commit, oldCommit);
            if (baseCommit == oldCommit)
                return SubmoduleStatus.FastForward;
            else if (baseCommit == commit)
                return SubmoduleStatus.Rewind;

            string error = "";
            if (loaddata)
                olddata = CommitData.GetCommitData(this, oldCommit, ref error);
            if (olddata == null)
                return SubmoduleStatus.NewSubmodule;
            if (loaddata)
                data = CommitData.GetCommitData(this, commit, ref error);
            if (data == null)
                return SubmoduleStatus.Unknown;
            if (data.CommitDate > olddata.CommitDate)
                return SubmoduleStatus.NewerTime;
            else if (data.CommitDate < olddata.CommitDate)
                return SubmoduleStatus.OlderTime;
            else if (data.CommitDate == olddata.CommitDate)
                return SubmoduleStatus.SameTime;
            return SubmoduleStatus.Unknown;
        }
Example #4
0
        /// <summary>
        /// Creates a CommitData object from formated commit info data from git.  The string passed in should be
        /// exact output of a log or show command using --format=LogFormat.
        /// </summary>
        /// <param name="data">Formated commit data from git.</param>
        /// <returns>CommitData object populated with parsed info from git string.</returns>
        public static CommitData CreateFromFormatedData(string data)
        {
            if (data == null)
                throw new ArgumentNullException("Data");

            var lines = data.Split('\n');

            var guid = lines[0];

            // TODO: we can use this to add more relationship info like gitk does if wanted
            var treeGuid = lines[1];

            // TODO: we can use this to add more relationship info like gitk does if wanted
            string[] parentLines = lines[2].Split(new char[]{' '});
            ReadOnlyCollection<string> parentGuids = parentLines.ToList().AsReadOnly();

            var author = GitCommandHelpers.ReEncodeStringFromLossless(lines[3]);
            var authorDate = GetTimeFromUtcTimeLine(lines[4]);

            var committer = GitCommandHelpers.ReEncodeStringFromLossless(lines[5]);
            var commitDate = GetTimeFromUtcTimeLine(lines[6]);

            string commitEncoding = lines[7];

            int startIndex = 8;
            int endIndex = lines.Length - 1;
            if (lines[endIndex] == "Notes:")
                endIndex--;

            var message = new StringBuilder();
            bool bNotesStart = false;
            for (int i = startIndex; i <= endIndex; i++)
            {
                string line = lines[i];
                if (bNotesStart)
                    line = "    " + line;
                message.AppendLine(line);
                if (lines[i] == "Notes:")
                    bNotesStart = true;
            }

            //commit message is not reencoded by git when format is given
            var body = GitCommandHelpers.ReEncodeCommitMessage(message.ToString(), commitEncoding);

            var commitInformation = new CommitData(guid, treeGuid, parentGuids, author, authorDate,
                committer, commitDate, body);

            return commitInformation;
        }
Example #5
0
        /// <summary>
        /// Creates a CommitData object from formated commit info data from git.  The string passed in should be
        /// exact output of a log or show command using --format=LogFormat.
        /// </summary>
        /// <param name="data">Formated commit data from git.</param>
        /// <returns>CommitData object populated with parsed info from git string.</returns>
        public static void UpdateBodyInCommitData(CommitData commitData, string data, GitModule aModule)
        {
            if (data == null)
                throw new ArgumentNullException("Data");

            var lines = data.Split('\n');

            var guid = lines[0];

            string commitEncoding = lines[1];

            int startIndex = 2;
            int endIndex = lines.Length - 1;
            if (lines[endIndex] == "Notes:")
                endIndex--;

            var message = new StringBuilder();
            bool bNotesStart = false;
            for (int i = startIndex; i <= endIndex; i++)
            {
                string line = lines[i];
                if (bNotesStart)
                    line = "    " + line;
                message.AppendLine(line);
                if (lines[i] == "Notes:")
                    bNotesStart = true;
            }

            //commit message is not reencoded by git when format is given
            Debug.Assert(commitData.Guid == guid);
            commitData.Body = aModule.ReEncodeCommitMessage(message.ToString(), commitEncoding);
        }
Example #6
0
        /// <summary>
        /// Creates a CommitData object from Git revision.
        /// </summary>
        /// <param name="revision">Git commit.</param>
        /// <returns>CommitData object populated with parsed info from git string.</returns>
        public static CommitData CreateFromRevision(GitRevision revision)
        {
            if (revision == null)
                throw new ArgumentNullException("revision");

            CommitData data = new CommitData(revision.Guid, revision.TreeGuid, revision.ParentGuids.ToList().AsReadOnly(),
                String.Format("{0} <{1}>", revision.Author, revision.AuthorEmail), revision.AuthorDate,
                String.Format("{0} <{1}>", revision.Committer, revision.CommitterEmail), revision.CommitDate,
                revision.Message);
            return data;
        }
 private CommitData ProvideCommitData(string commitId)
 {
     if (!_historyGraph.ContainsKey(commitId))
     {
         CommitData dta = new CommitData();
         _historyGraph.Add(commitId, dta);
         return dta;
     }
     else
     {
         return _historyGraph[commitId];
     }
 }
        /// <summary>
        /// Creates a CommitData object from raw commit info data from git.  The string passed in should be
        /// exact output of a log or show command using --format=raw.
        /// </summary>
        /// <param name="rawData">Raw commit data from git.</param>
        /// <returns>CommitData object populated with parsed info from git string.</returns>
        public static CommitData CreateFromRawData(string rawData)
        {
            if (rawData == null)
                throw new ArgumentNullException("rawData");

            var lines = new List<string>(rawData.Split('\n'));

            var commit = lines.Single(l => l.StartsWith(COMMIT_LABEL));
            var guid = commit.Substring(COMMIT_LABEL.Length);
            lines.Remove(commit);

            // TODO: we can use this to add more relationship info like gitk does if wanted
            var tree = lines.Single(l => l.StartsWith(TREE_LABEL));
            var treeGuid = tree.Substring(TREE_LABEL.Length);
            lines.Remove(tree);

            // TODO: we can use this to add more relationship info like gitk does if wanted
            List<string> parentLines = lines.FindAll(l => l.StartsWith(PARENT_LABEL));
            ReadOnlyCollection<string> parentGuids = parentLines.Select(parent => parent.Substring(PARENT_LABEL.Length)).ToList().AsReadOnly();
            lines.RemoveAll(parentLines.Contains);

            var authorInfo = lines.Single(l => l.StartsWith(AUTHOR_LABEL));
            var author = GetPersonFromAuthorInfoLine(authorInfo, AUTHOR_LABEL.Length);
            var authorDate = GetTimeFromAuthorInfoLine(authorInfo);
            lines.Remove(authorInfo);

            var committerInfo = lines.Single(l => l.StartsWith(COMMITTER_LABEL));
            var committer = GetPersonFromAuthorInfoLine(committerInfo, COMMITTER_LABEL.Length);
            var commitDate = GetTimeFromAuthorInfoLine(committerInfo);
            lines.Remove(committerInfo);

            var message = new StringBuilder();
            foreach (var line in lines)
                message.AppendLine(line);

            var body = message.ToString();

            //We need to recode the commit message because of a bug in Git.
            //We cannot let git recode the message to Settings.Encoding which is
            //needed to allow the "git log" to print the filename in Settings.Encoding
            Encoding logoutputEncoding = Settings.Module.GetLogoutputEncoding();
            if (logoutputEncoding != Settings.Encoding)
                body = logoutputEncoding.GetString(Settings.Encoding.GetBytes(body));

            var commitInformation = new CommitData(guid, treeGuid, parentGuids, author, authorDate,
                committer, commitDate, body);

            return commitInformation;
        }
Example #9
0
        /// <summary>
        /// Creates a CommitData object from formated commit info data from git.  The string passed in should be
        /// exact output of a log or show command using --format=LogFormat.
        /// </summary>
        /// <param name="data">Formated commit data from git.</param>
        /// <returns>CommitData object populated with parsed info from git string.</returns>
        public static void UpdateBodyInCommitData(CommitData commitData, string data, GitModule aModule)
        {
            if (data == null)
                throw new ArgumentNullException("data");

            var lines = data.Split(new[] { "\r\n", "\n" }, StringSplitOptions.None);

            var guid = lines[0];

            string commitEncoding = lines[1];

            const int startIndex = 2;
            string message = ProccessDiffNotes(startIndex, lines);

            //commit message is not reencoded by git when format is given
            Debug.Assert(commitData.Guid == guid);
            commitData.Body = aModule.ReEncodeCommitMessage(message, commitEncoding);
        }
Example #10
0
        /// <summary>
        /// Creates a CommitData object from formated commit info data from git.  The string passed in should be
        /// exact output of a log or show command using --format=LogFormat.
        /// </summary>
        /// <param name="data">Formated commit data from git.</param>
        /// <returns>CommitData object populated with parsed info from git string.</returns>
        public static CommitData CreateFromFormatedData(string data, GitModule aModule)
        {
            if (data == null)
                throw new ArgumentNullException("data");

            var lines = data.Split('\n');
            
            var guid = lines[0];

            // TODO: we can use this to add more relationship info like gitk does if wanted
            var treeGuid = lines[1];

            // TODO: we can use this to add more relationship info like gitk does if wanted
            string[] parentLines = lines[2].Split(new char[]{' '});
            ReadOnlyCollection<string> parentGuids = parentLines.ToList().AsReadOnly();

            var author = aModule.ReEncodeStringFromLossless(lines[3]);
            var authorDate = DateTimeUtils.ParseUnixTime(lines[4]);

            var committer = aModule.ReEncodeStringFromLossless(lines[5]);
            var commitDate = DateTimeUtils.ParseUnixTime(lines[6]);

            string commitEncoding = lines[7];

            const int startIndex = 8;
            string message = ProccessDiffNotes(startIndex, lines);

            //commit message is not reencoded by git when format is given
            var body = aModule.ReEncodeCommitMessage(message, commitEncoding);

            var commitInformation = new CommitData(guid, treeGuid, parentGuids, author, authorDate,
                committer, commitDate, body);

            return commitInformation;
        }
Example #11
0
        /// <summary>
        /// Creates a CommitData object from raw commit info data from git.  The string passed in should be
        /// exact output of a log or show command using --format=raw.
        /// </summary>
        /// <param name="rawData">Raw commit data from git.</param>
        /// <returns>CommitData object populated with parsed info from git string.</returns>
        public static CommitData CreateFromRawData(string rawData)
        {
            if (rawData == null)
                throw new ArgumentNullException("rawData");

            var lines = new List<string>(rawData.Split('\n'));

            var commit = lines.Single(l => l.StartsWith(COMMIT_LABEL));
            var guid = commit.Substring(COMMIT_LABEL.Length);
            lines.Remove(commit);

            // TODO: we can use this to add more relationship info like gitk does if wanted
            var tree = lines.Single(l => l.StartsWith(TREE_LABEL));
            var treeGuid = tree.Substring(TREE_LABEL.Length);
            lines.Remove(tree);

            // TODO: we can use this to add more relationship info like gitk does if wanted
            List<string> parentLines = lines.FindAll(l => l.StartsWith(PARENT_LABEL));
            ReadOnlyCollection<string> parentGuids = parentLines.Select(parent => parent.Substring(PARENT_LABEL.Length)).ToList().AsReadOnly();
            lines.RemoveAll(parentLines.Contains);

            var authorInfo = lines.Single(l => l.StartsWith(AUTHOR_LABEL));
            var author = GetPersonFromAuthorInfoLine(authorInfo, AUTHOR_LABEL.Length);
            var authorDate = GetTimeFromAuthorInfoLine(authorInfo);
            lines.Remove(authorInfo);

            var committerInfo = lines.Single(l => l.StartsWith(COMMITTER_LABEL));
            var committer = GetPersonFromAuthorInfoLine(committerInfo, COMMITTER_LABEL.Length);
            var commitDate = GetTimeFromAuthorInfoLine(committerInfo);
            lines.Remove(committerInfo);

            var message = new StringBuilder();
            foreach (var line in lines)
                message.AppendLine(line);

            var body = message.ToString();

            var commitInformation = new CommitData(guid, treeGuid, parentGuids, author, authorDate,
                committer, commitDate, body);

            return commitInformation;
        }
        private static CommitInformation CreateCommitInformation(CommitData data)
        {
            string header = data.GetHeader();
            string body = "\n\n" + HttpUtility.HtmlEncode(data.Body.Trim()) + "\n\n";

            return new CommitInformation(header, body);
        }
        /// <summary>
        /// Gets the commit info from CommitData.
        /// </summary>
        /// <returns></returns>
        public static CommitInformation GetCommitInfo(CommitData data)
        {
            if (data == null)
                throw new ArgumentNullException("data");

            return CreateCommitInformation(data);
        }