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(); }
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); } }
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); }
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); } }
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); }
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); }
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; } }
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); } }
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(); }
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; } }
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; }
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; }
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; }