Exemple #1
0
        void DataReceived(string line)
        {
            if (line == null)
            {
                return;
            }

            if (line == CommitBegin)
            {
                // a new commit finalizes the last revision
                FinishRevision();

                _nextStep = ReadStep.Commit;
            }

            switch (_nextStep)
            {
            case ReadStep.Commit:
                // Sanity check
                if (line == CommitBegin)
                {
                    _revision = new GitRevision(_module, null);
                }
                else
                {
                    // Bail out until we see what we expect
                    return;
                }
                break;

            case ReadStep.Hash:
                _revision.Guid = line;

                List <GitRef> gitRefs;
                if (_refs.TryGetValue(_revision.Guid, out gitRefs))
                {
                    _revision.Refs.AddRange(gitRefs);
                }

                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.CommitterEmail:
                _revision.CommitterEmail = 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 = _module.ReEncodeCommitMessage(line, _revision.MessageEncoding);

                break;

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

            _nextStep++;
        }
        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;
                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++;
        }
Exemple #3
0
        void DataReceived(string data)
        {
            if (data.StartsWith(CommitBegin))
            {
                // a new commit finalizes the last revision
                FinishRevision();
                _nextStep = ReadStep.Commit;
            }

            switch (_nextStep)
            {
            case ReadStep.Commit:
                data = GitModule.ReEncodeString(data, GitModule.LosslessEncoding, _module.LogOutputEncoding);

                string[] lines = data.Split(new char[] { '\n' });
                Debug.Assert(lines.Length == 11);
                Debug.Assert(lines[0] == CommitBegin);

                _revision = new GitRevision(_module, null);

                _revision.Guid = lines[1];
                {
                    List <GitRef> gitRefs;
                    if (_refs.TryGetValue(_revision.Guid, out gitRefs))
                    {
                        _revision.Refs.AddRange(gitRefs);
                    }
                }

                // RemoveEmptyEntries is required for root commits. They should have empty list of parents.
                _revision.ParentGuids = lines[2].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                _revision.TreeGuid    = lines[3];

                _revision.Author      = lines[4];
                _revision.AuthorEmail = lines[5];
                {
                    DateTime dateTime;
                    if (DateTimeUtils.TryParseUnixTime(lines[6], out dateTime))
                    {
                        _revision.AuthorDate = dateTime;
                    }
                }

                _revision.Committer      = lines[7];
                _revision.CommitterEmail = lines[8];
                {
                    DateTime dateTime;
                    if (DateTimeUtils.TryParseUnixTime(lines[9], out dateTime))
                    {
                        _revision.CommitDate = dateTime;
                    }
                }

                _revision.MessageEncoding = lines[10];
                break;

            case ReadStep.CommitSubject:
                _revision.Subject = _module.ReEncodeCommitMessage(data, _revision.MessageEncoding);
                break;

            case ReadStep.CommitBody:
                _revision.Body = _module.ReEncodeCommitMessage(data, _revision.MessageEncoding);
                break;

            case ReadStep.FileName:
                if (!string.IsNullOrEmpty(data))
                {
                    // Git adds \n between the format string (ends with \0 in our case)
                    // and the first file name. So, we need to remove it from the file name.
                    _revision.Name = data.TrimStart(new char[] { '\n' });
                }
                break;
            }

            _nextStep++;
        }