Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        void dataReceived(string line)
        {
            if (line == null)
            {
                return;
            }

            if (line == COMMIT_BEGIN)
            {
                // a new commit finalizes the last revision
                finishRevision();

                nextStep = ReadStep.Commit;
            }

            switch (nextStep)
            {
            case ReadStep.Commit:
                // Sanity check
                if (line == COMMIT_BEGIN)
                {
                    revision = new GitRevision(null);
                }
                else
                {
                    // Bail out until we see what we expect
                    return;
                }
                break;

            case ReadStep.Hash:
                revision.Guid = line;

                List <GitHead> headList;
                if (heads.TryGetValue(revision.Guid, out headList))
                {
                    revision.Heads.AddRange(headList);
                }

                break;

            case ReadStep.Parents:
                revision.ParentGuids = line.Split(splitChars, StringSplitOptions.RemoveEmptyEntries);
                break;

            case ReadStep.Tree:
                revision.TreeGuid = line;
                break;

            case ReadStep.AuthorName:
                revision.Author = line;
                break;

            case ReadStep.AuthorEmail:
                revision.AuthorEmail = line;
                break;

            case ReadStep.AuthorDate:
            {
                DateTime dateTime;
                if (DateTimeUtils.TryParseUnixTime(line, out dateTime))
                {
                    revision.AuthorDate = dateTime;
                }
            }
            break;

            case ReadStep.CommitterName:
                revision.Committer = line;
                break;

            case ReadStep.CommitterDate:
            {
                DateTime dateTime;
                if (DateTimeUtils.TryParseUnixTime(line, out dateTime))
                {
                    revision.CommitDate = dateTime;
                }
            }
            break;

            case ReadStep.CommitMessageEncoding:
                revision.MessageEncoding = line;
                break;

            case ReadStep.CommitMessage:
                revision.Message = GitCommandHelpers.ReEncodeCommitMessage(line, revision.MessageEncoding);

                break;

            case ReadStep.FileName:
                revision.Name = line;
                break;
            }

            nextStep++;
        }
Exemplo n.º 3
0
        void dataReceived(string line)
        {
            if (line == null)
            {
                return;
            }

            if (line == COMMIT_BEGIN)
            {
                // a new commit finalizes the last revision
                finishRevision();

                nextStep = ReadStep.Commit;
            }

            switch (nextStep)
            {
            case ReadStep.Commit:
                // Sanity check
                if (line == COMMIT_BEGIN)
                {
                    revision = new GitRevision(null);
                }
                else
                {
                    // Bail out until we see what we expect
                    return;
                }
                break;

            case ReadStep.Hash:
                revision.Guid = line;
                for (int i = heads.Count - 1; i >= 0; i--)
                {
                    if (heads[i].Guid == revision.Guid)
                    {
                        revision.Heads.Add(heads[i]);

                        //Only search for a head once, remove it from list
                        heads.Remove(heads[i]);
                    }
                }
                break;

            case ReadStep.Parents:
                revision.ParentGuids = line.Split(splitChars, StringSplitOptions.RemoveEmptyEntries);
                break;

            case ReadStep.Tree:
                revision.TreeGuid = line;
                break;

            case ReadStep.AuthorName:
                revision.Author = line;
                break;

            case ReadStep.AuthorEmail:
                revision.AuthorEmail = line;
                break;

            case ReadStep.AuthorDate:
            {
                DateTime dateTime;
                DateTime.TryParse(line, out dateTime);
                revision.AuthorDate = dateTime;
            }
            break;

            case ReadStep.CommitterName:
                revision.Committer = line;
                break;

            case ReadStep.CommitterDate:
            {
                DateTime dateTime;
                DateTime.TryParse(line, out dateTime);
                revision.CommitDate = dateTime;
            }
            break;

            case ReadStep.CommitMessageEncoding:
                revision.MessageEncoding = line;
                break;

            case ReadStep.CommitMessage:
                revision.Message = GitCommandHelpers.ReEncodeCommitMessage(line, revision.MessageEncoding);

                break;

            case ReadStep.FileName:
                revision.Name = line;
                break;
            }

            nextStep++;
        }