private void ReadSignature(GitObjectStream content) { content.Position = content.Length - 20; Sha1Signature = content.ReadToEnd().ToHexString(); content.Rewind(); }
public void Load(GitObjectStream content) { ReadSignature(content); Header = new IndexHeader(); Header.Load(content); while (content.Position < content.Length - 20) { var entry = new IndexEntry(); entry.Load(content); Entries.Add(entry); } }
public GitObject CreateFromContent(GitObjectStream content) { string type = ReadHeading(content); GitObject obj; if (type == "commit") obj = new Commit(); else if (type == "tree") obj = new Tree(); else if (type == "blob") obj = new Blob(); else throw new NotImplementedException("Support for file type is not implemented."); content.Rewind(); obj.Load(content); return obj; }
public GitObject Find(string sha1Id) { if (sha1Id.Length != 40) throw new ArgumentException("Invalid SHA1 provided.", "sha1Id"); string dirName = sha1Id.Substring(0, 2); string dirPath = Path.Combine(objectDir, dirName); if (!Directory.Exists(dirPath)) throw new InvalidOperationException("Could not find SHA1 directory '" + dirName + "'."); string filename = sha1Id.Substring(2); string fullPath = Path.Combine(dirPath, filename); if (!File.Exists(fullPath)) // should look in packs here? throw new InvalidOperationException("Could not find SHA1 file with path '" + fullPath + "'."); var uncompressedContent = zip.Decompress(fullPath); var stream = new GitObjectStream(uncompressedContent); return objectFactory.CreateFromContent(stream); }
private string ReadHeading(GitObjectStream content) { byte[] word = content.ReadWord(); return new System.Text.ASCIIEncoding().GetString(word); }
public void CreateStream() { CommitContent = "commit 187\0tree f37a9edbaa5601df27dcc24df5fcff752314b3ec\nauthor James Gregory <*****@*****.**> 1225463078 +0000\ncommitter James Gregory <*****@*****.**> 1225463078 +0000\n\nAdded first file\n" .ToGitObjectStream(); }
public void Load(GitObjectStream content) { Created = new IndexTime(); Created.Load(content); Modified = new IndexTime(); Modified.Load(content); var dev = content.ReadBytes(4); var ino = content.ReadBytes(4); var mode = content.ReadBytes(4); var uid = content.ReadBytes(4); var gid = content.ReadBytes(4); var size = content.ReadBytes(4); Signature = content.ReadBytes(20).ToHexString(); var flags = content.ReadBytes(2); Name = content.ReadToNull().ToAsciiString(); content.ReadToNextNonNull(); }
public void Load(GitObjectStream content) { var signatureBytes = content.ReadBytes(SignatureSize); var versionBytes = content.ReadBytes(VersionSize); var entriesBytes = content.ReadBytes(EntriesSize); Signature = signatureBytes.ToAsciiString(); Version = versionBytes.ToInt32(); Entries = entriesBytes.ToInt32(); }
public void CreateStream() { Stream = new GitObjectStream(content); }
public void CreateStream() { FakeCommitContent = "commit 1234\0Body" .ToGitObjectStream(); }