public virtual void TestCreateFileHeader_Add() { ObjectId adId = Blob("a\nd\n"); DiffEntry ent = DiffEntry.Add("FOO", adId); FileHeader fh = df.ToFileHeader(ent); string diffHeader = "diff --git a/FOO b/FOO\n" + "new file mode " + REGULAR_FILE + "\n" + "index " + ObjectId.ZeroId.Abbreviate(8).Name + ".." + adId.Abbreviate( 8).Name + "\n" + "--- /dev/null\n" + "+++ b/FOO\n"; // // // NUnit.Framework.Assert.AreEqual(diffHeader, RawParseUtils.Decode(fh.GetBuffer())); NUnit.Framework.Assert.AreEqual(0, fh.GetStartOffset()); NUnit.Framework.Assert.AreEqual(fh.GetBuffer().Length, fh.GetEndOffset()); NUnit.Framework.Assert.AreEqual(FileHeader.PatchType.UNIFIED, fh.GetPatchType()); NUnit.Framework.Assert.AreEqual(1, fh.GetHunks().Count); HunkHeader hh = fh.GetHunks()[0]; NUnit.Framework.Assert.AreEqual(1, hh.ToEditList().Count); EditList el = hh.ToEditList(); NUnit.Framework.Assert.AreEqual(1, el.Count); Edit e = el[0]; NUnit.Framework.Assert.AreEqual(0, e.GetBeginA()); NUnit.Framework.Assert.AreEqual(0, e.GetEndA()); NUnit.Framework.Assert.AreEqual(0, e.GetBeginB()); NUnit.Framework.Assert.AreEqual(2, e.GetEndB()); NUnit.Framework.Assert.AreEqual(Edit.Type.INSERT, e.GetType()); }
private string ParseName(string expect, int ptr, int end) { if (ptr == end) { return(expect); } string r; if (buf[ptr] == '"') { // New style GNU diff format // r = QuotedString.GIT_PATH.Dequote(buf, ptr, end - 1); } else { // Older style GNU diff format, an optional tab ends the name. // int tab = end; while (ptr < tab && buf[tab - 1] != '\t') { tab--; } if (ptr == tab) { tab = end; } r = RawParseUtils.Decode(Constants.CHARSET, buf, ptr, tab - 1); } if (r.Equals(DEV_NULL)) { r = DEV_NULL; } return(r); }
internal Entry(byte[] raw, int pos) { oldId = ObjectId.FromString(raw, pos); pos += Constants.OBJECT_ID_STRING_LENGTH; if (raw[pos++] != ' ') { throw new ArgumentException(JGitText.Get().rawLogMessageDoesNotParseAsLogEntry); } newId = ObjectId.FromString(raw, pos); pos += Constants.OBJECT_ID_STRING_LENGTH; if (raw[pos++] != ' ') { throw new ArgumentException(JGitText.Get().rawLogMessageDoesNotParseAsLogEntry); } who = RawParseUtils.ParsePersonIdentOnly(raw, pos); int p0 = RawParseUtils.Next(raw, pos, '\t'); // personident has no // \t if (p0 == -1) { throw new ArgumentException(JGitText.Get().rawLogMessageDoesNotParseAsLogEntry); } int p1 = RawParseUtils.NextLF(raw, p0); if (p1 == -1) { throw new ArgumentException(JGitText.Get().rawLogMessageDoesNotParseAsLogEntry); } comment = RawParseUtils.Decode(raw, p0, p1 - 1); }
/// <exception cref="System.IO.IOException"></exception> private void ReadSmartHeaders(InputStream @in, string service) { // A smart reply will have a '#' after the first 4 bytes, but // a dumb reply cannot contain a '#' until after byte 41. Do a // quick check to make sure its a smart reply before we parse // as a pkt-line stream. // byte[] magic = new byte[5]; IOUtil.ReadFully(@in, magic, 0, magic.Length); if (magic[4] != '#') { throw new TransportException(uri, MessageFormat.Format(JGitText.Get().expectedPktLineWithService , RawParseUtils.Decode(magic))); } PacketLineIn pckIn = new PacketLineIn(new UnionInputStream(new ByteArrayInputStream (magic), @in)); string exp = "# service=" + service; //$NON-NLS-1$ string act = pckIn.ReadString(); if (!exp.Equals(act)) { throw new TransportException(uri, MessageFormat.Format(JGitText.Get().expectedGot , exp, act)); } while (pckIn.ReadString() != PacketLineIn.END) { } }
internal ReflogEntry(byte[] raw, int pos) { oldId = ObjectId.FromString(raw, pos); pos += Constants.OBJECT_ID_STRING_LENGTH; if (raw[pos++] != ' ') { throw new ArgumentException(JGitText.Get().rawLogMessageDoesNotParseAsLogEntry); } newId = ObjectId.FromString(raw, pos); pos += Constants.OBJECT_ID_STRING_LENGTH; if (raw[pos++] != ' ') { throw new ArgumentException(JGitText.Get().rawLogMessageDoesNotParseAsLogEntry); } who = RawParseUtils.ParsePersonIdentOnly(raw, pos); int p0 = RawParseUtils.Next(raw, pos, '\t'); if (p0 >= raw.Length) { comment = string.Empty; } else { // personident has no \t, no comment present int p1 = RawParseUtils.NextLF(raw, p0); comment = p1 > p0?RawParseUtils.Decode(raw, p0, p1 - 1) : string.Empty; } }
public virtual void TestCreateFileHeader_Modify() { ObjectId adId = Blob("a\nd\n"); ObjectId abcdId = Blob("a\nb\nc\nd\n"); string diffHeader = MakeDiffHeader(PATH_A, PATH_A, adId, abcdId); DiffEntry ad = DiffEntry.Delete(PATH_A, adId); DiffEntry abcd = DiffEntry.Add(PATH_A, abcdId); DiffEntry mod = DiffEntry.Pair(DiffEntry.ChangeType.MODIFY, ad, abcd, 0); FileHeader fh = df.ToFileHeader(mod); NUnit.Framework.Assert.AreEqual(diffHeader, RawParseUtils.Decode(fh.GetBuffer())); NUnit.Framework.Assert.AreEqual(0, fh.GetStartOffset()); NUnit.Framework.Assert.AreEqual(fh.GetBuffer().Length, fh.GetEndOffset()); NUnit.Framework.Assert.AreEqual(FileHeader.PatchType.UNIFIED, fh.GetPatchType()); NUnit.Framework.Assert.AreEqual(1, fh.GetHunks().Count); HunkHeader hh = fh.GetHunks()[0]; NUnit.Framework.Assert.AreEqual(1, hh.ToEditList().Count); EditList el = hh.ToEditList(); NUnit.Framework.Assert.AreEqual(1, el.Count); Edit e = el[0]; NUnit.Framework.Assert.AreEqual(1, e.GetBeginA()); NUnit.Framework.Assert.AreEqual(1, e.GetEndA()); NUnit.Framework.Assert.AreEqual(1, e.GetBeginB()); NUnit.Framework.Assert.AreEqual(3, e.GetEndB()); NUnit.Framework.Assert.AreEqual(Edit.Type.INSERT, e.GetType()); }
/// <exception cref="System.IO.IOException"></exception> private void AssertFormatted(string name) { fmt.Format(file, a, b); string exp = RawParseUtils.Decode(ReadFile(name)); NUnit.Framework.Assert.AreEqual(exp, RawParseUtils.Decode(@out.ToByteArray())); }
/// <exception cref="System.IO.IOException"></exception> internal virtual string ReadString() { int len = ReadLength(); if (len == 0) { return(END); } len -= 4; // length header (4 bytes) if (len == 0) { return(string.Empty); } byte[] raw; if (len <= lineBuffer.Length) { raw = lineBuffer; } else { raw = new byte[len]; } IOUtil.ReadFully(@in, raw, 0, len); if (raw[len - 1] == '\n') { len--; } return(RawParseUtils.Decode(Constants.CHARSET, raw, 0, len)); }
// // // // // // // /// <exception cref="System.IO.IOException"></exception> private static FilePath GetSymRef(FilePath workTree, FilePath dotGit) { byte[] content = IOUtil.ReadFully(dotGit); if (!IsSymRef(content)) { throw new IOException(MessageFormat.Format(JGitText.Get().invalidGitdirRef, dotGit .GetAbsolutePath())); } int pathStart = 8; int lineEnd = RawParseUtils.NextLF(content, pathStart); if (content[lineEnd - 1] == '\n') { lineEnd--; } if (lineEnd == pathStart) { throw new IOException(MessageFormat.Format(JGitText.Get().invalidGitdirRef, dotGit .GetAbsolutePath())); } string gitdirPath = RawParseUtils.Decode(content, pathStart, lineEnd); FilePath gitdirFile = new FilePath(gitdirPath); if (gitdirFile.IsAbsolute()) { return(gitdirFile); } else { return(new FilePath(workTree, gitdirPath).GetCanonicalFile()); } }
/// <returns>the name of this entry.</returns> public virtual string GetName() { if (nameUTF8 != null) { return(RawParseUtils.Decode(nameUTF8)); } return(null); }
/// <exception cref="System.IO.IOException"></exception> private ObjectDirectory.CachedPackList ScanCachedPacks(ObjectDirectory.CachedPackList old) { FileSnapshot s = FileSnapshot.Save(cachedPacksFile); byte[] buf; try { buf = IOUtil.ReadFully(cachedPacksFile); } catch (FileNotFoundException) { buf = new byte[0]; } if (old != null && old.snapshot.Equals(s) && Arrays.Equals(old.raw, buf)) { old.snapshot.SetClean(s); return(old); } AList <LocalCachedPack> list = new AList <LocalCachedPack>(4); ICollection <ObjectId> tips = new HashSet <ObjectId>(); int ptr = 0; while (ptr < buf.Length) { if (buf[ptr] == '#' || buf[ptr] == '\n') { ptr = RawParseUtils.NextLF(buf, ptr); continue; } if (buf[ptr] == '+') { tips.AddItem(ObjectId.FromString(buf, ptr + 2)); ptr = RawParseUtils.NextLF(buf, ptr + 2); continue; } IList <string> names = new AList <string>(4); while (ptr < buf.Length && buf[ptr] == 'P') { int end = RawParseUtils.NextLF(buf, ptr); if (buf[end - 1] == '\n') { end--; } names.AddItem(RawParseUtils.Decode(buf, ptr + 2, end)); ptr = RawParseUtils.NextLF(buf, end); } if (!tips.IsEmpty() && !names.IsEmpty()) { list.AddItem(new LocalCachedPack(this, tips, names)); tips = new HashSet <ObjectId>(); } } list.TrimToSize(); return(new ObjectDirectory.CachedPackList(s, Sharpen.Collections.UnmodifiableList (list), buf)); }
public virtual void TestWriteLine2() { RawText a = new RawText(Constants.EncodeASCII("foo-a\nfoo-b")); ByteArrayOutputStream o = new ByteArrayOutputStream(); a.WriteLine(o, 1); byte[] r = o.ToByteArray(); NUnit.Framework.Assert.AreEqual("foo-b", RawParseUtils.Decode(r)); }
/// <summary>Load the configuration as a Git text style configuration file.</summary> /// <remarks> /// Load the configuration as a Git text style configuration file. /// <p> /// If the file does not exist, this configuration is cleared, and thus /// behaves the same as though the file exists, but is empty. /// </remarks> /// <exception cref="System.IO.IOException">the file could not be read (but does exist). /// </exception> /// <exception cref="NGit.Errors.ConfigInvalidException">the file is not a properly formatted configuration file. /// </exception> public override void Load() { FileSnapshot oldSnapshot = snapshot; FileSnapshot newSnapshot = FileSnapshot.Save(GetFile()); try { byte[] @in = IOUtil.ReadFully(GetFile()); ObjectId newHash = Hash(@in); if (hash.Equals(newHash)) { if (oldSnapshot.Equals(newSnapshot)) { oldSnapshot.SetClean(newSnapshot); } else { snapshot = newSnapshot; } } else { string decoded; if (@in.Length >= 3 && @in[0] == unchecked ((byte)unchecked ((int)(0xEF))) && @in[1 ] == unchecked ((byte)unchecked ((int)(0xBB))) && @in[2] == unchecked ((byte)unchecked ( (int)(0xBF)))) { decoded = RawParseUtils.Decode(RawParseUtils.UTF8_CHARSET, @in, 3, @in.Length); utf8Bom = true; } else { decoded = RawParseUtils.Decode(@in); } FromText(decoded); snapshot = newSnapshot; hash = newHash; } } catch (FileNotFoundException) { Clear(); snapshot = newSnapshot; } catch (IOException e) { IOException e2 = new IOException(MessageFormat.Format(JGitText.Get().cannotReadFile , GetFile())); Sharpen.Extensions.InitCause(e2, e); throw e2; } catch (ConfigInvalidException e) { throw new ConfigInvalidException(MessageFormat.Format(JGitText.Get().cannotReadFile , GetFile()), e); } }
public virtual void TestWriteLine3() { RawText a = new RawText(Constants.EncodeASCII("a\n\nb\n")); ByteArrayOutputStream o = new ByteArrayOutputStream(); a.WriteLineInternal(o, 1); byte[] r = o.ToByteArray(); NUnit.Framework.Assert.AreEqual(string.Empty, RawParseUtils.Decode(r)); }
/// <summary>Get the current object's complete path.</summary> /// <remarks> /// Get the current object's complete path. /// <p> /// This method is not very efficient and is primarily meant for debugging /// and final output generation. Applications should try to avoid calling it, /// and if invoked do so only once per interesting entry, where the name is /// absolutely required for correct function. /// </remarks> /// <returns> /// complete path of the current entry, from the root of the /// repository. If the current entry is in a subtree there will be at /// least one '/' in the returned string. Null if the current entry /// has no path, such as for annotated tags or root level trees. /// </returns> public virtual string GetPathString() { if (pathLen == 0) { pathLen = UpdatePathBuf(currVisit); if (pathLen == 0) { return(null); } } return(RawParseUtils.Decode(pathBuf, 0, pathLen)); }
/// <summary>Parse the complete commit message and decode it to a string.</summary> /// <remarks> /// Parse the complete commit message and decode it to a string. /// <p> /// This method parses and returns the message portion of the commit buffer, /// after taking the commit's character set into account and decoding the /// buffer using that character set. This method is a fairly expensive /// operation and produces a new string on each invocation. /// </remarks> /// <returns>decoded commit message as a string. Never null.</returns> public string GetFullMessage() { byte[] raw = buffer; int msgB = RawParseUtils.CommitMessage(raw, 0); if (msgB < 0) { return(string.Empty); } System.Text.Encoding enc = RawParseUtils.ParseEncoding(raw); return(RawParseUtils.Decode(enc, raw, msgB, raw.Length)); }
/// <exception cref="System.IO.IOException"></exception> private string ReadFile(FilePath directory, string fileName) { byte[] content = IOUtil.ReadFully(new FilePath(directory, fileName)); // strip off the last LF int end = content.Length; while (0 < end && content[end - 1] == '\n') { end--; } return(RawParseUtils.Decode(content, 0, end)); }
internal virtual PersonIdent ParseAuthor(byte[] raw) { if (raw.Length == 0) { return(null); } IDictionary <string, string> keyValueMap = new Dictionary <string, string>(); for (int p = 0; p < raw.Length;) { int end = RawParseUtils.NextLF(raw, p); if (end == p) { break; } int equalsIndex = RawParseUtils.Next(raw, p, '='); if (equalsIndex == end) { break; } string key = RawParseUtils.Decode(raw, p, equalsIndex - 1); string value = RawParseUtils.Decode(raw, equalsIndex + 1, end - 2); p = end; keyValueMap.Put(key, value); } string name = keyValueMap.Get(GIT_AUTHOR_NAME); string email = keyValueMap.Get(GIT_AUTHOR_EMAIL); string time = keyValueMap.Get(GIT_AUTHOR_DATE); // the time is saved as <seconds since 1970> <timezone offset> long when = long.Parse(Sharpen.Runtime.Substring(time, 0, time.IndexOf(' '))) * 1000; string tzOffsetString = Sharpen.Runtime.Substring(time, time.IndexOf(' ') + 1); int multiplier = -1; if (tzOffsetString[0] == '+') { multiplier = 1; } int hours = System.Convert.ToInt32(Sharpen.Runtime.Substring(tzOffsetString, 1, 3 )); int minutes = System.Convert.ToInt32(Sharpen.Runtime.Substring(tzOffsetString, 3, 5)); // this is in format (+/-)HHMM (hours and minutes) // we need to convert into minutes int tz = (hours * 60 + minutes) * multiplier; if (name != null && email != null) { return(new PersonIdent(name, email, when, tz)); } return(null); }
public virtual void TestInsertChangeId() { Git git = new Git(db); string messageHeader = "Some header line\n\nSome detail explanation\n"; string changeIdTemplate = "\nChange-Id: I" + ObjectId.ZeroId.GetName() + "\n"; string messageFooter = "Some foooter lines\nAnother footer line\n"; RevCommit commit = git.Commit().SetMessage(messageHeader + messageFooter).SetInsertChangeId (true).Call(); // we should find a real change id (at the end of the file) byte[] chars = Sharpen.Runtime.GetBytesForString(commit.GetFullMessage()); int lastLineBegin = RawParseUtils.PrevLF(chars, chars.Length - 2); string lastLine = RawParseUtils.Decode(chars, lastLineBegin + 1, chars.Length); NUnit.Framework.Assert.IsTrue(lastLine.Contains("Change-Id:")); NUnit.Framework.Assert.IsFalse(lastLine.Contains("Change-Id: I" + ObjectId.ZeroId .GetName())); commit = git.Commit().SetMessage(messageHeader + changeIdTemplate + messageFooter ).SetInsertChangeId(true).Call(); // we should find a real change id (in the line as dictated by the // template) chars = Sharpen.Runtime.GetBytesForString(commit.GetFullMessage()); int lineStart = 0; int lineEnd = 0; for (int i = 0; i < 4; i++) { lineStart = RawParseUtils.NextLF(chars, lineStart); } lineEnd = RawParseUtils.NextLF(chars, lineStart); string line = RawParseUtils.Decode(chars, lineStart, lineEnd); NUnit.Framework.Assert.IsTrue(line.Contains("Change-Id:")); NUnit.Framework.Assert.IsFalse(line.Contains("Change-Id: I" + ObjectId.ZeroId.GetName ())); commit = git.Commit().SetMessage(messageHeader + changeIdTemplate + messageFooter ).SetInsertChangeId(false).Call(); // we should find the untouched template chars = Sharpen.Runtime.GetBytesForString(commit.GetFullMessage()); lineStart = 0; lineEnd = 0; for (int i_1 = 0; i_1 < 4; i_1++) { lineStart = RawParseUtils.NextLF(chars, lineStart); } lineEnd = RawParseUtils.NextLF(chars, lineStart); line = RawParseUtils.Decode(chars, lineStart, lineEnd); NUnit.Framework.Assert.IsTrue(commit.GetFullMessage().Contains("Change-Id: I" + ObjectId .ZeroId.GetName())); }
public virtual void TestFreakingHugePathName() { int n = AbstractTreeIterator.DEFAULT_PATH_SIZE * 4; StringBuilder b = new StringBuilder(n); for (int i = 0; i < n; i++) { b.Append('q'); } string name = b.ToString(); ctp.Reset(Entry(m644, name, hash_a)); NUnit.Framework.Assert.IsFalse(ctp.Eof); NUnit.Framework.Assert.AreEqual(name, RawParseUtils.Decode(Constants.CHARSET, ctp .path, ctp.pathOffset, ctp.pathLen)); }
public virtual void TestGetCachedBytes() { string exp = "this is test data"; RevBlob a = tr.Blob("a"); RevBlob data = tr.Blob(exp); RevCommit r = tr.Commit().Add(a.Name, data).Create(); // // tr.ParseBody(r); NoteMap map = NoteMap.Read(reader, r); byte[] act = map.GetCachedBytes(a, exp.Length * 4); NUnit.Framework.Assert.IsNotNull(act, "has data for a"); NUnit.Framework.Assert.AreEqual(exp, RawParseUtils.Decode(act)); }
public virtual void TestCreateFileHeader_Binary() { ObjectId adId = Blob("a\nd\n"); ObjectId binId = Blob("a\nb\nc\n\x0\x0\x0\x0d\n"); string diffHeader = MakeDiffHeader(PATH_A, PATH_B, adId, binId) + "Binary files differ\n"; DiffEntry ad = DiffEntry.Delete(PATH_A, adId); DiffEntry abcd = DiffEntry.Add(PATH_B, binId); DiffEntry mod = DiffEntry.Pair(DiffEntry.ChangeType.MODIFY, ad, abcd, 0); FileHeader fh = df.ToFileHeader(mod); NUnit.Framework.Assert.AreEqual(diffHeader, RawParseUtils.Decode(fh.GetBuffer())); NUnit.Framework.Assert.AreEqual(FileHeader.PatchType.BINARY, fh.GetPatchType()); NUnit.Framework.Assert.AreEqual(1, fh.GetHunks().Count); HunkHeader hh = fh.GetHunks()[0]; NUnit.Framework.Assert.AreEqual(0, hh.ToEditList().Count); }
/// <summary>Load the configuration as a Git text style configuration file.</summary> /// <remarks> /// Load the configuration as a Git text style configuration file. /// <p> /// If the file does not exist, this configuration is cleared, and thus /// behaves the same as though the file exists, but is empty. /// </remarks> /// <exception cref="System.IO.IOException">the file could not be read (but does exist). /// </exception> /// <exception cref="NGit.Errors.ConfigInvalidException">the file is not a properly formatted configuration file. /// </exception> public override void Load() { FileSnapshot oldSnapshot = snapshot; FileSnapshot newSnapshot = FileSnapshot.Save(GetFile()); try { byte[] @in = IOUtil.ReadFully(GetFile()); ObjectId newHash = Hash(@in); if (hash.Equals(newHash)) { if (oldSnapshot.Equals(newSnapshot)) { oldSnapshot.SetClean(newSnapshot); } else { snapshot = newSnapshot; } } else { FromText(RawParseUtils.Decode(@in)); snapshot = newSnapshot; hash = newHash; } } catch (FileNotFoundException) { Clear(); snapshot = newSnapshot; } catch (IOException e) { IOException e2 = new IOException(MessageFormat.Format(JGitText.Get().cannotReadFile , GetFile())); Sharpen.Extensions.InitCause(e2, e); throw e2; } catch (ConfigInvalidException e) { throw new ConfigInvalidException(MessageFormat.Format(JGitText.Get().cannotReadFile , GetFile()), e); } }
/// <exception cref="System.IO.IOException"></exception> private string ReadLine(byte[] hdrbuf) { bin.Mark(hdrbuf.Length); int cnt = bin.Read(hdrbuf); int lf = 0; while (lf < cnt && hdrbuf[lf] != '\n') { lf++; } bin.Reset(); IOUtil.SkipFully(bin, lf); if (lf < cnt && hdrbuf[lf] == '\n') { IOUtil.SkipFully(bin, 1); } return(RawParseUtils.Decode(Constants.CHARSET, hdrbuf, 0, lf)); }
/// <exception cref="Sharpen.URISyntaxException"></exception> private static string Unescape(string s) { if (s == null) { return(null); } if (s.IndexOf('%') < 0) { return(s); } byte[] bytes; try { bytes = Sharpen.Runtime.GetBytesForString(s, Constants.CHARACTER_ENCODING); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } // can't happen byte[] os = new byte[bytes.Length]; int j = 0; for (int i = 0; i < bytes.Length; ++i) { byte c = bytes[i]; if (c == '%') { if (i + 2 >= bytes.Length) { throw new URISyntaxException(s, JGitText.Get().cannotParseGitURIish); } int val = (RawParseUtils.ParseHexInt4(bytes[i + 1]) << 4) | RawParseUtils.ParseHexInt4 (bytes[i + 2]); os[j++] = unchecked ((byte)val); i += 2; } else { os[j++] = c; } } return(RawParseUtils.Decode(os, 0, j)); }
/// <summary>Parse the tag message and return the first "line" of it.</summary> /// <remarks> /// Parse the tag message and return the first "line" of it. /// <p> /// The first line is everything up to the first pair of LFs. This is the /// "oneline" format, suitable for output in a single line display. /// <p> /// This method parses and returns the message portion of the tag buffer, /// after taking the tag's character set into account and decoding the buffer /// using that character set. This method is a fairly expensive operation and /// produces a new string on each invocation. /// </remarks> /// <returns> /// decoded tag message as a string. Never null. The returned string /// does not contain any LFs, even if the first paragraph spanned /// multiple lines. Embedded LFs are converted to spaces. /// </returns> public string GetShortMessage() { byte[] raw = buffer; int msgB = RawParseUtils.TagMessage(raw, 0); if (msgB < 0) { return(string.Empty); } Encoding enc = RawParseUtils.ParseEncoding(raw); int msgE = RawParseUtils.EndOfParagraph(raw, msgB); string str = RawParseUtils.Decode(enc, raw, msgB, msgE); if (RevCommit.HasLF(raw, msgB, msgE)) { str = str.Replace('\n', ' '); } return(str); }
public virtual void TestCreateFileHeader_GitLink() { ObjectId aId = Blob("a\n"); ObjectId bId = Blob("b\n"); string diffHeader = MakeDiffHeaderModeChange(PATH_A, PATH_A, aId, bId, GITLINK, REGULAR_FILE ) + "-Subproject commit " + aId.Name + "\n"; DiffEntry ad = DiffEntry.Delete(PATH_A, aId); ad.oldMode = FileMode.GITLINK; DiffEntry abcd = DiffEntry.Add(PATH_A, bId); DiffEntry mod = DiffEntry.Pair(DiffEntry.ChangeType.MODIFY, ad, abcd, 0); FileHeader fh = df.ToFileHeader(mod); NUnit.Framework.Assert.AreEqual(diffHeader, RawParseUtils.Decode(fh.GetBuffer())); NUnit.Framework.Assert.AreEqual(1, fh.GetHunks().Count); HunkHeader hh = fh.GetHunks()[0]; NUnit.Framework.Assert.AreEqual(0, hh.ToEditList().Count); }
/// <exception cref="NGit.Errors.CorruptObjectException"></exception> internal virtual void ParseCanonical(RevWalk walk, byte[] rawTag) { MutableInteger pos = new MutableInteger(); int oType; pos.value = 53; // "object $sha1\ntype " oType = Constants.DecodeTypeString(this, rawTag, unchecked ((byte)'\n'), pos); walk.idBuffer.FromString(rawTag, 7); @object = walk.LookupAny(walk.idBuffer, oType); int p = pos.value += 4; // "tag " int nameEnd = RawParseUtils.NextLF(rawTag, p) - 1; tagName = RawParseUtils.Decode(Constants.CHARSET, rawTag, p, nameEnd); if (walk.IsRetainBody()) { buffer = rawTag; } flags |= PARSED; }
private static string ReadFirstLine(FilePath head) { try { byte[] buf = IOUtil.ReadFully(head, 4096); int n = buf.Length; if (n == 0) { return(null); } if (buf[n - 1] == '\n') { n--; } return(RawParseUtils.Decode(buf, 0, n)); } catch (IOException) { return(null); } }
/// <summary>Extract the email address (if present) from the footer.</summary> /// <remarks> /// Extract the email address (if present) from the footer. /// <p> /// If there is an email address looking string inside of angle brackets /// (e.g. "<a@b>"), the return value is the part extracted from inside the /// brackets. If no brackets are found, then /// <see cref="GetValue()">GetValue()</see> /// is returned /// if the value contains an '@' sign. Otherwise, null. /// </remarks> /// <returns>email address appearing in the value of this footer, or null.</returns> public string GetEmailAddress() { int lt = RawParseUtils.NextLF(buffer, valStart, '<'); if (valEnd <= lt) { int at = RawParseUtils.NextLF(buffer, valStart, '@'); if (valStart < at && at < valEnd) { return(GetValue()); } return(null); } int gt = RawParseUtils.NextLF(buffer, lt, '>'); if (valEnd < gt) { return(null); } return(RawParseUtils.Decode(enc, buffer, lt, gt - 1)); }