/** * Add a commit if it does not have a flag set yet, then set the flag. * <para /> * This method permits the application to test if the commit has the given * flag; if it does not already have the flag than the commit is added to * the queue and the flag is set. This later will prevent the commit from * being added twice. * * @param c * commit to add. * @param queueControl * flag that controls admission to the queue. */ public void add(RevCommit c, RevFlag queueControl) { if (!c.has(queueControl)) { c.add(queueControl); add(c); } }
public override void add(RevCommit c) { Block b = _head; if (b == null || !b.canUnpop()) { b = Free.newBlock(); b.resetToEnd(); b.Next = _head; _head = b; } b.unpop(c); }
public RepositoryWalker(CoreRepository repo) { if (repo == null) { throw new ArgumentNullException(nameof(repo)); } _walker = new RevWalk(repo); _assistantWalker = new RevWalk(repo); _initCommit = new RevCommit(repo.Head.ObjectId); }
public override void setUp() { base.setUp(); diskRepo = createBareRepository(); refdir = (RefDirectory)diskRepo.RefDatabase; repo = new TestRepository(diskRepo); A = repo.commit().create(); B = repo.commit(repo.getRevWalk().parseCommit(A)); v1_0 = repo.tag("v1_0", B); repo.getRevWalk().parseBody(v1_0); }
private CommitWrapper GetCommit(RevCommit currentRev) { return Map.GetOrAdd(currentRev, (s) => { var commit = currentRev.AsCommit(_walker); return new CommitWrapper { Commit = commit, Detail = ConvertToCommitDetail(commit), TreeEntry = commit.TreeEntry, ParentCount = commit.ParentIds.Length }; }); }
/// <summary> /// Mark an object or commit to start graph traversal from. /// <para /> /// Callers are encouraged to use <see cref="RevWalk.parseAny(AnyObjectId)"/> /// instead of <see cref="RevWalk.lookupAny(AnyObjectId, int)"/>, as this method /// requires the object to be parsed before it can be added as a root for the /// traversal. /// <para /> /// The method will automatically parse an unparsed object, but error /// handling may be more difficult for the application to explain why a /// RevObject is not actually valid. The object pool of this walker would /// also be 'poisoned' by the invalid <see cref="RevObject"/>. /// <para /> /// This method will automatically call <see cref="RevWalk.markStart(RevCommit)"/> /// if passed RevCommit instance, or a <see cref="RevTag"/> that directly (or indirectly) /// references a <see cref="RevCommit"/>. /// </summary> /// <param name="o"> /// The object to start traversing from. The object passed must be /// from this same revision walker. /// </param> /// <exception cref="MissingObjectException"> /// The object supplied is not available from the object /// database. This usually indicates the supplied object is /// invalid, but the reference was constructed during an earlier /// invocation to <see cref="RevWalk.lookupAny(AnyObjectId, int)"/>. /// </exception> /// <exception cref="IncorrectObjectTypeException"> /// The object was not parsed yet and it was discovered during /// parsing that it is not actually the type of the instance /// passed in. This usually indicates the caller used the wrong /// type in a <see cref="RevWalk.lookupAny(AnyObjectId, int)"/> call. /// </exception> /// <exception cref="Exception"> /// A pack file or loose object could not be Read. /// </exception> public void markStart(RevObject o) { while (o is RevTag) { AddObject(o); o = ((RevTag)o).getObject(); parseHeaders(o); } RevCommit oComm = (o as RevCommit); if (oComm != null) { base.markStart(oComm); } else { AddObject(o); } }
public override void add(RevCommit c) { Block b = _tail; if (b == null) { b = Free.newBlock(); b.add(c); _head = b; _tail = b; return; } if (b.isFull()) { b = Free.newBlock(); _tail.Next = b; _tail = b; } b.add(c); }
public override RevCommit next() { RevCommit c = _source.next(); if (c != null) { foreach (RevCommit p in c.Parents) { if ((p.Flags & RevWalk.UNINTERESTING) != 0) { _held.add(p); } } return(c); } var boundary = new FIFORevQueue(); boundary.shareFreeList(_held); while (true) { c = _held.next(); if (c == null) { break; } if ((c.Flags & Duplicate) != 0) { continue; } if ((c.Flags & Parsed) == 0) { c.parseHeaders(_walk); } c.Flags |= Duplicate; boundary.add(c); } boundary.removeFlag(Duplicate); _parent._generator = boundary; return(boundary.next()); }
/// <summary> /// Parse the tag message and return the first "line" of it. /// <para /> /// 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. /// <para /> /// 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. /// </summary> /// <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 override void add(RevCommit c) { Entry q = _head; long when = c.CommitTime; Entry n = NewEntry(c); if (q == null || when > q.Commit.CommitTime) { n.Next = q; _head = n; } else { Entry p = q.Next; while (p != null && p.Commit.CommitTime > when) { q = p; p = q.Next; } n.Next = q.Next; q.Next = n; } }
public override RevCommit next() { Block b = _head; if (b == null) { return(null); } RevCommit c = b.pop(); if (b.isEmpty()) { _head = b.Next; if (_head == null) { _tail = null; } Free.freeBlock(b); } return(c); }
public void testParse_explicit_bad_encoded() { RevCommit c; using (var b = new BinaryWriter(new MemoryStream())) { b.Write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8")); b.Write("author F\u00f6r fattare <*****@*****.**> 1218123387 +0700\n".getBytes("ISO-8859-1")); b.Write("committer C O. Miter <*****@*****.**> 1218123390 -0500\n".getBytes("UTF-8")); b.Write("encoding EUC-JP\n".getBytes("UTF-8")); b.Write("\n".getBytes("UTF-8")); b.Write("\u304d\u308c\u3044\n".getBytes("UTF-8")); b.Write("\n".getBytes("UTF-8")); b.Write("Hi\n".getBytes("UTF-8")); c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id c.parseCanonical(new GitSharp.Core.RevWalk.RevWalk(db), ((MemoryStream) b.BaseStream).ToArray()); } Assert.AreEqual("EUC-JP", c.Encoding.WebName.ToUpperInvariant()); //Hacked as Windows uses a lowercased naming convention AssertHelper.IgnoreOn(AssertedPlatform.Mono, () => Assert.AreEqual("F\u00f6r fattare", c.getAuthorIdent().Name), "Will fail in mono due to https://bugzilla.novell.com/show_bug.cgi?id=547902"); Assert.AreEqual("\u304d\u308c\u3044", c.getShortMessage()); Assert.AreEqual("\u304d\u308c\u3044\n\nHi\n", c.getFullMessage()); }
public override void setUp() { base.setUp(); // Test graph was stolen from git-core t6012-rev-list-simplify // (by Junio C Hamano in 65347030590bcc251a9ff2ed96487a0f1b9e9fa8) // RevBlob zF = blob("zF"); RevBlob zH = blob("zH"); RevBlob zI = blob("zI"); RevBlob zS = blob("zS"); RevBlob zY = blob("zY"); a = Commit(tree(File(pF, zH))); b = Commit(tree(File(pF, zI)), a); c = Commit(tree(File(pF, zI)), a); d = Commit(tree(File(pA, zS), File(pF, zI)), c); parseBody(d); e = Commit(d.Tree, d, b); f = Commit(tree(File(pA, zS), File(pE, zY), File(pF, zI)), e); parseBody(f); g = Commit(tree(File(pE, zY), File(pF, zI)), b); h = Commit(f.Tree, g, f); i = Commit(tree(File(pA, zS), File(pE, zY), File(pF, zF)), h); byName = new Dictionary<RevCommit, string>(); var fields = typeof(RevWalkPathFilter6012Test).GetFields(BindingFlags.NonPublic | BindingFlags.Instance) .Where(x => x.FieldType == typeof(RevCommit)); foreach (FieldInfo z in fields) { byName.Add((RevCommit)z.GetValue(this), z.Name); } }
public override bool include(GitSharp.Core.RevWalk.RevWalk walker, RevCommit cmit) { bool remoteKnowsIsCommon = cmit.has(_common); if (cmit.has(_advertised)) { cmit.add(_common); } return !remoteKnowsIsCommon; }
private RevCommit create(string msg) { var b = new StringBuilder(); b.Append("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"); b.Append("author A U. Thor <*****@*****.**> 1218123387 +0700\n"); b.Append("committer C O. Miter <*****@*****.**> 1218123390 -0500\n"); b.Append("\n"); b.Append(msg); var c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); c.parseCanonical(new GitSharp.Core.RevWalk.RevWalk(db), b.ToString().getBytes("UTF-8")); return c; }
public void testParse_WeirdHeaderOnlyCommit() { var b = new StringBuilder(); b.Append("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"); b.Append("author A U. Thor <*****@*****.**> 1218123387 +0700\n"); b.Append("committer C O. Miter <*****@*****.**> 1218123390 -0500\n"); var c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); c.parseCanonical(new GitSharp.Core.RevWalk.RevWalk(db), b.ToString().getBytes("UTF-8")); Assert.AreEqual(string.Empty, c.getFullMessage()); Assert.AreEqual(string.Empty, c.getShortMessage()); }
private void PushLocalCommit(RevCommit p) { if (p.has(LOCALLY_SEEN)) return; _revWalk.parseHeaders(p); p.add(LOCALLY_SEEN); p.add(COMPLETE); p.carry(COMPLETE); p.DisposeBody(); _localCommitQueue.add(p); }
public override void add(RevCommit c) { throw new InvalidOperationException(); }
/// <summary> /// Add a commit to the queue. /// <para /> /// This method always adds the commit, even if it is already in the queue or /// previously was in the queue but has already been removed. To control /// queue admission use <see cref="add(RevCommit, RevFlag)"/>. /// </summary> /// <param name="c">Commit to add.</param> public abstract void add(RevCommit c);
public void parseCanonical(RevWalk walk, byte[] raw) { MutableObjectId idBuffer = walk.IdBuffer; idBuffer.FromString(raw, 5); _tree = walk.lookupTree(idBuffer); int ptr = 46; if (Parents == null) { var pList = new RevCommit[1]; int nParents = 0; while (true) { if (raw[ptr] != (byte)'p') { break; } idBuffer.FromString(raw, ptr + 7); RevCommit p = walk.lookupCommit(idBuffer); if (nParents == 0) { pList[nParents++] = p; } else if (nParents == 1) { pList = new[] { pList[0], p }; nParents = 2; } else { if (pList.Length <= nParents) { RevCommit[] old = pList; pList = new RevCommit[pList.Length + 32]; Array.Copy(old, 0, pList, 0, nParents); } pList[nParents++] = p; } ptr += 48; } if (nParents != pList.Length) { RevCommit[] old = pList; pList = new RevCommit[nParents]; Array.Copy(old, 0, pList, 0, nParents); } Parents = pList; } // extract time from "committer " ptr = RawParseUtils.committer(raw, ptr); if (ptr > 0) { ptr = RawParseUtils.nextLF(raw, ptr, (byte)'>'); // In 2038 commitTime will overflow unless it is changed to long. CommitTime = RawParseUtils.parseBase10(raw, ptr, null); } if (walk.isRetainBody()) { _buffer = raw; } Flags |= PARSED; }
private bool CarryOntoOne(RevCommit p, int carry) { bool haveAll = (p.Flags & carry) == carry; p.Flags |= carry; if ((p.Flags & _recarryMask) == _recarryTest) { // We were popped without being a merge base, but we just got // voted to be one. Inject ourselves back at the front of the // pending queue and tell all of our ancestors they are within // the merge base now. // p.Flags &= ~Popped; _pending.add(p); CarryOntoHistory(p, _branchMask | MergeBase); return true; } // If we already had all carried flags, our parents do too. // Return true to stop the caller from running down this leg // of the revision graph any further. // return haveAll; }
private void Add(RevCommit c) { int flag = _walker.allocFlag(); _branchMask |= flag; if ((c.Flags & _branchMask) != 0) { // This should never happen. RevWalk ensures we get a // commit admitted to the initial queue only once. If // we see this marks aren't correctly erased. // throw new InvalidOperationException("Stale RevFlags on " + c); } c.Flags |= flag; _pending.add(c); }
public void testNewNamespaceConflictWithLoosePrefixOfExisting() { string newRef = "refs/heads/z/a"; RefUpdate ru = updateRef(newRef); RevCommit newid = new RevCommit(ru.NewObjectId) { // empty }; ru.NewObjectId = newid; RefUpdate.RefUpdateResult update = ru.Update(); Assert.AreEqual(RefUpdate.RefUpdateResult.New, update); // end setup string newRef2 = "refs/heads/z"; RefUpdate ru2 = updateRef(newRef2); RevCommit newid2 = new RevCommit(ru2.NewObjectId) { // empty }; ru.NewObjectId = newid2; RefUpdate.RefUpdateResult update2 = ru2.Update(); Assert.AreEqual(RefUpdate.RefUpdateResult.LockFailure, update2); Assert.AreEqual(1, db.ReflogReader("refs/heads/z/a").getReverseEntries().Count); Assert.IsNull(db.ReflogReader("refs/heads/z")); Assert.AreEqual(0, db.ReflogReader("HEAD").getReverseEntries().Count); }
public override RevCommit next() { try { while (true) { RevCommit c = _pending.next(); if (c == null) { _walker.WindowCursor.Release(); return(null); } bool produce = !((c.Flags & UNINTERESTING) != 0) && _filter.include(_walker, c); foreach (RevCommit p in c.Parents) { if ((p.Flags & SEEN) != 0) { continue; } if ((p.Flags & PARSED) == 0) { p.parseHeaders(_walker); } p.Flags |= SEEN; _pending.add(p); } _walker.carryFlagsImpl(c); if ((c.Flags & UNINTERESTING) != 0) { if (_pending.everbodyHasFlag(UNINTERESTING)) { RevCommit n = _pending.peek(); if (n != null && n.CommitTime >= _last.CommitTime) { // This is too close to call. The Next commit we // would pop is dated After the last one produced. // We have to keep going to ensure that we carry // flags as much as necessary. // _overScan = OVER_SCAN; } else if (--_overScan == 0) { throw StopWalkException.INSTANCE; } } else { _overScan = OVER_SCAN; } if (CanDispose) { c.DisposeBody(); } continue; } if (produce) { return(_last = c); } if (CanDispose) { c.DisposeBody(); } } } catch (StopWalkException) { _walker.WindowCursor.Release(); _pending.clear(); return(null); } }
/// <summary> /// Assume a commit is available on the recipient's side. /// <para/> /// In order to fetch from a bundle the recipient must have any assumed /// commit. Each assumed commit is explicitly recorded in the bundle header /// to permit the recipient to validate it has these objects. /// </summary> /// <param name="c"> /// the commit to assume being available. This commit should be /// parsed and not disposed in order to maximize the amount of /// debugging information available in the bundle stream. /// </param> public void assume(RevCommit c) { if (c != null) { _assume.Add(c); } }
public override RevCommit next() { try { while (true) { RevCommit c = _pending.next(); if (c == null) { _walker.WindowCursor.Release(); return null; } bool produce = !((c.Flags & UNINTERESTING) != 0) && _filter.include(_walker, c); foreach (RevCommit p in c.Parents) { if ((p.Flags & SEEN) != 0) continue; if ((p.Flags & PARSED) == 0) { p.parseHeaders(_walker); } p.Flags |= SEEN; _pending.add(p); } _walker.carryFlagsImpl(c); if ((c.Flags & UNINTERESTING) != 0) { if (_pending.everbodyHasFlag(UNINTERESTING)) { RevCommit n = _pending.peek(); if (n != null && n.CommitTime >= _last.CommitTime) { // This is too close to call. The Next commit we // would pop is dated After the last one produced. // We have to keep going to ensure that we carry // flags as much as necessary. // _overScan = OVER_SCAN; } else if (--_overScan == 0) { throw StopWalkException.INSTANCE; } } else { _overScan = OVER_SCAN; } if (CanDispose) { c.DisposeBody(); } continue; } if (produce) { return _last = c; } if (CanDispose) { c.DisposeBody(); } } } catch (StopWalkException) { _walker.WindowCursor.Release(); _pending.clear(); return null; } }
private bool WantSatisfied(RevCommit want) { _walk.resetRetain(SAVE); _walk.markStart(want); while (true) { RevCommit c = _walk.next(); if (c == null) break; if (c.has(PEER_HAS)) { AddCommonBase(c); return true; } } return false; }
public override bool include(RevWalk walker, RevCommit c) { // Reset the tree filter to scan this commit and parents. // RevCommit[] pList = c.Parents; int nParents = pList.Length; TreeWalk.TreeWalk tw = _pathFilter; var trees = new ObjectId[nParents + 1]; for (int i = 0; i < nParents; i++) { RevCommit p = c.Parents[i]; if ((p.Flags & Parsed) == 0) { p.parseHeaders(walker); } trees[i] = p.Tree; } trees[nParents] = c.Tree; tw.reset(trees); if (nParents == 1) { // We have exactly one parent. This is a very common case. // int chgs = 0, adds = 0; while (tw.next()) { chgs++; if (tw.getRawMode(0) == 0 && tw.getRawMode(1) != 0) { adds++; } else { break; // no point in looking at this further. } } if (chgs == 0) { // No changes, so our tree is effectively the same as // our parent tree. We pass the buck to our parent. // c.Flags |= Rewrite; return(false); } // We have interesting items, but neither of the special // cases denoted above. // return(true); } if (nParents == 0) { // We have no parents to compare against. Consider us to be // Rewrite only if we have no paths matching our filter. // if (tw.next()) { return(true); } c.Flags |= Rewrite; return(false); } // We are a merge commit. We can only be Rewrite if we are same // to _all_ parents. We may also be able to eliminate a parent if // it does not contribute changes to us. Such a parent may be an // uninteresting side branch. // var chgs_ = new int[nParents]; var adds_ = new int[nParents]; while (tw.next()) { int myMode = tw.getRawMode(nParents); for (int i = 0; i < nParents; i++) { int pMode = tw.getRawMode(i); if (myMode == pMode && tw.idEqual(i, nParents)) { continue; } chgs_[i]++; if (pMode == 0 && myMode != 0) { adds_[i]++; } } } bool same = false; bool diff = false; for (int i = 0; i < nParents; i++) { if (chgs_[i] == 0) { // No changes, so our tree is effectively the same as // this parent tree. We pass the buck to only this one // parent commit. // RevCommit p = pList[i]; if ((p.Flags & Uninteresting) != 0) { // This parent was marked as not interesting by the // application. We should look for another parent // that is interesting. // same = true; continue; } c.Flags |= Rewrite; c.Parents = new[] { p }; return(false); } if (chgs_[i] == adds_[i]) { // All of the differences from this parent were because we // added files that they did not have. This parent is our // "empty tree root" and thus their history is not relevant. // Cut our grandparents to be an empty list. // pList[i].Parents = RevCommit.NoParents; } // We have an interesting difference relative to this parent. // diff = true; } if (diff && !same) { // We did not abort above, so we are different in at least one // way from all of our parents. We have to take the blame for // that difference. // return(true); } // We are the same as all of our parents. We must keep them // as they are and allow those parents to flow into pending // for further scanning. // c.Flags |= Rewrite; return(false); }
public void testNewNamespaceConflictWithPackedPrefixOfExisting() { string newRef = "refs/heads/prefix"; RefUpdate ru = updateRef(newRef); RevCommit newid = new RevCommit(ru.NewObjectId) { // empty }; ru.NewObjectId = newid; RefUpdate.RefUpdateResult update = ru.Update(); Assert.AreEqual(RefUpdate.RefUpdateResult.LockFailure, update); Assert.IsNull(db.ReflogReader("refs/heads/prefix")); Assert.AreEqual(0, db.ReflogReader("HEAD").getReverseEntries().Count); }
public override bool include(RevWalk walker, RevCommit cmit) { // Reset the tree filter to scan this commit and parents. // RevCommit[] pList = cmit.Parents; int nParents = pList.Length; TreeWalk.TreeWalk tw = _pathFilter; var trees = new ObjectId[nParents + 1]; for (int i = 0; i < nParents; i++) { RevCommit p = cmit.Parents[i]; if ((p.Flags & Parsed) == 0) { p.parseHeaders(walker); } trees[i] = p.Tree; } trees[nParents] = cmit.Tree; tw.reset(trees); if (nParents == 1) { // We have exactly one parent. This is a very common case. // int chgs = 0, adds = 0; while (tw.next()) { chgs++; if (tw.getRawMode(0) == 0 && tw.getRawMode(1) != 0) adds++; else break; // no point in looking at this further. } if (chgs == 0) { // No changes, so our tree is effectively the same as // our parent tree. We pass the buck to our parent. // cmit.Flags |= Rewrite; return false; } // We have interesting items, but neither of the special // cases denoted above. // return true; } if (nParents == 0) { // We have no parents to compare against. Consider us to be // Rewrite only if we have no paths matching our filter. // if (tw.next()) return true; cmit.Flags |= Rewrite; return false; } // We are a merge commit. We can only be Rewrite if we are same // to _all_ parents. We may also be able to eliminate a parent if // it does not contribute changes to us. Such a parent may be an // uninteresting side branch. // var chgs_ = new int[nParents]; var adds_ = new int[nParents]; while (tw.next()) { int myMode = tw.getRawMode(nParents); for (int i = 0; i < nParents; i++) { int pMode = tw.getRawMode(i); if (myMode == pMode && tw.idEqual(i, nParents)) continue; chgs_[i]++; if (pMode == 0 && myMode != 0) { adds_[i]++; } } } bool same = false; bool diff = false; for (int i = 0; i < nParents; i++) { if (chgs_[i] == 0) { // No changes, so our tree is effectively the same as // this parent tree. We pass the buck to only this one // parent commit. // RevCommit p = pList[i]; if ((p.Flags & Uninteresting) != 0) { // This parent was marked as not interesting by the // application. We should look for another parent // that is interesting. // same = true; continue; } cmit.Flags |= Rewrite; cmit.Parents = new[] { p }; return false; } if (chgs_[i] == adds_[i]) { // All of the differences from this parent were because we // added files that they did not have. This parent is our // "empty tree root" and thus their history is not relevant. // Cut our grandparents to be an empty list. // pList[i].Parents = RevCommit.NoParents; } // We have an interesting difference relative to this parent. // diff = true; } if (diff && !same) { // We did not abort above, so we are different in at least one // way from all of our parents. We have to take the blame for // that difference. // return true; } // We are the same as all of our parents. We must keep them // as they are and allow those parents to flow into pending // for further scanning. // cmit.Flags |= Rewrite; return false; }
private void CarryOntoHistory(RevCommit c, int carry) { while (true) { RevCommit[] pList = c.Parents; if (pList == null) return; int n = pList.Length; if (n == 0) return; for (int i = 1; i < n; i++) { RevCommit p = pList[i]; if (!CarryOntoOne(p, carry)) { CarryOntoHistory(p, carry); } } c = pList[0]; if (CarryOntoOne(c, carry)) break; } }
public void testNoCacheObjectIdSubclass() { string newRef = "refs/heads/abc"; RefUpdate ru = updateRef(newRef); RevCommit newid = new RevCommit(ru.NewObjectId) { // empty }; ru.NewObjectId = newid; RefUpdate.RefUpdateResult update = ru.Update(); Assert.AreEqual(RefUpdate.RefUpdateResult.New, update); Ref r = db.getAllRefs()[newRef]; Assert.IsNotNull(r); Assert.AreEqual(newRef, r.Name); Assert.IsNotNull(r.ObjectId); Assert.AreNotSame(newid, r.ObjectId); Assert.AreSame(typeof (ObjectId), r.ObjectId.GetType()); Assert.AreEqual(newid.Copy(), r.ObjectId); IList<ReflogReader.Entry> reverseEntries1 = db.ReflogReader("refs/heads/abc").getReverseEntries(); ReflogReader.Entry entry1 = reverseEntries1[0]; Assert.AreEqual(1, reverseEntries1.Count); Assert.AreEqual(ObjectId.ZeroId, entry1.getOldId()); Assert.AreEqual(r.ObjectId, entry1.getNewId()); Assert.AreEqual(new PersonIdent(db).ToString(), entry1.getWho().ToString()); Assert.AreEqual("", entry1.getComment()); IList<ReflogReader.Entry> reverseEntries2 = db.ReflogReader("HEAD").getReverseEntries(); Assert.AreEqual(0, reverseEntries2.Count); }
private byte[] makeBundle(string name, string anObjectToInclude, RevCommit assume) { var bw = new BundleWriter(db, NullProgressMonitor.Instance); bw.include(name, ObjectId.FromString(anObjectToInclude)); if (assume != null) { bw.assume(assume); } var @out = new MemoryStream(); bw.writeBundle(@out); return @out.ToArray(); }
public void testParse_explicit_encoded() { Assert.Ignore("We are going to deal with encoding problems later. For now, they are only disturbing the build."); RevCommit c; using (var b = new BinaryWriter(new MemoryStream())) { b.Write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("EUC-JP")); b.Write("author F\u00f6r fattare <*****@*****.**> 1218123387 +0700\n".getBytes("EUC-JP")); b.Write("committer C O. Miter <*****@*****.**> 1218123390 -0500\n".getBytes("EUC-JP")); b.Write("encoding euc_JP\n".getBytes("EUC-JP")); b.Write("\n".getBytes("EUC-JP")); b.Write("\u304d\u308c\u3044\n".getBytes("EUC-JP")); b.Write("\n".getBytes("EUC-JP")); b.Write("Hi\n".getBytes("EUC-JP")); c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id c.parseCanonical(new GitSharp.Core.RevWalk.RevWalk(db), ((MemoryStream) b.BaseStream).ToArray()); } Assert.AreEqual("EUC-JP", c.Encoding.WebName.ToUpperInvariant()); //Hacked as Windows uses a lowercased naming convention Assert.AreEqual("F\u00f6r fattare", c.getAuthorIdent().Name); Assert.AreEqual("\u304d\u308c\u3044", c.getShortMessage()); Assert.AreEqual("\u304d\u308c\u3044\n\nHi\n", c.getFullMessage()); }
public override bool include(GitSharp.Core.RevWalk.RevWalk walker, RevCommit cmit) { return true; }
protected static void Describe(StringBuilder s, RevCommit c) { s.Append(c.ToString()); s.Append('\n'); }
static PendingGenerator() { InitLast = new RevCommit(ObjectId.ZeroId) { CommitTime = int.MaxValue }; }
public void testParse_implicit_UTF8_encoded() { RevCommit c; using (var b = new BinaryWriter(new MemoryStream())) { b.Write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8")); b.Write("author F\u00f6r fattare <*****@*****.**> 1218123387 +0700\n".getBytes("UTF-8")); b.Write("committer C O. Miter <*****@*****.**> 1218123390 -0500\n".getBytes("UTF-8")); b.Write("\n".getBytes("UTF-8")); b.Write("Sm\u00f6rg\u00e5sbord\n".getBytes("UTF-8")); b.Write("\n".getBytes("UTF-8")); b.Write("\u304d\u308c\u3044\n".getBytes("UTF-8")); c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id c.parseCanonical(new GitSharp.Core.RevWalk.RevWalk(db), ((MemoryStream) b.BaseStream).ToArray()); } Assert.AreSame(Constants.CHARSET, c.Encoding); Assert.AreEqual("F\u00f6r fattare", c.getAuthorIdent().Name); Assert.AreEqual("Sm\u00f6rg\u00e5sbord", c.getShortMessage()); Assert.AreEqual("Sm\u00f6rg\u00e5sbord\n\n\u304d\u308c\u3044\n", c.getFullMessage()); }
public void testParse_implicit_mixed_encoded() { RevCommit c; using (var b = new BinaryWriter(new MemoryStream())) { b.Write("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n".getBytes("UTF-8")); b.Write("author F\u00f6r fattare <*****@*****.**> 1218123387 +0700\n".getBytes("ISO-8859-1")); b.Write("committer C O. Miter <*****@*****.**> 1218123390 -0500\n".getBytes("UTF-8")); b.Write("\n".getBytes("UTF-8")); b.Write("Sm\u00f6rg\u00e5sbord\n".getBytes("UTF-8")); b.Write("\n".getBytes("UTF-8")); b.Write("\u304d\u308c\u3044\n".getBytes("UTF-8")); c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); // bogus id c.parseCanonical(new GitSharp.Core.RevWalk.RevWalk(db), ((MemoryStream) b.BaseStream).ToArray()); } Assert.AreSame(Constants.CHARSET, c.Encoding); AssertHelper.IgnoreOn(AssertedPlatform.Mono, () => Assert.AreEqual("F\u00f6r fattare", c.getAuthorIdent().Name), "Will fail in mono due to https://bugzilla.novell.com/show_bug.cgi?id=549914"); Assert.AreEqual("Sm\u00f6rg\u00e5sbord", c.getShortMessage()); Assert.AreEqual("Sm\u00f6rg\u00e5sbord\n\n\u304d\u308c\u3044\n", c.getFullMessage()); }
public void testParse_NoParents() { ObjectId treeId = id("9788669ad918b6fcce64af8882fc9a81cb6aba67"); const string authorName = "A U. Thor"; const string authorEmail = "*****@*****.**"; const int authorTime = 1218123387; const string committerName = "C O. Miter"; const string committerEmail = "*****@*****.**"; const int committerTime = 1218123390; var body = new StringBuilder(); body.Append("tree "); body.Append(treeId.Name); body.Append("\n"); body.Append("author "); body.Append(authorName); body.Append(" <"); body.Append(authorEmail); body.Append("> "); body.Append(authorTime); body.Append(" +0700\n"); body.Append("committer "); body.Append(committerName); body.Append(" <"); body.Append(committerEmail); body.Append("> "); body.Append(committerTime); body.Append(" -0500\n"); body.Append("\n"); var rw = new GitSharp.Core.RevWalk.RevWalk(db); var c = new RevCommit(id("9473095c4cb2f12aefe1db8a355fe3fafba42f67")); Assert.IsNull(c.Tree); Assert.IsNull(c.Parents); c.parseCanonical(rw, body.ToString().getBytes("UTF-8")); Assert.IsNotNull(c.Tree); Assert.AreEqual(treeId, c.Tree.getId()); Assert.AreSame(rw.lookupTree(treeId), c.Tree); Assert.IsNotNull(c.Parents); Assert.AreEqual(0, c.Parents.Length); Assert.AreEqual(string.Empty, c.getFullMessage()); PersonIdent cAuthor = c.getAuthorIdent(); Assert.IsNotNull(cAuthor); Assert.AreEqual(authorName, cAuthor.Name); Assert.AreEqual(authorEmail, cAuthor.EmailAddress); PersonIdent cCommitter = c.getCommitterIdent(); Assert.IsNotNull(cCommitter); Assert.AreEqual(committerName, cCommitter.Name); Assert.AreEqual(committerEmail, cCommitter.EmailAddress); }