Example #1
0
        protected override bool ProcessLine(string line, out GitBranch result)
        {
            base.ProcessLine(line, out result);

            if (line == null)
            {
                return(false);
            }

            var proc = new LineParser(line);

            if (proc.IsAtEnd)
            {
                return(false);
            }

            try
            {
                string name;
                string trackingName = null;

                if (proc.Matches('*'))
                {
                    proc.MoveNext();
                }
                proc.SkipWhitespace();
                if (proc.Matches("(HEAD "))
                {
                    name = "detached";
                    proc.MoveToAfter(')');
                }
                else
                {
                    name = proc.ReadUntilWhitespace();
                }

                proc.ReadUntilWhitespaceTrim();
                if (proc.Matches(trackingBranchRegex))
                {
                    trackingName = proc.ReadChunk('[', ']');
                    var indexOf = trackingName.IndexOf(':');
                    if (indexOf != -1)
                    {
                        trackingName = trackingName.Substring(0, indexOf);
                    }
                }

                result = new GitBranch(name, trackingName);
                return(true);
            }
            catch (Exception ex)
            {
                Logger.Warning(ex, "Unexpected input when listing branches");
            }

            return(false);
        }
        public override void LineReceived(string line)
        {
            if (line == null)
            {
                return;
            }

            var proc = new LineParser(line);

            if (proc.IsAtEnd)
            {
                return;
            }

            try
            {
                string name;
                string trackingName = null;

                if (proc.Matches('*'))
                {
                    proc.MoveNext();
                }
                proc.SkipWhitespace();
                if (proc.Matches("(HEAD "))
                {
                    name = "detached";
                    proc.MoveToAfter(')');
                }
                else
                {
                    name = proc.ReadUntilWhitespace();
                }

                proc.ReadUntilWhitespaceTrim();
                if (proc.Matches(trackingBranchRegex))
                {
                    trackingName = proc.ReadChunk('[', ']');
                    var indexOf = trackingName.IndexOf(':');
                    if (indexOf != -1)
                    {
                        trackingName = trackingName.Substring(0, indexOf);
                    }
                }

                var branch = new GitBranch(name, trackingName);
                RaiseOnEntry(branch);
            }
            catch (Exception ex)
            {
                Logger.Warning(ex, "Unexpected input when listing branches");
            }
        }
        private GitRemote ReturnRemote()
        {
            var modes = currentModes.Select(s => s.ToUpperInvariant()).ToArray();

            var isFetch = modes.Contains("FETCH");
            var isPush  = modes.Contains("PUSH");

            GitRemoteFunction remoteFunction;

            if (isFetch && isPush)
            {
                remoteFunction = GitRemoteFunction.Both;
            }
            else if (isFetch)
            {
                remoteFunction = GitRemoteFunction.Fetch;
            }
            else if (isPush)
            {
                remoteFunction = GitRemoteFunction.Push;
            }
            else
            {
                remoteFunction = GitRemoteFunction.Unknown;
            }

            string host;
            string user = null;
            var    proc = new LineParser(currentUrl);

            if (proc.Matches("http") || proc.Matches("https"))
            {
                proc.MoveToAfter(':');
                proc.MoveNext();
                proc.MoveNext();
                host = proc.ReadUntil('/');
            }
            else
            {
                //Assuming SSH here
                user = proc.ReadUntil('@');
                proc.MoveNext();
                host = proc.ReadUntil(':');

                currentUrl = currentUrl.Substring(user.Length + 1);
            }

            var remote = new GitRemote(currentName, host, currentUrl, remoteFunction, user, null, null);

            Reset();
            return(remote);
        }
        public override void LineReceived(string line)
        {
            if (line == null)
            {
                return;
            }

            int kb;
            var proc = new LineParser(line);

            if (int.TryParse(proc.ReadUntilWhitespace(), out kb))
            {
                RaiseOnEntry(kb);
            }
        }
        protected override bool ProcessLine(string line, out GitRemote result)
        {
            base.ProcessLine(line, out result);

            //origin https://github.com/github/VisualStudio.git (fetch)

            if (line == null)
            {
                result = ReturnRemote();
                return(true);
            }

            var shouldRaiseEntry = false;

            var proc = new LineParser(line);
            var name = proc.ReadUntilWhitespace();

            proc.SkipWhitespace();

            var url = proc.ReadUntilWhitespace();

            proc.SkipWhitespace();

            proc.MoveNext();
            var mode = proc.ReadUntil(')');

            if (currentName == null)
            {
                currentName = name;
                currentUrl  = url;
                currentModes.Add(mode);
            }
            else if (currentName == name)
            {
                currentModes.Add(mode);
            }
            else
            {
                shouldRaiseEntry = true;
                result           = ReturnRemote();

                currentName = name;
                currentUrl  = url;
                currentModes.Add(mode);
            }
            return(shouldRaiseEntry);
        }
        protected override bool ProcessLine(string line, out GitAheadBehindStatus result)
        {
            base.ProcessLine(line, out result);

            if (line == null)
            {
                return(false);
            }

            var proc = new LineParser(line);

            var ahead  = int.Parse(proc.ReadUntilWhitespace());
            var behind = int.Parse(proc.ReadToEnd());

            result = new GitAheadBehindStatus(ahead, behind);
            return(true);
        }
Example #7
0
        protected override bool ProcessLine(string line, out int result)
        {
            base.ProcessLine(line, out result);

            //parses 2488 objects, 4237 kilobytes
            try
            {
                var proc = new LineParser(line);

                proc.MoveToAfter(',');
                var kilobytes = int.Parse(proc.ReadUntilWhitespaceTrim());

                result = kilobytes;
                return(true);
            }
            catch {}
            return(false);
        }
Example #8
0
        public override void LineReceived(string line)
        {
            //origin https://github.com/github/VisualStudio.git (fetch)

            if (line == null)
            {
                ReturnRemote();
                return;
            }

            var proc = new LineParser(line);
            var name = proc.ReadUntilWhitespace();
            proc.SkipWhitespace();

            var url = proc.ReadUntilWhitespace();
            proc.SkipWhitespace();

            proc.MoveNext();
            var mode = proc.ReadUntil(')');

            if (currentName == null)
            {
                currentName = name;
                currentUrl = url;
                currentModes.Add(mode);
            }
            else if (currentName == name)
            {
                currentModes.Add(mode);
            }
            else
            {
                ReturnRemote();

                currentName = name;
                currentUrl = url;
                currentModes.Add(mode);
            }
        }
        protected override bool ProcessLine(string line, out GitStatus result)
        {
            result = default;

            if (line == null)
            {
                ReturnStatus();
            }
            else
            {
                Prepare();

                var proc = new LineParser(line);
                if (gitStatus.LocalBranch == null)
                {
                    if (proc.Matches("##"))
                    {
                        proc.MoveToAfter('#');
                        proc.SkipWhitespace();

                        string branchesString;
                        if (proc.Matches(branchTrackedAndDelta))
                        {
                            //master...origin/master [ahead 1]
                            //master...origin/master [behind 1]
                            //master...origin/master [ahead 1, behind 1]

                            branchesString = proc.ReadUntilWhitespace();

                            proc.MoveToAfter('[');

                            var deltaString = proc.ReadUntil(']');
                            var deltas      = deltaString.Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (var delta in deltas)
                            {
                                var deltaComponents = delta.Split(' ');
                                if (deltaComponents[0] == "ahead")
                                {
                                    gitStatus.ahead = Int32.Parse(deltaComponents[1]);
                                }
                                else if (deltaComponents[0] == "behind")
                                {
                                    gitStatus.behind = Int32.Parse(deltaComponents[1]);
                                }
                                else if (deltaComponents[0] == "gone")
                                {
                                }
                                else
                                {
                                    throw new InvalidOperationException("Unexpected deltaComponent in o");
                                }
                            }
                        }
                        else
                        {
                            branchesString = proc.ReadToEnd();
                        }

                        var branches = branchesString.Split(new[] { "..." }, StringSplitOptions.RemoveEmptyEntries);
                        gitStatus.localBranch = branches[0];
                        if (branches.Length == 2)
                        {
                            gitStatus.remoteBranch = branches[1];
                        }
                    }
                    else
                    {
                        HandleUnexpected(line);
                    }
                }
                else
                {
                    var gitStatusMarker = proc.Read(2);
                    if (gitStatusMarker == null)
                    {
                        HandleUnexpected(line);
                        return(false);
                    }


                    /*
                     * X          Y     Meaning
                     * -------------------------------------------------
                     *           [AMD]   not updated
                     * M        [ MD]   updated in index
                     * A        [ MD]   added to index
                     * D                deleted from index
                     * R        [ MD]   renamed in index
                     * C        [ MD]   copied in index
                     * [MARC]           index and work tree matches
                     * [ MARC]     M    work tree changed since index
                     * [ MARC]     D    deleted in work tree
                     * [ D]        R    renamed in work tree
                     * [ D]        C    copied in work tree
                     * -------------------------------------------------
                     * D           D    unmerged, both deleted
                     * A           A    unmerged, both added
                     * A           U    unmerged, added by us
                     * D           U    unmerged, deleted by us
                     * U           A    unmerged, added by them
                     * U           D    unmerged, deleted by them
                     * U           U    unmerged, both modified
                     * -------------------------------------------------
                     * ?           ?    untracked
                     * !           !    ignored
                     * -------------------------------------------------
                     */

                    string originalPath = null;
                    string path         = null;

                    var indexStatusMarker    = gitStatusMarker[0];
                    var workTreeStatusMarker = gitStatusMarker[1];

                    GitFileStatus indexStatus    = GitStatusEntry.ParseStatusMarker(indexStatusMarker);
                    GitFileStatus workTreeStatus = GitStatusEntry.ParseStatusMarker(workTreeStatusMarker);
                    GitFileStatus status         = workTreeStatus != GitFileStatus.None ? workTreeStatus : indexStatus;

                    if (status == GitFileStatus.None)
                    {
                        HandleUnexpected(line);
                        return(false);
                    }

                    if (status == GitFileStatus.Copied || status == GitFileStatus.Renamed)
                    {
                        var files =
                            proc.ReadToEnd()
                            .Split(new[] { "->" }, StringSplitOptions.RemoveEmptyEntries)
                            .Select(s => s.Trim())
                            .Select(s => s.Trim('"'))
                            .ToArray();

                        originalPath = files[0];
                        path         = files[1];
                    }
                    else
                    {
                        path = proc.ReadToEnd().Trim().Trim('"');
                    }

                    var gitStatusEntry = gitObjectFactory.CreateGitStatusEntry(path, indexStatus, workTreeStatus, originalPath);
                    gitStatus.Entries.Add(gitStatusEntry);
                }
            }
            return(false);
        }
        protected override bool ProcessLine(string line, out GitLogEntry result)
        {
            base.ProcessLine(line, out result);

            if (line == null)
            {
                ReturnGitLogEntry();
                return(false);
            }

            sb.AppendLine(line);

            if (phase == ProcessingPhase.Files && seenBodyEnd)
            {
                seenBodyEnd = false;
                var proc = new LineParser(line);
                if (proc.Matches(hashRegex))
                {
                    // there's no files on this commit, it's a new one!
                    ReturnGitLogEntry();
                }
            }

            switch (phase)
            {
            case ProcessingPhase.CommitHash:
                commitId = line;
                phase++;
                break;

            case ProcessingPhase.ParentHash:
                var parentHashes = line.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);

                if (parentHashes.Length > 1)
                {
                    mergeA = parentHashes[0];
                    mergeB = parentHashes[1];
                }

                phase++;
                break;

            case ProcessingPhase.AuthorName:
                authorName = line;
                phase++;
                break;

            case ProcessingPhase.AuthorEmail:
                authorEmail = line;
                phase++;
                break;

            case ProcessingPhase.AuthorDate:
                DateTimeOffset t;
                if (DateTimeOffset.TryParse(line, out t))
                {
                    time = t;
                }
                else
                {
                    Logger.Error("ERROR {0}", sb.ToString());
                    throw new FormatException("Invalid line");
                }
                phase++;
                break;

            case ProcessingPhase.CommitterName:
                committerName = line;
                phase++;
                break;

            case ProcessingPhase.CommitterEmail:
                committerEmail = line;
                phase++;
                break;

            case ProcessingPhase.CommitterDate:
                committerTime = DateTimeOffset.Parse(line);
                phase++;
                break;

            case ProcessingPhase.Summary:
            {
                var idx      = line.IndexOf("---GHUBODYEND---", StringComparison.Ordinal);
                var oneliner = idx >= 0;
                if (oneliner)
                {
                    line = line.Substring(0, idx);
                }

                summary = line;
                phase++;
                // there's no description so skip it
                if (oneliner)
                {
                    phase++;
                    seenBodyEnd = true;
                }
            }
            break;

            case ProcessingPhase.Description:
                var indexOf = line.IndexOf("---GHUBODYEND---", StringComparison.InvariantCulture);
                if (indexOf == -1)
                {
                    descriptionLines.Add(line);
                }
                else if (indexOf == 0)
                {
                    phase++;
                    seenBodyEnd = true;
                }
                else
                {
                    var substring = line.Substring(0, indexOf);
                    descriptionLines.Add(substring);
                    phase++;
                    seenBodyEnd = true;
                }
                break;

            case ProcessingPhase.Files:
                if (string.IsNullOrEmpty(line))
                {
                    ReturnGitLogEntry();
                    return(false);
                }

                if (line.IndexOf("---GHUBODYEND---", StringComparison.InvariantCulture) >= 0)
                {
                    seenBodyEnd = true;
                    return(false);
                }

                var proc = new LineParser(line);

                string        file         = null;
                GitFileStatus status       = GitFileStatus.None;
                string        originalPath = null;

                if (proc.IsAtEnd)
                {
                    // there's no files on this commit, it's a new one!
                    ReturnGitLogEntry();
                    return(false);
                }
                else
                {
                    status = GitStatusEntry.ParseStatusMarker(proc.ReadChar());
                }

                if (status == GitFileStatus.None)
                {
                    HandleUnexpected(line);
                    return(false);
                }

                proc.ReadUntilWhitespace();
                if (status == GitFileStatus.Copied || status == GitFileStatus.Renamed)
                {
                    var files =
                        proc.ReadToEnd().Trim()
                        .Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries)
                        .Select(s => s.Trim())
                        .Select(s => s.Trim('"'))
                        .ToArray();

                    originalPath = files[0];
                    file         = files[1];
                }
                else
                {
                    file = proc.ReadToEnd().Trim().Trim('"');
                }

                changes.Add(gitObjectFactory.CreateGitStatusEntry(file, status, GitFileStatus.None, originalPath));

                break;

            default:
                HandleUnexpected(line);
                break;
            }
            return(false);
        }