/// <exception cref="System.Exception"></exception>
        private static byte[] Entry(FileMode mode, string name, ObjectId id)
        {
            ByteArrayOutputStream @out = new ByteArrayOutputStream();

            mode.CopyTo(@out);
            @out.Write(' ');
            @out.Write(Constants.Encode(name));
            @out.Write(0);
            id.CopyRawTo(@out);
            return(@out.ToByteArray());
        }
示例#2
0
        /// <exception cref="System.IO.IOException"></exception>
        private void FormatHeader(ByteArrayOutputStream o, DiffEntry ent)
        {
            DiffEntry.ChangeType type = ent.GetChangeType();
            string   oldp             = ent.GetOldPath();
            string   newp             = ent.GetNewPath();
            FileMode oldMode          = ent.GetOldMode();
            FileMode newMode          = ent.GetNewMode();

            o.Write(Constants.EncodeASCII("diff --git "));
            o.Write(Constants.Encode(QuotePath(oldPrefix + (type == DiffEntry.ChangeType.ADD ?
                                                            newp : oldp))));
            o.Write(' ');
            o.Write(Constants.Encode(QuotePath(newPrefix + (type == DiffEntry.ChangeType.DELETE
                                           ? oldp : newp))));
            o.Write('\n');
            switch (type)
            {
            case DiffEntry.ChangeType.ADD:
            {
                o.Write(Constants.EncodeASCII("new file mode "));
                newMode.CopyTo(o);
                o.Write('\n');
                break;
            }

            case DiffEntry.ChangeType.DELETE:
            {
                o.Write(Constants.EncodeASCII("deleted file mode "));
                oldMode.CopyTo(o);
                o.Write('\n');
                break;
            }

            case DiffEntry.ChangeType.RENAME:
            {
                o.Write(Constants.EncodeASCII("similarity index " + ent.GetScore() + "%"));
                o.Write('\n');
                o.Write(Constants.Encode("rename from " + QuotePath(oldp)));
                o.Write('\n');
                o.Write(Constants.Encode("rename to " + QuotePath(newp)));
                o.Write('\n');
                break;
            }

            case DiffEntry.ChangeType.COPY:
            {
                o.Write(Constants.EncodeASCII("similarity index " + ent.GetScore() + "%"));
                o.Write('\n');
                o.Write(Constants.Encode("copy from " + QuotePath(oldp)));
                o.Write('\n');
                o.Write(Constants.Encode("copy to " + QuotePath(newp)));
                o.Write('\n');
                if (!oldMode.Equals(newMode))
                {
                    o.Write(Constants.EncodeASCII("new file mode "));
                    newMode.CopyTo(o);
                    o.Write('\n');
                }
                break;
            }

            case DiffEntry.ChangeType.MODIFY:
            {
                if (0 < ent.GetScore())
                {
                    o.Write(Constants.EncodeASCII("dissimilarity index " + (100 - ent.GetScore()) + "%"
                                                  ));
                    o.Write('\n');
                }
                break;
            }
            }
            if ((type == DiffEntry.ChangeType.MODIFY || type == DiffEntry.ChangeType.RENAME) &&
                !oldMode.Equals(newMode))
            {
                o.Write(Constants.EncodeASCII("old mode "));
                oldMode.CopyTo(o);
                o.Write('\n');
                o.Write(Constants.EncodeASCII("new mode "));
                newMode.CopyTo(o);
                o.Write('\n');
            }
            if (!ent.GetOldId().Equals(ent.GetNewId()))
            {
                FormatIndexLine(o, ent);
            }
        }
 private static byte[] Entry(FileMode mode, string name, AnyObjectId id)
 {
     var @out = new MemoryStream();
     mode.CopyTo(@out);
     @out.WriteByte((byte) ' ');
     byte[] bytes = Constants.encode(name);
     @out.Write(bytes, 0, bytes.Length);
     @out.WriteByte(0);
     id.copyRawTo(@out);
     return @out.ToArray();
 }