Exemple #1
0
        private int LineCallback(GitDiffDelta delta, GitDiffHunk hunk, GitDiffLine line, IntPtr payload)
        {
            string decodedContent = LaxUtf8Marshaler.FromNative(line.content, (int)line.contentLen);

            string prefix;

            switch (line.lineOrigin)
            {
            case GitDiffLineOrigin.GIT_DIFF_LINE_ADDITION:
                LinesAdded++;
                prefix = Encoding.ASCII.GetString(new[] { (byte)line.lineOrigin });
                break;

            case GitDiffLineOrigin.GIT_DIFF_LINE_DELETION:
                LinesDeleted++;
                prefix = Encoding.ASCII.GetString(new[] { (byte)line.lineOrigin });
                break;

            case GitDiffLineOrigin.GIT_DIFF_LINE_CONTEXT:
                prefix = Encoding.ASCII.GetString(new[] { (byte)line.lineOrigin });
                break;

            default:
                prefix = string.Empty;
                break;
            }

            AppendToPatch(prefix);
            AppendToPatch(decodedContent);
            return(0);
        }
        internal void AppendGitDiffLine(GitDiffLine line, string patch)
        {
            switch (line.lineOrigin)
            {
            case GitDiffLineOrigin.GIT_DIFF_LINE_ADDITION:
                AddedLines.Add(new Line(line.NewLineNo, patch));
                LinesAdded++;
                lines.Add(new ContentChangeLine(line));
                break;

            case GitDiffLineOrigin.GIT_DIFF_LINE_DELETION:
                DeletedLines.Add(new Line(line.OldLineNo, patch));
                LinesDeleted++;
                lines.Add(new ContentChangeLine(line));
                break;
            }
        }
Exemple #3
0
        private unsafe int PrintCallBack(git_diff_delta *delta, GitDiffHunk hunk, GitDiffLine line, IntPtr payload)
        {
            string patchPart = LaxUtf8Marshaler.FromNative(line.content, (int)line.contentLen);

            // Deleted files mean no "new file" path

            var pathPtr = delta->new_file.Path != null
                ? delta->new_file.Path
                : delta->old_file.Path;
            var filePath = LaxFilePathMarshaler.FromNative(pathPtr);

            PatchEntryChanges currentChange = this[filePath];
            string            prefix        = string.Empty;

            switch (line.lineOrigin)
            {
            case GitDiffLineOrigin.GIT_DIFF_LINE_CONTEXT:
                prefix = " ";
                break;

            case GitDiffLineOrigin.GIT_DIFF_LINE_ADDITION:
                linesAdded++;
                currentChange.LinesAdded++;
                currentChange.AddedLines.Add(new Line(line.NewLineNo, patchPart));
                prefix = "+";
                break;

            case GitDiffLineOrigin.GIT_DIFF_LINE_DELETION:
                linesDeleted++;
                currentChange.LinesDeleted++;
                currentChange.DeletedLines.Add(new Line(line.OldLineNo, patchPart));
                prefix = "-";
                break;
            }

            string formattedOutput = string.Concat(prefix, patchPart);

            fullPatchBuilder.Append(formattedOutput);
            currentChange.AppendToPatch(formattedOutput);

            return(0);
        }
 internal ContentChangeLine(GitDiffLine line)
 {
     OldLineNo = line.OldLineNo;
     NewLineNo = line.NewLineNo;
     NumLines  = line.NumLines;
 }