Parse() 공개 메소드

Parse a patch received from an InputStream.
Parse a patch received from an InputStream.

Multiple parse calls on the same instance will concatenate the patch data, but each parse input must start with a valid file header (don't split a single file across parse calls).

there was an error reading from the input stream. ///
public Parse ( InputStream @is ) : void
@is Sharpen.InputStream
리턴 void
예제 #1
0
 /// <exception cref="System.IO.IOException"></exception>
 private NGit.Patch.Patch ParseTestPatchFile()
 {
     using (var @in = GetResourceStream())
     {
         NGit.Patch.Patch p = new NGit.Patch.Patch();
         p.Parse(@in);
         return(p);
     }
 }
예제 #2
0
        /// <exception cref="System.IO.IOException"></exception>
        private NGit.Patch.Patch ParseTestPatchFile(string patchFile)
        {
            InputStream @in = GetType().GetResourceAsStream(patchFile);

            if (@in == null)
            {
                NUnit.Framework.Assert.Fail("No " + patchFile + " test vector");
                return(null);
            }
            // Never happens
            try
            {
                NGit.Patch.Patch p = new NGit.Patch.Patch();
                p.Parse(@in);
                return(p);
            }
            finally
            {
                @in.Close();
            }
        }
예제 #3
0
		/// <exception cref="System.IO.IOException"></exception>
		private NGit.Patch.Patch ParseTestPatchFile(string patchFile)
		{
			InputStream @in = GetType().GetResourceAsStream(patchFile);
			if (@in == null)
			{
				NUnit.Framework.Assert.Fail("No " + patchFile + " test vector");
				return null;
			}
			// Never happens
			try
			{
				NGit.Patch.Patch p = new NGit.Patch.Patch();
				p.Parse(@in);
				return p;
			}
			finally
			{
				@in.Close();
			}
		}
예제 #4
0
        /// <summary>
        /// Executes the
        /// <code>ApplyCommand</code>
        /// command with all the options and
        /// parameters collected by the setter methods (e.g.
        /// <see cref="SetPatch(Sharpen.InputStream)">SetPatch(Sharpen.InputStream)</see>
        /// of this class. Each instance of this class
        /// should only be used for one invocation of the command. Don't call this
        /// method twice on an instance.
        /// </summary>
        /// <returns>
        /// an
        /// <see cref="ApplyResult">ApplyResult</see>
        /// object representing the command result
        /// </returns>
        /// <exception cref="NGit.Api.Errors.GitAPIException">NGit.Api.Errors.GitAPIException
        ///     </exception>
        /// <exception cref="NGit.Api.Errors.PatchFormatException">NGit.Api.Errors.PatchFormatException
        ///     </exception>
        /// <exception cref="NGit.Api.Errors.PatchApplyException">NGit.Api.Errors.PatchApplyException
        ///     </exception>
        public override ApplyResult Call()
        {
            CheckCallable();
            ApplyResult r = new ApplyResult();

            try
            {
                NGit.Patch.Patch p = new NGit.Patch.Patch();
                try
                {
                    p.Parse(@in);
                }
                finally
                {
                    @in.Close();
                }
                if (!p.GetErrors().IsEmpty())
                {
                    throw new PatchFormatException(p.GetErrors());
                }
                foreach (FileHeader fh in p.GetFiles())
                {
                    DiffEntry.ChangeType type = fh.GetChangeType();
                    FilePath             f    = null;
                    switch (type)
                    {
                    case DiffEntry.ChangeType.ADD:
                    {
                        f = GetFile(fh.GetNewPath(), true);
                        Apply(f, fh);
                        break;
                    }

                    case DiffEntry.ChangeType.MODIFY:
                    {
                        f = GetFile(fh.GetOldPath(), false);
                        Apply(f, fh);
                        break;
                    }

                    case DiffEntry.ChangeType.DELETE:
                    {
                        f = GetFile(fh.GetOldPath(), false);
                        if (!f.Delete())
                        {
                            throw new PatchApplyException(MessageFormat.Format(JGitText.Get().cannotDeleteFile
                                                                               , f));
                        }
                        break;
                    }

                    case DiffEntry.ChangeType.RENAME:
                    {
                        f = GetFile(fh.GetOldPath(), false);
                        FilePath dest = GetFile(fh.GetNewPath(), false);
                        if (!f.RenameTo(dest))
                        {
                            throw new PatchApplyException(MessageFormat.Format(JGitText.Get().renameFileFailed
                                                                               , f, dest));
                        }
                        break;
                    }

                    case DiffEntry.ChangeType.COPY:
                    {
                        f = GetFile(fh.GetOldPath(), false);
                        byte[]     bs = IOUtil.ReadFully(f);
                        FileWriter fw = new FileWriter(GetFile(fh.GetNewPath(), true));
                        fw.Write(Sharpen.Runtime.GetStringForBytes(bs));
                        fw.Close();
                        break;
                    }
                    }
                    r.AddUpdatedFile(f);
                }
            }
            catch (IOException e)
            {
                throw new PatchApplyException(MessageFormat.Format(JGitText.Get().patchApplyException
                                                                   , e.Message), e);
            }
            SetCallable(false);
            return(r);
        }
예제 #5
0
 private static Patch Parse(InputStream crlfStream)
 {
     NGit.Patch.Patch p = new Patch();
     p.Parse(crlfStream);
     return(p);
 }