예제 #1
0
        private string ParseTagMessage(Command command, GitOutput output)
        {
            Assert.IsNotNull(output);

            output.ThrowOnBadReturnCode();
            var parser = new GitParser(output.Output);

            while (!parser.IsAtEndOfLine)
            {
                parser.SkipLine();
            }
            parser.SkipLine();
            if (parser.RemainingSymbols > 1)
            {
                var        message = parser.ReadStringUpTo(parser.Length - 1);
                const char c       = '�';
                if (message.ContainsAnyOf(c))
                {
                    output = _commandExecutor.ExecuteCommand(command, Encoding.Default, CommandExecutionFlags.None);
                    output.ThrowOnBadReturnCode();
                    parser = new GitParser(output.Output);
                    while (!parser.IsAtEndOfLine)
                    {
                        parser.SkipLine();
                    }
                    parser.SkipLine();
                    if (parser.RemainingSymbols > 1)
                    {
                        message = parser.ReadStringUpTo(parser.Length - 1);
                    }
                    else
                    {
                        message = string.Empty;
                    }
                }
                return(message);
            }
            else
            {
                return(string.Empty);
            }
        }
예제 #2
0
파일: GitProcess.cs 프로젝트: oqewok/gitter
        public static Version CheckVersion(string gitExe)
        {
            var stdErrReceiver = new AsyncTextReader();
            var stdOutReceiver = new AsyncTextReader();
            var executor       = new GitProcessExecutor(gitExe);
            var exitCode       = executor.Execute(new GitInput(new Command("--version")), stdOutReceiver, stdErrReceiver);
            var output         = new GitOutput(stdOutReceiver.GetText(), stdErrReceiver.GetText(), exitCode);

            output.ThrowOnBadReturnCode();
            var parser = new GitParser(output.Output);

            return(parser.ReadVersion());
        }
예제 #3
0
파일: OutputParser.cs 프로젝트: Kuzq/gitter
        public IList<RevisionGraphData> ParseRevisionGraph(GitOutput output)
        {
            Assert.IsNotNull(output);

            output.ThrowOnBadReturnCode();
            var parser = new GitParser(output.Output);
            var result = new List<RevisionGraphData>();
            while(!parser.IsAtEndOfString)
            {
                var sha1 = parser.ReadString(40, 1);
                int end = parser.FindNullOrEndOfString();
                int numParents = (end - parser.Position + 1) / 41;
                if(numParents == 0)
                {
                    parser.Position = end + 1;
                    result.Add(new RevisionGraphData(sha1, new string[0]));
                }
                else
                {
                    var parents = new List<string>(numParents);
                    for(int i = 0; i < numParents; ++i)
                    {
                        parents.Add(parser.ReadString(40, 1));
                    }
                    result.Add(new RevisionGraphData(sha1, parents));
                }
            }
            return result;
        }
예제 #4
0
파일: OutputParser.cs 프로젝트: Kuzq/gitter
        public Diff ParseRevisionDiff(GitOutput output)
        {
            Assert.IsNotNull(output);

            output.ThrowOnBadReturnCode();
            var parser = new DiffParser(output.Output);
            return parser.ReadDiff(DiffType.CommittedChanges);
        }
예제 #5
0
파일: OutputParser.cs 프로젝트: Kuzq/gitter
        public IList<RemoteData> ParseRemotesOutput(GitOutput output)
        {
            Assert.IsNotNull(output);

            output.ThrowOnBadReturnCode();
            var remotes = output.Output;
            int pos = 0;
            int l = remotes.Length;
            var res = new List<RemoteData>();
            while(pos < l)
            {
                var r = ParseRemote(remotes, ref pos);
                if(r != null)
                {
                    res.Add(r);
                }
            }
            return res;
        }
예제 #6
0
파일: OutputParser.cs 프로젝트: Kuzq/gitter
        public IList<RemoteReferenceData> ParseRemoteReferences(GitOutput output)
        {
            Assert.IsNotNull(output);

            output.ThrowOnBadReturnCode();

            var srefs = output.Output;
            var l = srefs.Length;
            int pos = 0;
            var refs = new List<RemoteReferenceData>();
            while(pos != -1 && pos < srefs.Length)
            {
                var rrinfo = ParseRemoteReference(srefs, ref pos);
                refs.Add(rrinfo);
            }
            return refs;
        }
예제 #7
0
파일: OutputParser.cs 프로젝트: Kuzq/gitter
        public IList<string> ParsePrunedBranches(GitOutput output)
        {
            Assert.IsNotNull(output);

            output.ThrowOnBadReturnCode();
            var res = new List<string>();
            var branches = output.Output;
            var pos = 0;
            var l = branches.Length;
            while(pos < l)
            {
                int end = branches.IndexOf('\n', pos);
                if(end == -1) end = l;

                if(StringUtility.CheckValue(branches, pos, " * [would prune] "))
                {
                    res.Add(branches.Substring(pos + 17, end - pos - 17));
                }

                pos = end + 1;
            }
            return res;
        }
예제 #8
0
파일: OutputParser.cs 프로젝트: Kuzq/gitter
        public ObjectCountData ParseObjectCountData(GitOutput output)
        {
            Assert.IsNotNull(output);

            output.ThrowOnBadReturnCode();
            int count = 0;
            int size = 0;
            int inPack = 0;
            int packs = 0;
            int sizePack = 0;
            int prunePackable = 0;
            int garbage = 0;
            var parser = new GitParser(output.Output);
            while(!parser.IsAtEndOfString)
            {
                if(parser.CheckValueAndSkip("count: "))
                {
                    int.TryParse(parser.ReadLine(), NumberStyles.Integer, CultureInfo.InvariantCulture, out count);
                }
                else if(parser.CheckValueAndSkip("size: "))
                {
                    int.TryParse(parser.ReadLine(), NumberStyles.Integer, CultureInfo.InvariantCulture, out size);
                }
                else if(parser.CheckValueAndSkip("in-pack: "))
                {
                    int.TryParse(parser.ReadLine(), NumberStyles.Integer, CultureInfo.InvariantCulture, out inPack);
                }
                else if(parser.CheckValueAndSkip("packs: "))
                {
                    int.TryParse(parser.ReadLine(), NumberStyles.Integer, CultureInfo.InvariantCulture, out packs);
                }
                else if(parser.CheckValueAndSkip("size-pack: "))
                {
                    int.TryParse(parser.ReadLine(), NumberStyles.Integer, CultureInfo.InvariantCulture, out sizePack);
                }
                else if(parser.CheckValueAndSkip("prune-packable: "))
                {
                    int.TryParse(parser.ReadLine(), NumberStyles.Integer, CultureInfo.InvariantCulture, out prunePackable);
                }
                else if(parser.CheckValueAndSkip("garbage: "))
                {
                    int.TryParse(parser.ReadLine(), NumberStyles.Integer, CultureInfo.InvariantCulture, out garbage);
                }
                else
                {
                    parser.SkipLine();
                }
            }
            return new ObjectCountData(count, size, inPack, packs, sizePack, prunePackable, garbage);
        }
예제 #9
0
파일: OutputParser.cs 프로젝트: Kuzq/gitter
        public IList<string> ParseFilesToRemove(GitOutput output)
        {
            Assert.IsNotNull(output);

            output.ThrowOnBadReturnCode();
            var files = output.Output;
            var l = files.Length;
            var pos = 0;
            var res = new List<string>();
            while(pos < l)
            {
                var eol = files.IndexOf('\n', pos);
                if(eol == -1) eol = files.Length;
                if(StringUtility.CheckValue(files, pos, "rm '"))
                {
                    res.Add(files.Substring(pos + 4, eol - pos - 5));
                }
                pos = eol + 1;
            }
            return res;
        }
예제 #10
0
파일: OutputParser.cs 프로젝트: Kuzq/gitter
        public IList<string> ParseFilesToClean(GitOutput output)
        {
            Assert.IsNotNull(output);

            output.ThrowOnBadReturnCode();
            var files = output.Output;
            var res = new List<string>();
            var parser = new GitParser(files);
            while(!parser.IsAtEndOfString)
            {
                if(parser.CheckValue("Would remove "))
                {
                    parser.Skip(13);
                    res.Add(parser.DecodeEscapedString(parser.FindNewLineOrEndOfString(), 1));
                }
                else
                {
                    parser.SkipLine();
                }
            }
            return res;
        }
예제 #11
0
파일: OutputParser.cs 프로젝트: Kuzq/gitter
        public BranchesData ParseBranches(QueryBranchesParameters parameters, GitOutput output)
        {
            Assert.IsNotNull(parameters);
            Assert.IsNotNull(output);

            output.ThrowOnBadReturnCode();
            var parser = new GitParser(output.Output);
            return parser.ParseBranches(parameters.Restriction, parameters.AllowFakeBranch);
        }
예제 #12
0
파일: OutputParser.cs 프로젝트: Kuzq/gitter
        public BlameFile ParseBlame(QueryBlameParameters parameters, GitOutput output)
        {
            Assert.IsNotNull(parameters);
            Assert.IsNotNull(output);

            output.ThrowOnBadReturnCode();
            var parser = new BlameParser(output.Output);
            return parser.ParseBlameFile(parameters.FileName);
        }
예제 #13
0
파일: OutputParser.cs 프로젝트: Kuzq/gitter
        public void HandleRevertResult(GitOutput output)
        {
            Assert.IsNotNull(output);

            if(output.Error != "Finished one revert.\n") // TODO: needs a better parser.
            {
                output.ThrowOnBadReturnCode();
            }
        }
예제 #14
0
파일: OutputParser.cs 프로젝트: Kuzq/gitter
        public IList<UserData> ParseUsers(GitOutput output)
        {
            Assert.IsNotNull(output);

            output.ThrowOnBadReturnCode();
            var res = new List<UserData>();
            var parser = new GitParser(output.Output);
            while(!parser.IsAtEndOfString)
            {
                var tab = parser.FindNoAdvance('\t');
                string commitsCountStr = parser.ReadStringUpTo(tab, 1);
                int commitsCount = int.Parse(commitsCountStr, NumberStyles.Integer, CultureInfo.InvariantCulture);
                var eol = parser.FindLfLineEnding();
                var emailSeparator = parser.String.LastIndexOf(" <", eol - 1, eol - tab - 1);
                string name = parser.ReadStringUpTo(emailSeparator, 2);
                string email = parser.ReadStringUpTo(eol - 1, 2);
                var userData = new UserData(name, email, commitsCount);
                res.Add(userData);
            }
            return res;
        }
예제 #15
0
파일: OutputParser.cs 프로젝트: Kuzq/gitter
        public RemoteData ParseSingleRemote(QueryRemoteParameters parameters, GitOutput output)
        {
            Assert.IsNotNull(parameters);
            Assert.IsNotNull(output);

            output.ThrowOnBadReturnCode();
            var info = output.Output;
            int pos = info.IndexOf('\n') + 1;
            int pos2 = info.IndexOf('\n', pos);
            string fetchUrl = info.Substring(pos + 13, pos2 - pos - 13);
            pos = pos2 + 1;
            pos = info.IndexOf('\n', pos);
            string pushUrl = info.Substring(pos + 13, pos2 - pos - 13);
            return new RemoteData(parameters.RemoteName, fetchUrl, pushUrl);
        }
예제 #16
0
파일: OutputParser.cs 프로젝트: Kuzq/gitter
        public IList<NoteData> ParseNotes(GitOutput output)
        {
            Assert.IsNotNull(output);

            output.ThrowOnBadReturnCode();
            var res = new List<NoteData>();
            var notes = output.Output;
            if(notes.Length > 81)
            {
                var parser = new GitParser(notes);
                while(!parser.IsAtEndOfString)
                {
                    var noteSHA1 = parser.ReadString(40, 1);
                    var objectSHA1 = parser.ReadString(40, 1);
                    res.Add(new NoteData(noteSHA1, objectSHA1, null));
                }
            }
            return res;
        }
예제 #17
0
파일: OutputParser.cs 프로젝트: Kuzq/gitter
        public IList<TreeContentData> ParseTreeContent(GitOutput output)
        {
            Assert.IsNotNull(output);

            output.ThrowOnBadReturnCode();
            var content = output.Output;
            int pos = 0;
            int l = content.Length;
            var res = new List<TreeContentData>();
            // <mode> SP <type> SP <object> SP <object size> TAB <file>
            while(pos < l)
            {
                var end = content.IndexOf('\0', pos);
                if(end == -1) end = l;

                int delimeter = content.IndexOf(' ', pos);
                int mode = int.Parse(content.Substring(pos, delimeter - pos), CultureInfo.InvariantCulture);
                pos = delimeter + 1;
                while(content[pos] == ' ')
                {
                    ++pos;
                }

                bool isTree		= StringUtility.CheckValue(content, pos, GitConstants.TreeObjectType);
                bool isBlob		= !isTree && StringUtility.CheckValue(content, pos, GitConstants.BlobObjectType);
                bool isCommit	= !isTree && !isBlob && StringUtility.CheckValue(content, pos, GitConstants.CommitObjectType);
                bool isTag		= !isTree && !isBlob && !isCommit && StringUtility.CheckValue(content, pos, GitConstants.TagObjectType);

                pos += 5;
                delimeter = content.IndexOf(' ', pos);
                var hash = content.Substring(pos, delimeter - pos);
                pos += 41;
                while(content[pos] == ' ')
                {
                    ++pos;
                }
                delimeter = content.IndexOf('\t', pos);
                long size = 0;
                if(isBlob)
                {
                    size = long.Parse(content.Substring(pos, delimeter - pos), CultureInfo.InvariantCulture);
                }
                pos = delimeter + 1;
                var name = content.Substring(pos, end - pos);
                if(isBlob)
                {
                    res.Add(new BlobData(hash, mode, name, size));
                }
                else if(isTree)
                {
                    res.Add(new TreeData(hash, mode, name));
                }
                else if(isCommit)
                {
                    res.Add(new TreeCommitData(hash, mode, name));
                }
                pos = end + 1;
            }
            return res;
        }
예제 #18
0
파일: GitProcess.cs 프로젝트: Kuzq/gitter
 public static Version CheckVersion(string gitExe)
 {
     var stdErrReceiver = new AsyncTextReader();
     var stdOutReceiver = new AsyncTextReader();
     var executor = new GitProcessExecutor(gitExe);
     var exitCode = executor.Execute(new GitInput(new Command("--version")), stdOutReceiver, stdErrReceiver);
     var output = new GitOutput(stdOutReceiver.GetText(), stdErrReceiver.GetText(), exitCode);
     output.ThrowOnBadReturnCode();
     var parser = new GitParser(output.Output);
     return parser.ReadVersion();
 }