Inheritance: System.IO.BinaryReader
コード例 #1
0
ファイル: Index.cs プロジェクト: schacon/dotgit
        internal Index(Repository repo)
        {
            Repo = repo;

            using(GitObjectReader stream = new GitObjectReader(File.OpenRead(Path.Combine(Repo.GitDir.FullName, "index"))))
            {
                string header = stream.ReadBytes(4).GetString();

                if (header != HEADER)
                    throw new ParseException("Could not parse Index file. Expected HEADER: '{0}', got: '{1}'".FormatWith(HEADER, header));

                Version = stream.ReadBytes(4).Sum(b => (int)b);

                if (!VERSIONS.Contains(Version))
                    throw new ParseException("Unknown version number {0}. Needs to be one of: {1}".FormatWith(Version, String.Join(",", VERSIONS.Select(i => i.ToString()).ToArray())));

                NumberOfEntries = stream.ReadBytes(4).Sum(b => (int)b);

                Entries = new IndexEntryCollection(NumberOfEntries);

                for (int i = 0; i < NumberOfEntries; i++)
                {
                    Entries.Add(new IndexEntry(stream));
                }

                string indexSHA = stream.ReadToEnd().ToSHAString();
            }
        }
コード例 #2
0
        /// <summary>
        /// Gets called be the Children getter for lazy loading
        /// </summary>
        private void LoadChildren()
        {
            _children = new TreeNodeCollection();

            try
            {
                using (GitObjectReader stream = new GitObjectReader(_childrenRaw))
                {
                    while (!stream.IsEndOfStream)
                    {
                        string mode, path, sha;

                        mode = stream.ReadWord().GetString();
                        path = stream.ReadToNull().GetString();
                        sha  = Sha.Decode(stream.ReadBytes(20));

                        TreeNode child = Repo.Storage.GetObject <TreeNode>(sha);
                        child.Path   = path;
                        child.Mode   = FileMode.FromBits(int.Parse(mode));
                        child.Parent = this;

                        _children.Add(child);
                    }
                }
            }
            catch (Exception)
            {
                // Reset _children field, otherwise the object would be in an invalid state
                _children = null;

                throw;
            }
        }
コード例 #3
0
        /// <summary>
        /// Loads the tree from the GitObjectReader. The child objects themselves will be lazy loaded
        /// </summary>
        /// <param name="input">A reader with inflated tree contents</param>
        public override void Deserialize(GitObjectReader input)
        {
            //string sha = Sha.Compute(input);
            //if (SHA != sha)
            //  throw new ShaMismatchException(SHA, sha);

            _childrenRaw = input.ReadToEnd();
        }
コード例 #4
0
        /// <summary>
        /// Loads the commit from the GitObjectReader
        /// </summary>
        /// <param name="input">A reader with inflated commit contents</param>
        public override void Deserialize(GitObjectReader input)
        {
            //Skip 'tree' at beginning of line and read tree sha
            input.ReadWord();
            _treeSha = input.ReadLine().GetString();


            // Check for 'parent' at beginning of line
            _parentShas = new List <string>();
            string parentOrAuthor = input.ReadWord().GetString();

            // TODO: Make recursive
            while (parentOrAuthor == "parent")
            {
                _parentShas.Add(input.GetString(40));
                input.Position++;

                // Skip 'author'
                parentOrAuthor = input.ReadWord().GetString();
            }

            // Author
            string authorLine = input.ReadLine().GetString();

            AuthoredDate = Utility.StripDate(authorLine, out authorLine);
            Author       = Contributer.Parse(authorLine);

            // Committer
            input.ReadWord();
            string committerLine = input.ReadLine().GetString();

            CommittedDate = Utility.StripDate(committerLine, out committerLine);
            Committer     = Contributer.Parse(committerLine);

            //Skip extra '\n'
            input.Position++;
            Message = input.ReadToEnd().GetString().TrimEnd();
        }
コード例 #5
0
ファイル: Blob.cs プロジェクト: schacon/dotgit
 public override void Deserialize(GitObjectReader stream)
 {
     Content = stream.ReadToEnd();
 }
コード例 #6
0
ファイル: IndexTime.cs プロジェクト: schacon/dotgit
 internal IndexTime(GitObjectReader input)
 {
     Seconds = input.ReadBytes(4).ToInt();
     NanoSeconds = input.ReadBytes(4).ToInt();
 }
コード例 #7
0
ファイル: Blob.cs プロジェクト: optionalg/dotgit
 public override void Deserialize(GitObjectReader stream)
 {
     Content = stream.ReadToEnd();
 }
コード例 #8
0
ファイル: GitObject.cs プロジェクト: optionalg/dotgit
 public abstract void Deserialize(GitObjectReader input);