Пример #1
0
 public override void Run()
 {
     try
     {
         ReceivePack rp = this._enclosing._enclosing.CreateReceivePack(dst);
         rp.Receive(out_r, in_w, System.Console.OpenStandardError());
     }
     catch (IOException)
     {
     }
     catch (RuntimeException)
     {
     }
     finally
     {
         try
         {
             out_r.Close();
         }
         catch (IOException)
         {
         }
         try
         {
             in_w.Close();
         }
         catch (IOException)
         {
         }
         dst.Close();
     }
 }
Пример #2
0
 public override void OnPreReceive(ReceivePack rp, ICollection <ReceiveCommand> commands
                                   )
 {
     for (int i = 0; i < count; i++)
     {
         hooks[i].OnPreReceive(rp, commands);
     }
 }
Пример #3
0
 public override void AdvertiseReceivePack(Stream output)
 {
     using (var repository = GetRepository())
     {
         var pack = new ReceivePack(repository);
         pack.SendAdvertisedRefs(new RefAdvertiser.PacketLineOutRefAdvertiser(new PacketLineOut(output)));
     }
 }
            /// <exception cref="System.IO.IOException"></exception>
            /// <exception cref="NGit.Transport.Resolver.ServiceNotEnabledException"></exception>
            /// <exception cref="NGit.Transport.Resolver.ServiceNotAuthorizedException"></exception>
            internal override void Execute(DaemonClient dc, Repository db)
            {
                ReceivePack  rp   = this._enclosing.receivePackFactory.Create(dc, db);
                InputStream  @in  = dc.GetInputStream();
                OutputStream @out = dc.GetOutputStream();

                rp.Receive(@in, @out, null);
            }
Пример #5
0
            internal override ReceivePack CreateReceivePack(Repository db)
            {
                db.Close();
                this._enclosing.dst.IncrementOpen();
                ReceivePack rp = base.CreateReceivePack(this._enclosing.dst);

                rp.SetRefFilter(new ReceivePackRefFilterTest.HidePrivateFilter());
                return(rp);
            }
            internal override ReceivePack CreateReceivePack(Repository db)
            {
                db.Close();
                this._enclosing.dst.IncrementOpen();
                ReceivePack rp = base.CreateReceivePack(this._enclosing.dst);

                rp.SetAdvertiseRefsHook(new ReceivePackAdvertiseRefsHookTest.HidePrivateHook());
                return(rp);
            }
Пример #7
0
 public override void Receive(Stream inputStream, Stream outputStream)
 {
     using (var repository = GetRepository())
     {
         var pack = new ReceivePack(repository);
         pack.SetBiDirectionalPipe(false);
         pack.Receive(inputStream, outputStream, outputStream);
     }
 }
        public virtual void TestUsingHiddenDeltaBaseFails()
        {
            byte[] delta = new byte[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked (
                                            (int)(0x1)), (byte)('c') };
            TestRepository <Repository> s = new TestRepository <Repository>(src);
            RevCommit N = s.Commit().Parent(B).Add("q", s.Blob(BinaryDelta.Apply(dst.Open(b).
                                                                                 GetCachedBytes(), delta))).Create();

            TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
            PackHeader(pack, 3);
            Copy(pack, src.Open(N));
            Copy(pack, src.Open(s.ParseBody(N).Tree));
            pack.Write((Constants.OBJ_REF_DELTA) << 4 | 4);
            b.CopyRawTo(pack);
            Deflate(pack, delta);
            Digest(pack);
            TemporaryBuffer.Heap inBuf     = new TemporaryBuffer.Heap(1024);
            PacketLineOut        inPckLine = new PacketLineOut(inBuf);

            inPckLine.WriteString(ObjectId.ZeroId.Name + ' ' + N.Name + ' ' + "refs/heads/s"
                                  + '\0' + BasePackPushConnection.CAPABILITY_REPORT_STATUS);
            inPckLine.End();
            pack.WriteTo(inBuf, PM);
            TemporaryBuffer.Heap outBuf = new TemporaryBuffer.Heap(1024);
            ReceivePack          rp     = new ReceivePack(dst);

            rp.SetCheckReceivedObjects(true);
            rp.SetCheckReferencedObjectsAreReachable(true);
            rp.SetAdvertiseRefsHook(new ReceivePackAdvertiseRefsHookTest.HidePrivateHook());
            try
            {
                Receive(rp, inBuf, outBuf);
                NUnit.Framework.Assert.Fail("Expected UnpackException");
            }
            catch (UnpackException failed)
            {
                Exception err = failed.InnerException;
                NUnit.Framework.Assert.IsTrue(err is MissingObjectException);
                MissingObjectException moe = (MissingObjectException)err;
                NUnit.Framework.Assert.AreEqual(b, moe.GetObjectId());
            }
            PacketLineIn r      = AsPacketLineIn(outBuf);
            string       master = r.ReadString();
            int          nul    = master.IndexOf('\0');

            NUnit.Framework.Assert.IsTrue(nul > 0, "has capability list");
            NUnit.Framework.Assert.AreEqual(B.Name + ' ' + R_MASTER, Sharpen.Runtime.Substring
                                                (master, 0, nul));
            NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString());
            NUnit.Framework.Assert.AreEqual("unpack error Missing blob " + b.Name, r.ReadString
                                                ());
            NUnit.Framework.Assert.AreEqual("ng refs/heads/s n/a (unpacker error)", r.ReadString
                                                ());
            NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString());
        }
        public virtual void TestUsingUnknownBlobFails()
        {
            // Try to use the 'n' blob that is not on the server.
            //
            TestRepository <Repository> s = new TestRepository <Repository>(src);
            RevBlob   n = s.Blob("n");
            RevCommit N = s.Commit().Parent(B).Add("q", n).Create();

            // But don't include it in the pack.
            //
            TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
            PackHeader(pack, 2);
            Copy(pack, src.Open(N));
            Copy(pack, src.Open(s.ParseBody(N).Tree));
            Digest(pack);
            TemporaryBuffer.Heap inBuf     = new TemporaryBuffer.Heap(1024);
            PacketLineOut        inPckLine = new PacketLineOut(inBuf);

            inPckLine.WriteString(ObjectId.ZeroId.Name + ' ' + N.Name + ' ' + "refs/heads/s"
                                  + '\0' + BasePackPushConnection.CAPABILITY_REPORT_STATUS);
            inPckLine.End();
            pack.WriteTo(inBuf, PM);
            TemporaryBuffer.Heap outBuf = new TemporaryBuffer.Heap(1024);
            ReceivePack          rp     = new ReceivePack(dst);

            rp.SetCheckReceivedObjects(true);
            rp.SetCheckReferencedObjectsAreReachable(true);
            rp.SetAdvertiseRefsHook(new ReceivePackAdvertiseRefsHookTest.HidePrivateHook());
            try
            {
                Receive(rp, inBuf, outBuf);
                NUnit.Framework.Assert.Fail("Expected UnpackException");
            }
            catch (UnpackException failed)
            {
                Exception err = failed.InnerException;
                NUnit.Framework.Assert.IsTrue(err is MissingObjectException);
                MissingObjectException moe = (MissingObjectException)err;
                NUnit.Framework.Assert.AreEqual(n, moe.GetObjectId());
            }
            PacketLineIn r      = AsPacketLineIn(outBuf);
            string       master = r.ReadString();
            int          nul    = master.IndexOf('\0');

            NUnit.Framework.Assert.IsTrue(nul > 0, "has capability list");
            NUnit.Framework.Assert.AreEqual(B.Name + ' ' + R_MASTER, Sharpen.Runtime.Substring
                                                (master, 0, nul));
            NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString());
            NUnit.Framework.Assert.AreEqual("unpack error Missing blob " + n.Name, r.ReadString
                                                ());
            NUnit.Framework.Assert.AreEqual("ng refs/heads/s n/a (unpacker error)", r.ReadString
                                                ());
            NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString());
        }
            /// <exception cref="NGit.Transport.Resolver.ServiceNotEnabledException"></exception>
            /// <exception cref="NGit.Transport.Resolver.ServiceNotAuthorizedException"></exception>
            public override ReceivePack Create(DaemonClient req, Repository db)
            {
                ReceivePack rp   = new ReceivePack(db);
                IPAddress   peer = req.GetRemoteAddress();
                string      host = peer.ToString();

                if (host == null)
                {
                    host = peer.GetHostAddress();
                }
                string name  = "anonymous";
                string email = name + "@" + host;

                rp.SetRefLogIdent(new PersonIdent(name, email));
                rp.SetTimeout(this._enclosing.GetTimeout());
                return(rp);
            }
        public virtual void TestCreateBranchAtHiddenCommitFails()
        {
            TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(64);
            PackHeader(pack, 0);
            Digest(pack);
            TemporaryBuffer.Heap inBuf     = new TemporaryBuffer.Heap(256);
            PacketLineOut        inPckLine = new PacketLineOut(inBuf);

            inPckLine.WriteString(ObjectId.ZeroId.Name + ' ' + P.Name + ' ' + "refs/heads/s"
                                  + '\0' + BasePackPushConnection.CAPABILITY_REPORT_STATUS);
            inPckLine.End();
            pack.WriteTo(inBuf, PM);
            TemporaryBuffer.Heap outBuf = new TemporaryBuffer.Heap(1024);
            ReceivePack          rp     = new ReceivePack(dst);

            rp.SetCheckReceivedObjects(true);
            rp.SetCheckReferencedObjectsAreReachable(true);
            rp.SetAdvertiseRefsHook(new ReceivePackAdvertiseRefsHookTest.HidePrivateHook());
            try
            {
                Receive(rp, inBuf, outBuf);
                NUnit.Framework.Assert.Fail("Expected UnpackException");
            }
            catch (UnpackException failed)
            {
                Exception err = failed.InnerException;
                NUnit.Framework.Assert.IsTrue(err is MissingObjectException);
                MissingObjectException moe = (MissingObjectException)err;
                NUnit.Framework.Assert.AreEqual(P, moe.GetObjectId());
            }
            PacketLineIn r      = AsPacketLineIn(outBuf);
            string       master = r.ReadString();
            int          nul    = master.IndexOf('\0');

            NUnit.Framework.Assert.IsTrue(nul > 0, "has capability list");
            NUnit.Framework.Assert.AreEqual(B.Name + ' ' + R_MASTER, Sharpen.Runtime.Substring
                                                (master, 0, nul));
            NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString());
            NUnit.Framework.Assert.AreEqual("unpack error Missing commit " + P.Name, r.ReadString
                                                ());
            NUnit.Framework.Assert.AreEqual("ng refs/heads/s n/a (unpacker error)", r.ReadString
                                                ());
            NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString());
        }
		public virtual void TestUsingHiddenDeltaBaseFails()
		{
			byte[] delta = new byte[] { unchecked((int)(0x1)), unchecked((int)(0x1)), unchecked(
				(int)(0x1)), (byte)('c') };
			TestRepository<Repository> s = new TestRepository<Repository>(src);
			RevCommit N = s.Commit().Parent(B).Add("q", s.Blob(BinaryDelta.Apply(dst.Open(b).
				GetCachedBytes(), delta))).Create();
			TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
			PackHeader(pack, 3);
			Copy(pack, src.Open(N));
			Copy(pack, src.Open(s.ParseBody(N).Tree));
			pack.Write((Constants.OBJ_REF_DELTA) << 4 | 4);
			b.CopyRawTo(pack);
			Deflate(pack, delta);
			Digest(pack);
			TemporaryBuffer.Heap inBuf = new TemporaryBuffer.Heap(1024);
			PacketLineOut inPckLine = new PacketLineOut(inBuf);
			inPckLine.WriteString(ObjectId.ZeroId.Name + ' ' + N.Name + ' ' + "refs/heads/s" 
				+ '\0' + BasePackPushConnection.CAPABILITY_REPORT_STATUS);
			inPckLine.End();
			pack.WriteTo(inBuf, PM);
			TemporaryBuffer.Heap outBuf = new TemporaryBuffer.Heap(1024);
			ReceivePack rp = new ReceivePack(dst);
			rp.SetCheckReceivedObjects(true);
			rp.SetCheckReferencedObjectsAreReachable(true);
			rp.SetAdvertiseRefsHook(new ReceivePackAdvertiseRefsHookTest.HidePrivateHook());
			try
			{
				Receive(rp, inBuf, outBuf);
				NUnit.Framework.Assert.Fail("Expected UnpackException");
			}
			catch (UnpackException failed)
			{
				Exception err = failed.InnerException;
				NUnit.Framework.Assert.IsTrue(err is MissingObjectException);
				MissingObjectException moe = (MissingObjectException)err;
				NUnit.Framework.Assert.AreEqual(b, moe.GetObjectId());
			}
			PacketLineIn r = AsPacketLineIn(outBuf);
			string master = r.ReadString();
			int nul = master.IndexOf('\0');
			NUnit.Framework.Assert.IsTrue(nul > 0, "has capability list");
			NUnit.Framework.Assert.AreEqual(B.Name + ' ' + R_MASTER, Sharpen.Runtime.Substring
				(master, 0, nul));
			NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString());
			NUnit.Framework.Assert.AreEqual("unpack error Missing blob " + b.Name, r.ReadString
				());
			NUnit.Framework.Assert.AreEqual("ng refs/heads/s n/a (unpacker error)", r.ReadString
				());
			NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString());
		}
Пример #13
0
 // Do nothing.
 /// <summary>Invoked just before commands are executed.</summary>
 /// <remarks>
 /// Invoked just before commands are executed.
 /// <p>
 /// See the class description for how this method can impact execution.
 /// </remarks>
 /// <param name="rp">
 /// the process handling the current receive. Hooks may obtain
 /// details about the destination repository through this handle.
 /// </param>
 /// <param name="commands">
 /// unmodifiable set of valid commands still pending execution.
 /// May be the empty set.
 /// </param>
 public abstract void OnPreReceive(ReceivePack rp, ICollection <ReceiveCommand> commands
                                   );
 public _Reporter_192(ReceivePack _enclosing)
 {
     this._enclosing = _enclosing;
 }
Пример #15
0
 public override void OnPreReceive(ReceivePack rp, ICollection <ReceiveCommand> commands
                                   )
 {
 }
Пример #16
0
			/// <exception cref="System.IO.IOException"></exception>
			internal override void Execute(DaemonClient dc, Repository db)
			{
				IPAddress peer = dc.GetRemoteAddress();
				string host = peer.ToString();
				if (host == null)
				{
					host = peer.GetHostAddress();
				}
				ReceivePack rp = new ReceivePack(db);
				InputStream @in = dc.GetInputStream();
				string name = "anonymous";
				string email = name + "@" + host;
				rp.SetRefLogIdent(new PersonIdent(name, email));
				rp.SetTimeout(this._enclosing.GetTimeout());
				rp.Receive(@in, dc.GetOutputStream(), null);
			}
 /// <exception cref="System.IO.IOException"></exception>
 private void Receive(ReceivePack rp, TemporaryBuffer.Heap inBuf, TemporaryBuffer.Heap
                      outBuf)
 {
     rp.Receive(new ByteArrayInputStream(inBuf.ToByteArray()), outBuf, null);
 }
Пример #18
0
 public _Reporter_229(ReceivePack _enclosing)
 {
     this._enclosing = _enclosing;
 }
Пример #19
0
        /// <summary>Execute this command during a receive-pack session.</summary>
        /// <remarks>
        /// Execute this command during a receive-pack session.
        /// <p/>
        /// Sets the status of the command as a side effect.
        /// </remarks>
        /// <param name="rp">receive-pack session.</param>
        public virtual void Execute(ReceivePack rp)
        {
            try
            {
                RefUpdate ru = rp.GetRepository().UpdateRef(GetRefName());
                ru.SetRefLogIdent(rp.GetRefLogIdent());
                switch (GetType())
                {
                    case ReceiveCommand.Type.DELETE:
                    {
                        if (!ObjectId.ZeroId.Equals(GetOldId()))
                        {
                            // We can only do a CAS style delete if the client
                            // didn't bork its delete request by sending the
                            // wrong zero id rather than the advertised one.
                            //
                            ru.SetExpectedOldObjectId(GetOldId());
                        }
                        ru.SetForceUpdate(true);
                        SetResult(ru.Delete(rp.GetRevWalk()));
                        break;
                    }

                    case ReceiveCommand.Type.CREATE:
                    case ReceiveCommand.Type.UPDATE:
                    case ReceiveCommand.Type.UPDATE_NONFASTFORWARD:
                    {
                        ru.SetForceUpdate(rp.IsAllowNonFastForwards());
                        ru.SetExpectedOldObjectId(GetOldId());
                        ru.SetNewObjectId(GetNewId());
                        ru.SetRefLogMessage("push", true);
                        SetResult(ru.Update(rp.GetRevWalk()));
                        break;
                    }
                }
            }
            catch (IOException err)
            {
                SetResult(ReceiveCommand.Result.REJECTED_OTHER_REASON, MessageFormat.Format(JGitText
                    .Get().lockError, err.Message));
            }
        }
Пример #20
0
 // Do nothing.
 public override void AdvertiseRefs(ReceivePack receivePack)
 {
 }
Пример #21
0
 /// <summary>Advertise refs for receive-pack.</summary>
 /// <remarks>Advertise refs for receive-pack.</remarks>
 /// <param name="receivePack">
 /// instance on which to call
 /// <see cref="ReceivePack.SetAdvertisedRefs(System.Collections.Generic.IDictionary{K, V}, System.Collections.Generic.ICollection{E})
 /// 	">ReceivePack.SetAdvertisedRefs(System.Collections.Generic.IDictionary&lt;K, V&gt;, System.Collections.Generic.ICollection&lt;E&gt;)
 /// 	</see>
 /// if necessary.
 /// </param>
 /// <exception cref="ServiceMayNotContinueException">abort; the message will be sent to the user.
 /// 	</exception>
 /// <exception cref="NGit.Transport.ServiceMayNotContinueException"></exception>
 public abstract void AdvertiseRefs(ReceivePack receivePack);
		public virtual void TestUsingUnknownTreeFails()
		{
			TestRepository<Repository> s = new TestRepository<Repository>(src);
			RevCommit N = s.Commit().Parent(B).Add("q", s.Blob("a")).Create();
			RevTree t = s.ParseBody(N).Tree;
			// Don't include the tree in the pack.
			//
			TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024);
			PackHeader(pack, 1);
			Copy(pack, src.Open(N));
			Digest(pack);
			TemporaryBuffer.Heap inBuf = new TemporaryBuffer.Heap(1024);
			PacketLineOut inPckLine = new PacketLineOut(inBuf);
			inPckLine.WriteString(ObjectId.ZeroId.Name + ' ' + N.Name + ' ' + "refs/heads/s" 
				+ '\0' + BasePackPushConnection.CAPABILITY_REPORT_STATUS);
			inPckLine.End();
			pack.WriteTo(inBuf, PM);
			TemporaryBuffer.Heap outBuf = new TemporaryBuffer.Heap(1024);
			ReceivePack rp = new ReceivePack(dst);
			rp.SetCheckReceivedObjects(true);
			rp.SetCheckReferencedObjectsAreReachable(true);
			rp.SetAdvertiseRefsHook(new ReceivePackAdvertiseRefsHookTest.HidePrivateHook());
			try
			{
				Receive(rp, inBuf, outBuf);
				NUnit.Framework.Assert.Fail("Expected UnpackException");
			}
			catch (UnpackException failed)
			{
				Exception err = failed.InnerException;
				NUnit.Framework.Assert.IsTrue(err is MissingObjectException);
				MissingObjectException moe = (MissingObjectException)err;
				NUnit.Framework.Assert.AreEqual(t, moe.GetObjectId());
			}
			PacketLineIn r = AsPacketLineIn(outBuf);
			string master = r.ReadString();
			int nul = master.IndexOf('\0');
			NUnit.Framework.Assert.IsTrue(nul > 0, "has capability list");
			NUnit.Framework.Assert.AreEqual(B.Name + ' ' + R_MASTER, Sharpen.Runtime.Substring
				(master, 0, nul));
			NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString());
			NUnit.Framework.Assert.AreEqual("unpack error Missing tree " + t.Name, r.ReadString
				());
			NUnit.Framework.Assert.AreEqual("ng refs/heads/s n/a (unpacker error)", r.ReadString
				());
			NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString());
		}
Пример #23
0
			public override void OnPostReceive(ReceivePack rp, ICollection<ReceiveCommand> commands
				)
			{
			}
		/// <exception cref="System.IO.IOException"></exception>
		private void Receive(ReceivePack rp, TemporaryBuffer.Heap inBuf, TemporaryBuffer.Heap
			 outBuf)
		{
			rp.Receive(new ByteArrayInputStream(inBuf.ToByteArray()), outBuf, null);
		}
		public virtual void TestCreateBranchAtHiddenCommitFails()
		{
			TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(64);
			PackHeader(pack, 0);
			Digest(pack);
			TemporaryBuffer.Heap inBuf = new TemporaryBuffer.Heap(256);
			PacketLineOut inPckLine = new PacketLineOut(inBuf);
			inPckLine.WriteString(ObjectId.ZeroId.Name + ' ' + P.Name + ' ' + "refs/heads/s" 
				+ '\0' + BasePackPushConnection.CAPABILITY_REPORT_STATUS);
			inPckLine.End();
			pack.WriteTo(inBuf, PM);
			TemporaryBuffer.Heap outBuf = new TemporaryBuffer.Heap(1024);
			ReceivePack rp = new ReceivePack(dst);
			rp.SetCheckReceivedObjects(true);
			rp.SetCheckReferencedObjectsAreReachable(true);
			rp.SetAdvertiseRefsHook(new ReceivePackAdvertiseRefsHookTest.HidePrivateHook());
			try
			{
				Receive(rp, inBuf, outBuf);
				NUnit.Framework.Assert.Fail("Expected UnpackException");
			}
			catch (UnpackException failed)
			{
				Exception err = failed.InnerException;
				NUnit.Framework.Assert.IsTrue(err is MissingObjectException);
				MissingObjectException moe = (MissingObjectException)err;
				NUnit.Framework.Assert.AreEqual(P, moe.GetObjectId());
			}
			PacketLineIn r = AsPacketLineIn(outBuf);
			string master = r.ReadString();
			int nul = master.IndexOf('\0');
			NUnit.Framework.Assert.IsTrue(nul > 0, "has capability list");
			NUnit.Framework.Assert.AreEqual(B.Name + ' ' + R_MASTER, Sharpen.Runtime.Substring
				(master, 0, nul));
			NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString());
			NUnit.Framework.Assert.AreEqual("unpack error Missing commit " + P.Name, r.ReadString
				());
			NUnit.Framework.Assert.AreEqual("ng refs/heads/s n/a (unpacker error)", r.ReadString
				());
			NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString());
		}
Пример #26
0
		// Do nothing.
		/// <summary>Invoked after all commands are executed and status has been returned.</summary>
		/// <remarks>Invoked after all commands are executed and status has been returned.</remarks>
		/// <param name="rp">
		/// the process handling the current receive. Hooks may obtain
		/// details about the destination repository through this handle.
		/// </param>
		/// <param name="commands">
		/// unmodifiable set of successfully completed commands. May be
		/// the empty set.
		/// </param>
		public abstract void OnPostReceive(ReceivePack rp, ICollection<ReceiveCommand> commands
			);