Exemplo n.º 1
0
        /// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="NGit.Errors.CorruptObjectException"></exception>
        /// <exception cref="NGit.Errors.MissingObjectException"></exception>
        private DiffFormatter.FormatResult CreateFormatResult(DiffEntry ent)
        {
            DiffFormatter.FormatResult res = new DiffFormatter.FormatResult();
            ByteArrayOutputStream      buf = new ByteArrayOutputStream();
            EditList editList;

            FileHeader.PatchType type;
            FormatHeader(buf, ent);
            if (ent.GetOldMode() == FileMode.GITLINK || ent.GetNewMode() == FileMode.GITLINK)
            {
                FormatOldNewPaths(buf, ent);
                WriteGitLinkDiffText(buf, ent);
                editList = new EditList();
                type     = FileHeader.PatchType.UNIFIED;
            }
            else
            {
                AssertHaveRepository();
                byte[] aRaw = Open(DiffEntry.Side.OLD, ent);
                byte[] bRaw = Open(DiffEntry.Side.NEW, ent);
                if (aRaw == BINARY || bRaw == BINARY || RawText.IsBinary(aRaw) || RawText.IsBinary
                        (bRaw))
                {
                    //
                    FormatOldNewPaths(buf, ent);
                    buf.Write(Constants.EncodeASCII("Binary files differ\n"));
                    editList = new EditList();
                    type     = FileHeader.PatchType.BINARY;
                }
                else
                {
                    res.a    = new RawText(aRaw);
                    res.b    = new RawText(bRaw);
                    editList = Diff(res.a, res.b);
                    type     = FileHeader.PatchType.UNIFIED;
                    switch (ent.GetChangeType())
                    {
                    case DiffEntry.ChangeType.RENAME:
                    case DiffEntry.ChangeType.COPY:
                    {
                        if (!editList.IsEmpty())
                        {
                            FormatOldNewPaths(buf, ent);
                        }
                        break;
                    }

                    default:
                    {
                        FormatOldNewPaths(buf, ent);
                        break;
                        break;
                    }
                    }
                }
            }
            res.header = new FileHeader(buf.ToByteArray(), editList, type);
            return(res);
        }
Exemplo n.º 2
0
 /// <summary>Format a patch script for one file entry.</summary>
 /// <remarks>Format a patch script for one file entry.</remarks>
 /// <param name="ent">the entry to be formatted.</param>
 /// <exception cref="System.IO.IOException">
 /// a file's content cannot be read, or the output stream cannot
 /// be written to.
 /// </exception>
 public virtual void Format(DiffEntry ent)
 {
     DiffFormatter.FormatResult res = CreateFormatResult(ent);
     Format(res.header, res.a, res.b);
 }