Esempio n. 1
0
        public void testGetRefs_PackedWithPeeled()
        {
            IDictionary <string, global::GitSharp.Core.Ref> all;

            writePackedRefs("# pack-refs with: peeled \n" +   //
                            A.Name + " refs/heads/master\n" + //
                            B.Name + " refs/heads/other\n" +  //
                            v1_0.Name + " refs/tags/v1.0\n" + //
                            "^" + v1_0.getObject().Name + "\n");
            all = refdir.getRefs(RefDatabase.ALL);

            Assert.AreEqual(4, all.size());
            global::GitSharp.Core.Ref head   = all.get(Constants.HEAD);
            global::GitSharp.Core.Ref master = all.get("refs/heads/master");
            global::GitSharp.Core.Ref other  = all.get("refs/heads/other");
            global::GitSharp.Core.Ref tag    = all.get("refs/tags/v1.0");

            Assert.AreEqual(A, master.getObjectId());
            Assert.IsTrue(master.isPeeled());
            Assert.IsNull(master.getPeeledObjectId());

            Assert.AreEqual(B, other.getObjectId());
            Assert.IsTrue(other.isPeeled());
            Assert.IsNull(other.getPeeledObjectId());

            Assert.AreSame(master, head.getTarget());
            Assert.AreEqual(A, head.getObjectId());
            Assert.IsTrue(head.isPeeled());
            Assert.IsNull(head.getPeeledObjectId());

            Assert.AreEqual(v1_0, tag.getObjectId());
            Assert.IsTrue(tag.isPeeled());
            Assert.AreEqual(v1_0.getObject(), tag.getPeeledObjectId());
        }
Esempio n. 2
0
        public void testParseAllFields()
        {
            ObjectId     treeId      = Id("9788669ad918b6fcce64af8882fc9a81cb6aba67");
            const string name        = "v1.2.3.4.5";
            const string taggerName  = "A U. Thor";
            const string taggerEmail = "*****@*****.**";
            const int    taggerTime  = 1218123387;

            var body = new StringBuilder();

            body.Append("object ");
            body.Append(treeId.Name);
            body.Append("\n");

            body.Append("type tree\n");

            body.Append("tag ");
            body.Append(name);
            body.Append("\n");

            body.Append("tagger ");
            body.Append(taggerName);
            body.Append(" <");
            body.Append(taggerEmail);
            body.Append("> ");
            body.Append(taggerTime);
            body.Append(" +0700\n");

            body.Append("\n");

            var rw = new Core.RevWalk.RevWalk(db);

            var c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));

            Assert.IsNull(c.getObject());
            Assert.IsNull(c.getTagName());

            c.parseCanonical(rw, body.ToString().getBytes("UTF-8"));
            Assert.IsNotNull(c.getObject());
            Assert.AreEqual(treeId, c.getObject().getId());
            Assert.AreSame(rw.lookupTree(treeId), c.getObject());

            Assert.IsNotNull(c.getTagName());
            Assert.AreEqual(name, c.getTagName());
            Assert.AreEqual(string.Empty, c.getFullMessage());

            PersonIdent cTagger = c.getTaggerIdent();

            Assert.IsNotNull(cTagger);
            Assert.AreEqual(taggerName, cTagger.Name);
            Assert.AreEqual(taggerEmail, cTagger.EmailAddress);
        }
Esempio n. 3
0
        private void Want(RevObject o)
        {
            if (o.has(WANT))
            {
                return;
            }

            o.add(WANT);
            _wantAll.Add(o);

            RevTag oTag = (o as RevTag);

            while (oTag != null)
            {
                o    = oTag.getObject();
                oTag = (o as RevTag);
            }

            RevCommit oComm = (o as RevCommit);

            if (oComm != null)
            {
                _wantCommits.Add(oComm);
            }
        }
Esempio n. 4
0
        public void testParseOldStyleNoTagger()
        {
            ObjectId treeId  = Id("9788669ad918b6fcce64af8882fc9a81cb6aba67");
            string   name    = "v1.2.3.4.5";
            string   message = "test\n"                                //
                               + "\n"                                  //
                               + "-----BEGIN PGP SIGNATURE-----\n"     //
                               + "Version: GnuPG v1.4.1 (GNU/Linux)\n" //
                               + "\n"                                  //
                               + "iD8DBQBC0b9oF3Y\n"                   //
                               + "-----END PGP SIGNATURE------n";

            var body = new StringBuilder();

            body.Append("object ");
            body.Append(treeId.Name);
            body.Append("\n");

            body.Append("type tree\n");

            body.Append("tag ");
            body.Append(name);
            body.Append("\n");
            body.Append("\n");
            body.Append(message);

            var    rw = new Core.RevWalk.RevWalk(db);
            RevTag c;

            c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
            Assert.IsNull(c.getObject());
            Assert.IsNull(c.getTagName());

            c.parseCanonical(rw, body.ToString().getBytes("UTF-8"));
            Assert.IsNotNull(c.getObject());
            Assert.AreEqual(treeId, c.getObject().getId());
            Assert.AreSame(rw.lookupTree(treeId), c.getObject());

            Assert.IsNotNull(c.getTagName());
            Assert.AreEqual(name, c.getTagName());
            Assert.AreEqual("test", c.getShortMessage());
            Assert.AreEqual(message, c.getFullMessage());

            Assert.IsNull(c.getTaggerIdent());
        }
Esempio n. 5
0
        private void testOneType(int typeCode)
        {
            ObjectId locId = Id("9788669ad918b6fcce64af8882fc9a81cb6aba67");
            var      b     = new StringBuilder();

            b.Append("object " + locId.Name + "\n");
            b.Append("type " + Constants.typeString(typeCode) + "\n");
            b.Append("tag v1.2.3.4.5\n");
            b.Append("tagger A U. Thor <*****@*****.**> 1218123387 +0700\n");
            b.Append("\n");

            var rw = new Core.RevWalk.RevWalk(db);

            var c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));

            Assert.IsNull(c.getObject());
            Assert.IsNull(c.getTagName());

            c.parseCanonical(rw, b.ToString().getBytes("UTF-8"));
            Assert.IsNotNull(c.getObject());
            Assert.AreEqual(locId, c.getObject().getId());
            Assert.AreSame(rw.lookupAny(locId, typeCode), c.getObject());
        }
Esempio n. 6
0
        /// <summary>
        /// Advertise one object is available using the magic <code>.have</code>.
        /// <para/>
        /// The magic <code>.have</code> advertisement is not available for fetching by a
        /// client, but can be used by a client when considering a delta base
        /// candidate before transferring data in a push. Within the record created
        /// by this method the ref name is simply the invalid string <code>.have</code>.
        /// </summary>
        /// <param name="id">
        /// identity of the object that is assumed to exist.
        /// </param>
        public void advertiseHave(AnyObjectId id)
        {
            RevObject obj = parseAnyOrNull(id);

            if (obj != null)
            {
                advertiseAnyOnce(obj, ".have");
            }

            RevTag rt = (obj as RevTag);

            if (rt != null)
            {
                advertiseAnyOnce(rt.getObject(), ".have");
            }
        }
Esempio n. 7
0
        private void advertiseTag(RevTag tag, string refName)
        {
            RevTag o = (tag as RevTag);

            do
            {
                RevTag target = (o.getObject() as RevTag);
                try
                {
                    _walk.parseHeaders(target);
                }
                catch (IOException)
                {
                    return;
                }
                target.add(ADVERTISED);
                o = target;
            } while (o != null);
            advertiseAny(tag.getObject(), refName);
        }
Esempio n. 8
0
        private void advertiseTag(RevTag tag, string refName)
        {
            RevObject o = tag;

            do
            {
                // Fully unwrap here so later on we have these already parsed.
                RevObject target = (((RevTag)o).getObject());
                try
                {
                    _walk.parseHeaders(target);
                }
                catch (IOException)
                {
                    return;
                }
                target.add(ADVERTISED);
                o = target;
            } while (o is RevTag);

            advertiseAny(tag.getObject(), refName);
        }
Esempio n. 9
0
        private void SendPack()
        {
            bool thin     = _options.Contains(OptionThinPack);
            bool progress = !_options.Contains(OptionNoProgress);
            bool sideband = _options.Contains(OptionSideBand) || _options.Contains(OptionSideBand64K);

            ProgressMonitor pm       = NullProgressMonitor.Instance;
            Stream          _packOut = _rawOut;

            if (sideband)
            {
                int bufsz = SideBandOutputStream.SMALL_BUF;
                if (_options.Contains(OptionSideBand64K))
                {
                    bufsz = SideBandOutputStream.MAX_BUF;
                }

                _packOut = new SideBandOutputStream(SideBandOutputStream.CH_DATA, bufsz, _rawOut);

                if (progress)
                {
                    pm = new SideBandProgressMonitor(new SideBandOutputStream(SideBandOutputStream.CH_PROGRESS, bufsz, _rawOut));
                }
            }

            var pw = new PackWriter(_db, pm, NullProgressMonitor.Instance)
            {
                DeltaBaseAsOffset = _options.Contains(OptionOfsDelta),
                Thin = thin
            };

            pw.preparePack(_wantAll, _commonBase);
            if (_options.Contains(OptionIncludeTag))
            {
                foreach (Ref r in _refs.Values)
                {
                    RevObject o;
                    try
                    {
                        o = _walk.parseAny(r.ObjectId);
                    }
                    catch (IOException)
                    {
                        continue;
                    }
                    RevTag t = (o as RevTag);
                    if (o.has(WANT) || (t == null))
                    {
                        continue;
                    }

                    if (!pw.willInclude(t) && pw.willInclude(t.getObject()))
                    {
                        pw.addObject(t);
                    }
                }
            }

            pw.writePack(_packOut);

            if (sideband)
            {
                _packOut.Flush();
                _pckOut.End();
            }
            else
            {
                _rawOut.Flush();
            }
        }