示例#1
0
        private static IList <ReflogRecordData> ParseResult1(GitOutput output, Dictionary <Hash, RevisionData> cache)
        {
            if (output.Output.Length < 40)
            {
                return(new ReflogRecordData[0]);
            }
            var parser = new GitParser(output.Output);
            int index  = 0;
            var list   = new List <ReflogRecordData>();

            while (!parser.IsAtEndOfString)
            {
                var selector = parser.ReadLine();
                if (selector.Length == 0)
                {
                    break;
                }
                var          message = parser.ReadLine();
                var          sha1    = parser.ReadHash(skip: 1);
                RevisionData rev;
                if (!cache.TryGetValue(sha1, out rev))
                {
                    rev = new RevisionData(sha1);
                    cache.Add(sha1, rev);
                }
                parser.ParseRevisionData(rev, cache);
                list.Add(new ReflogRecordData(index++, message, rev));
            }
            return(list);
        }
示例#2
0
        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
        private static IList <StashedStateData> ParseResult1(GitOutput output, Dictionary <Hash, RevisionData> cache)
        {
            int index  = 0;
            var parser = new GitParser(output.Output);
            var res    = new List <StashedStateData>();

            while (!parser.IsAtEndOfString)
            {
                var sha1 = new Hash(parser.String, parser.Position);
                var rev  = new RevisionData(sha1);
                parser.Skip(41);
                parser.ParseRevisionData(rev, cache);
                var state = new StashedStateData(index, rev);
                res.Add(state);
                ++index;
            }
            return(res);
        }
示例#4
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);
            }
        }
示例#5
0
        public void HandleCheckoutResult(CheckoutParameters parameters, GitOutput output)
        {
            Assert.IsNotNull(parameters);
            Assert.IsNotNull(output);

            if(output.ExitCode != 0)
            {
                if(IsUnknownRevisionError(output.Error, parameters.Revision))
                {
                    throw new UnknownRevisionException(parameters.Revision);
                }
                if(IsRefrerenceIsNotATreeError(output.Error, parameters.Revision))
                {
                    throw new UnknownRevisionException(parameters.Revision);
                }
                if(IsUnknownPathspecError(output.Error, parameters.Revision))
                {
                    throw new UnknownRevisionException(parameters.Revision);
                }
                if(!parameters.Force)
                {
                    string fileName;
                    if(IsUntrackedFileWouldBeOverwrittenError(output.Error, out fileName))
                    {
                        throw new UntrackedFileWouldBeOverwrittenException(fileName);
                    }
                    if(IsHaveLocalChangesError(output.Error, out fileName))
                    {
                        throw new HaveLocalChangesException(fileName);
                    }
                    if(IsHaveConflictsError(output.Error))
                    {
                        throw new HaveConflictsException();
                    }
                }
                output.Throw();
            }
        }
示例#6
0
        public ConfigParameterData ParseQueryConfigParameterResult(QueryConfigParameterParameters parameters, GitOutput output)
        {
            Assert.IsNotNull(parameters);
            Assert.IsNotNull(output);

            if(output.ExitCode == 0)
            {
                var value = output.Output.TrimEnd('\n');
                return new ConfigParameterData(parameters.ParameterName, value, parameters.ConfigFile, parameters.FileName);
            }
            else
            {
                return null;
            }
        }
示例#7
0
        public IList<ConfigParameterData> ParseQueryConfigResults(QueryConfigParameters parameters, GitOutput output)
        {
            Assert.IsNotNull(parameters);
            Assert.IsNotNull(output);

            if(output.ExitCode != 0 && parameters.ConfigFile != ConfigFile.Other)
            {
                return new ConfigParameterData[0];
            }
            HandleConfigResults(output);
            var res = new List<ConfigParameterData>();
            var parser = new GitParser(output.Output);
            while(!parser.IsAtEndOfString)
            {
                var name = parser.ReadStringUpTo(parser.FindNewLineOrEndOfString(), 1);
                var value = parser.ReadStringUpTo(parser.FindNullOrEndOfString(), 1);
                if(parameters.ConfigFile != ConfigFile.Other)
                {
                    res.Add(new ConfigParameterData(name, value, parameters.ConfigFile));
                }
                else
                {
                    res.Add(new ConfigParameterData(name, value, parameters.FileName));
                }
            }
            return res;
        }
示例#8
0
        public IList<TagData> ParseTags(GitOutput output)
        {
            Assert.IsNotNull(output);

            if(output.ExitCode != 0)
            {
                return new TagData[0];
            }
            var tags = output.Output;
            int pos = 0;
            int l = tags.Length;
            var res = new List<TagData>();
            while(pos < l)
            {
                var tag = TryParseTag(tags, ref pos);
                if(tag != null) res.Add(tag);
            }
            return res;
        }
示例#9
0
        public void HandleStashPopResult(GitOutput output)
        {
            Assert.IsNotNull(output);

            if(output.ExitCode != 0)
            {
                if(IsNothingToApplyError(output.Error))
                {
                    throw new StashIsEmptyException(output.Error);
                }
                if(IsCannotApplyToDirtyWorkingTreeError(output.Error))
                {
                    throw new DirtyWorkingDirectoryException();
                }
                output.Throw();
            }
        }
示例#10
0
        public Diff ParseRevisionDiff(GitOutput output)
        {
            Assert.IsNotNull(output);

            output.ThrowOnBadReturnCode();
            var parser = new DiffParser(output.Output);
            return parser.ReadDiff(DiffType.CommittedChanges);
        }
示例#11
0
        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
        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;
        }
示例#13
0
        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;
        }
示例#14
0
        public IList<TreeFileData> ParseFilesToAdd(GitOutput output)
        {
            Assert.IsNotNull(output);

            if(output.ExitCode != 0 && output.ExitCode != 128)
            {
                return new List<TreeFileData>(0);
            }
            var files = output.Output;
            var l = files.Length;
            var pos = 0;
            var res = new List<TreeFileData>();
            while(pos < l)
            {
                int eol = files.IndexOf('\n', pos);
                if(eol == -1) eol = l;
                var status = FileStatus.Cached;
                string filePath = null;
                switch(files[pos])
                {
                    case 'a':
                        status = FileStatus.Added;
                        filePath = files.Substring(pos + 5, eol - pos - 6);
                        break;
                    case 'r':
                        status = FileStatus.Removed;
                        filePath = files.Substring(pos + 8, eol - pos - 9);
                        break;
                    case 'T':
                        eol = l;
                        break;
                }
                if(filePath != null)
                {
                    var slashPos = filePath.LastIndexOf('/');
                    var fileName = slashPos != -1 ?
                        filePath.Substring(slashPos + 1) :
                        filePath;
                    var file = new TreeFileData(
                        filePath, status, ConflictType.None, StagedStatus.Unstaged);
                    res.Add(file);
                    pos = eol + 1;
                }
                else
                {
                    pos = eol + 1;
                }
            }
            return res;
        }
示例#15
0
        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;
        }
示例#16
0
        public Diff ParseDiff(QueryDiffParameters parameters, GitOutput output)
        {
            Assert.IsNotNull(parameters);
            Assert.IsNotNull(output);

            if(output.ExitCode != 0)
            {
                if(parameters.Cached && IsNoHEADCommitToCompareWithError(output.Error))
                {
                    throw new RepositoryIsEmptyException(output.Error);
                }
                output.Throw();
            }
            var parser = new DiffParser(output.Output);
            var diffType = GetDiffType(parameters);
            return parser.ReadDiff(diffType);
        }
示例#17
0
        public string ParseDescribeResult(DescribeParameters parameters, GitOutput output)
        {
            Assert.IsNotNull(parameters);
            Assert.IsNotNull(output);

            if(output.ExitCode != 0)
            {
                if(parameters.Revision != null)
                {
                    if(IsUnknownRevisionError(output.Error, parameters.Revision))
                    {
                        throw new UnknownRevisionException(parameters.Revision);
                    }
                }
                output.Throw();
            }
            if(string.IsNullOrWhiteSpace(output.Output))
            {
                return null;
            }
            return output.Output;
        }
示例#18
0
        public RevisionData ParseDereferenceOutput(DereferenceParameters parameters, GitOutput output)
        {
            Assert.IsNotNull(parameters);
            Assert.IsNotNull(output);

            if(output.ExitCode != 0)
            {
                if(IsUnknownRevisionError(output.Error, parameters.Reference))
                {
                    throw new UnknownRevisionException(parameters.Reference);
                }
                if(IsBadObjectError(output.Error, parameters.Reference))
                {
                    throw new UnknownRevisionException(parameters.Reference);
                }
                output.Throw();
            }

            if(parameters.LoadRevisionData)
            {
                var parser = new GitParser(output.Output);
                return parser.ParseRevision();
            }
            else
            {
                var hash = new Hash(output.Output);
                return new RevisionData(hash);
            }
        }
示例#19
0
        public RevisionData ParseQueryStashTopOutput(QueryStashTopParameters parameters, GitOutput output)
        {
            Assert.IsNotNull(parameters);
            Assert.IsNotNull(output);

            if(parameters.LoadCommitInfo)
            {
                return new GitParser(output.Output).ParseRevision();
            }
            else
            {
                if(output.ExitCode != 0 || output.Output.Length < 40)
                {
                    return null;
                }

                var hash = new Hash(output.Output);
                return new RevisionData(hash);
            }
        }
示例#20
0
        public BranchData ParseSingleBranch(QueryBranchParameters parameters, GitOutput output)
        {
            Assert.IsNotNull(parameters);
            Assert.IsNotNull(output);

            if(output.ExitCode == 0)
            {
                var hash = new Hash(output.Output);
                return new BranchData(parameters.BranchName, hash, false, parameters.IsRemote, false);
            }
            else
            {
                return null;
            }
        }
示例#21
0
        public ReferencesData ParseReferences(QueryReferencesParameters parameters, GitOutput output)
        {
            Assert.IsNotNull(parameters);
            Assert.IsNotNull(output);

            var refTypes = parameters.ReferenceTypes;

            bool needHeads		= (refTypes & ReferenceType.LocalBranch) == ReferenceType.LocalBranch;
            bool needRemotes	= (refTypes & ReferenceType.RemoteBranch) == ReferenceType.RemoteBranch;
            bool needTags		= (refTypes & ReferenceType.Tag) == ReferenceType.Tag;
            bool needStash		= (refTypes & ReferenceType.Stash) == ReferenceType.Stash;

            var heads	= needHeads   ? new List<BranchData>() : null;
            var remotes	= needRemotes ? new List<BranchData>() : null;
            var tags	= needTags    ? new List<TagData>()    : null;
            RevisionData stash = null;

            bool encounteredRemoteBranch = false;
            bool encounteredStash = false;
            bool encounteredTag = false;

            var refs = output.Output;
            int pos = 0;
            int l = refs.Length;
            while(pos < l)
            {
                var hash = new Hash(refs, pos);
                pos += 41;
                var end = refs.IndexOf('\n', pos);
                if(end == -1) end = l;

                if(!encounteredRemoteBranch && StringUtility.CheckValue(refs, pos, GitConstants.LocalBranchPrefix))
                {
                    if(needHeads)
                    {
                        pos += GitConstants.LocalBranchPrefix.Length;
                        var name = refs.Substring(pos, end - pos);
                        var branch = new BranchData(name, hash, false, false, false);
                        heads.Add(branch);
                    }
                }
                else if(!encounteredStash && StringUtility.CheckValue(refs, pos, GitConstants.RemoteBranchPrefix))
                {
                    encounteredRemoteBranch = true;
                    if(needRemotes)
                    {
                        pos += GitConstants.RemoteBranchPrefix.Length;
                        var name = refs.Substring(pos, end - pos);
                        if(!name.EndsWith("/HEAD"))
                        {
                            var branch = new BranchData(name, hash, false, true, false);
                            remotes.Add(branch);
                        }
                    }
                }
                else if(!encounteredTag && !encounteredStash && StringUtility.CheckValue(refs, pos, GitConstants.StashFullName))
                {
                    encounteredRemoteBranch = true;
                    encounteredStash = true;
                    if(needStash)
                    {
                        stash = new RevisionData(hash);
                    }
                }
                else if(StringUtility.CheckValue(refs, pos, GitConstants.TagPrefix))
                {
                    encounteredRemoteBranch = true;
                    encounteredStash = true;
                    encounteredTag = true;
                    if(needTags)
                    {
                        pos += GitConstants.TagPrefix.Length;
                        var name = refs.Substring(pos, end - pos);
                        var type = TagType.Lightweight;
                        if(end < l - 1)
                        {
                            int s2 = end + 1;
                            int pos2 = s2 + 41 + GitConstants.TagPrefix.Length;
                            var end2 = refs.IndexOf('\n', pos2);
                            if(end2 == -1) end2 = l;
                            if(end2 - pos2 == end - pos + 3)
                            {
                                if(StringUtility.CheckValue(refs, pos2, name) && StringUtility.CheckValue(refs, pos2 + name.Length, GitConstants.DereferencedTagPostfix))
                                {
                                    type = TagType.Annotated;
                                    hash = new Hash(refs, s2);
                                    end = end2;
                                }
                            }
                        }
                        var tag = new TagData(name, hash, type);
                        tags.Add(tag);
                    }
                    else break;
                }
                pos = end + 1;
            }
            return new ReferencesData(heads, remotes, tags, stash);
        }
示例#22
0
        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);
        }
示例#23
0
        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;
        }
示例#24
0
        public bool ParseStashSaveResult(GitOutput output)
        {
            Assert.IsNotNull(output);

            if(output.ExitCode != 0)
            {
                if(IsCantStashToEmptyRepositoryError(output.Error))
                {
                    throw new RepositoryIsEmptyException();
                }
                output.Throw();
            }
            return output.Output != "No local changes to save\n";
        }
示例#25
0
        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;
        }
示例#26
0
        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);
        }
示例#27
0
        public void HandleCherryPickResult(GitOutput output)
        {
            Assert.IsNotNull(output);

            if(output.ExitCode != 0)
            {
                string fileName;
                if(IsAutomaticCherryPickFailedError(output.Error))
                {
                    throw new AutomaticCherryPickFailedException();
                }
                if(IsCherryPickIsEmptyError(output.Error))
                {
                    throw new CherryPickIsEmptyException(output.Error);
                }
                if(IsHaveLocalChangesMergeError(output.Error, out fileName))
                {
                    throw new HaveLocalChangesException(fileName);
                }
                if(IsCherryPickNotPossibleBecauseOfMergeCommit(output.Error))
                {
                    throw new CommitIsMergeException();
                }
                if(IsCherryPickNotPossibleBecauseOfConflictsError(output.Error))
                {
                    throw new HaveConflictsException();
                }
                output.Throw();
            }
        }
示例#28
0
        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;
        }
示例#29
0
        public RevisionData ParseSingleRevision(QueryRevisionParameters parameters, GitOutput output)
        {
            Assert.IsNotNull(parameters);
            Assert.IsNotNull(output);

            if(output.ExitCode != 0)
            {
                var revName = parameters.SHA1.ToString();
                if(IsUnknownRevisionError(output.Error, revName))
                {
                    throw new UnknownRevisionException(revName);
                }
                output.Throw();
            }
            var parser = new GitParser(output.Output);
            var rev = new RevisionData(parameters.SHA1);
            parser.ParseRevisionData(rev, null);
            return rev;
        }
示例#30
0
        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);
        }
示例#31
0
        public TagData ParseTag(QueryTagParameters parameters, GitOutput output)
        {
            Assert.IsNotNull(parameters);
            Assert.IsNotNull(output);

            var tag = output.Output;
            if(output.ExitCode == 0 && tag.Length >= 40)
            {
                Hash hash;
                TagType type;
                if(tag.Length >= 81)
                {
                    hash = new Hash(output.Output, 41);
                    type = TagType.Annotated;
                }
                else
                {
                    hash = new Hash(output.Output);
                    type = TagType.Lightweight;
                }
                return new TagData(parameters.TagName, hash, type);
            }
            else
            {
                return null;
            }
        }
示例#32
0
 public string ParseObjects(GitOutput output)
 {
     return output.Output;
 }
示例#33
0
        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;
        }
示例#34
0
        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;
        }