예제 #1
0
        private static void ReadTree(Stream s, GitObject go, ObjectHeader header)
        {
            var sb = new StringBuilder();

            // The counter is increased inside the loop
            // with every read operation.
            for (int i = 0; i < header.Size;)
            {
                var leading = ReadLeadingBytes(s);
                sb.Append(leading);
                sb.Append(' ');
                i += 7;

                var filename = ReadFileName(s);
                sb.Append(filename);
                sb.Append(' ');
                i += filename.Length + 1;

                var hash = ReadHash(s);
                sb.AppendLine(hash);
                i += 20;

                go.AddReference(hash, filename);
            }

            go.Body = sb.ToString();
        }
예제 #2
0
        private static void ReadPackInfo(Stream s, GitObject go)
        {
            using (var sr = new StreamReader(s))
            {
                go.Body = sr.ReadToEnd();
            }

            var packs = new Regex(@"P (?<id>.*)");

            foreach (Match pack in packs.Matches(go.Body))
            {
                go.AddReference(pack.Groups["id"].Value);
            }
        }
예제 #3
0
        private static GitObject ReadObject(FileInfo fi, ref Stream s)
        {
            s = new Ionic.Zlib.ZlibStream(s, Ionic.Zlib.CompressionMode.Decompress);

            var go     = new GitObject();
            var header = ReadHeader(s);

            go.ObjectType = header.Type;

            ReadBody(s, go, header);
            go.Id = fi.Directory.Name + fi.Name;

            return(go);
        }
예제 #4
0
 private static GitObject ReadRef(FileInfo fi, Stream s)
 {
     using (var sr = new StreamReader(s))
     {
         var go = new GitObject
         {
             Id         = fi.Name,
             ObjectType = ObjectType.Branch,
             Body       = sr.ReadToEnd().Trim()
         };
         go.AddReference(go.Body);
         return(go);
     }
 }
예제 #5
0
        private static GitObject ReadInfo(FileInfo fi, Stream s)
        {
            GitObject result = new GitObject
            {
                Id         = fi.Name,
                ObjectType = ObjectType.Info
            };

            if (fi.Name == "packs")
            {
                ReadPackInfo(s, result);
            }

            return(result);
        }
예제 #6
0
        private static GitObject ReadPack(FileInfo fi)
        {
            var go = new GitObject
            {
                Id         = fi.Name,
                ObjectType = ObjectType.Pack
            };

            if (fi.Extension == ".idx")
            {
                go.AddReference(Path.ChangeExtension(fi.Name, ".pack"));
            }

            return(go);
        }
예제 #7
0
        private static void ReadBody(Stream s, GitObject go, ObjectHeader header)
        {
            switch (header.Type)
            {
            case ObjectType.Tree:
                ReadTree(s, go, header);
                break;

            case ObjectType.Commit:
                ReadCommit(s, go);
                break;

            default:
                go.Body = ReadFile(s);
                break;
            }
        }
예제 #8
0
        private static void ReadCommit(Stream s, GitObject go)
        {
            go.Body = ReadFile(s);

            Regex parents = new Regex(@"parent (?<id>\w*)");

            foreach (Match match in parents.Matches(go.Body))
            {
                go.AddReference(match.Groups["id"].Value);
            }

            var tree = Regex.Match(go.Body, @"tree (?<id>\w*)");

            if (tree.Success)
            {
                go.AddReference(tree.Groups["id"].Value);
            }
        }
예제 #9
0
        private static void ReadTree(Stream s, GitObject go, ObjectHeader header)
        {
            var sb = new StringBuilder();

            // The counter is increased inside the loop
            // with every read operation.
            for (int i = 0; i < header.Size; )
            {
                var leading = ReadLeadingBytes(s);
                sb.Append(leading);
                sb.Append(' ');
                i += 7;

                var filename = ReadFileName(s);
                sb.Append(filename);
                sb.Append(' ');
                i += filename.Length + 1;

                var hash = ReadHash(s);
                sb.AppendLine(hash);
                i += 20;

                go.AddReference(hash, filename);
            }

            go.Body = sb.ToString();
        }
예제 #10
0
        private static void ReadPackInfo(Stream s, GitObject go)
        {
            using (var sr = new StreamReader(s))
            {
                go.Body = sr.ReadToEnd();
            }

            var packs = new Regex(@"P (?<id>.*)");
            foreach (Match pack in packs.Matches(go.Body))
            {
                go.AddReference(pack.Groups["id"].Value);
            }
        }
예제 #11
0
 private static GitObject ReadRef(FileInfo fi, Stream s)
 {
     using (var sr = new StreamReader(s))
     {
         var go = new GitObject
         {
             Id = fi.Name,
             ObjectType = ObjectType.Branch,
             Body = sr.ReadToEnd().Trim()
         };
         go.AddReference(go.Body);
         return go;
     }
 }
예제 #12
0
        private static GitObject ReadPack(FileInfo fi)
        {
            var go = new GitObject
            {
                Id = fi.Name,
                ObjectType = ObjectType.Pack
            };
            if (fi.Extension == ".idx")
            {
                go.AddReference(Path.ChangeExtension(fi.Name, ".pack"));
            }

            return go;
        }
예제 #13
0
        private static GitObject ReadObject(FileInfo fi, ref Stream s)
        {
            s = new Ionic.Zlib.ZlibStream(s, Ionic.Zlib.CompressionMode.Decompress);

            var go = new GitObject();
            var header = ReadHeader(s);
            go.ObjectType = header.Type;

            ReadBody(s, go, header);
            go.Id = fi.Directory.Name + fi.Name;

            return go;
        }
예제 #14
0
        private static GitObject ReadInfo(FileInfo fi, Stream s)
        {
            GitObject result = new GitObject
            {
                Id = fi.Name,
                ObjectType = ObjectType.Info
            };
            if (fi.Name == "packs")
            {
                ReadPackInfo(s, result);
            }

            return result;
        }
예제 #15
0
        private static void ReadCommit(Stream s, GitObject go)
        {
            go.Body = ReadFile(s);

            Regex parents = new Regex(@"parent (?<id>\w*)");
            foreach (Match match in parents.Matches(go.Body))
            {
                go.AddReference(match.Groups["id"].Value);
            }

            var tree = Regex.Match(go.Body, @"tree (?<id>\w*)");
            if (tree.Success)
            {
                go.AddReference(tree.Groups["id"].Value);
            }
        }
예제 #16
0
 private static void ReadBody(Stream s, GitObject go, ObjectHeader header)
 {
     switch (header.Type)
     {
         case ObjectType.Tree:
             ReadTree(s, go, header);
             break;
         case ObjectType.Commit:
             ReadCommit(s, go);
             break;
         default:
             go.Body = ReadFile(s);
             break;
     }
 }