Example #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);
        }
Example #2
0
        private void AddFileChange(GitDiffDelta delta)
        {
            var pathPtr     = delta.NewFile.Path != IntPtr.Zero ? delta.NewFile.Path : delta.OldFile.Path;
            var newFilePath = LaxFilePathMarshaler.FromNative(pathPtr);

            changes.Add(newFilePath, new ContentChanges(delta.IsBinary()));
        }
Example #3
0
        private int LineCallback(IntPtr data, GitDiffDelta delta, GitDiffRange range, GitDiffLineOrigin lineorigin, IntPtr content, uint contentlen)
        {
            string decodedContent = marshaler.NativeToString(content, contentlen);

            string prefix;

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

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

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

            default:
                prefix = string.Empty;
                break;
            }

            PatchBuilder.AppendFormat("{0}{1}", prefix, decodedContent);
            return(0);
        }
Example #4
0
        private int HunkCallback(GitDiffDelta delta, GitDiffRange range, IntPtr header, UIntPtr headerlen, IntPtr payload)
        {
            string decodedContent = Utf8Marshaler.FromNative(header, (int)headerlen);

            AppendToPatch(decodedContent);
            return(0);
        }
Example #5
0
        internal RepositoryStatus(Repository repo, StatusOptions options)
        {
            statusEntries = new List <StatusEntry>();

            using (GitStatusOptions coreOptions = CreateStatusOptions(options ?? new StatusOptions()))
                using (StatusListSafeHandle list = Proxy.git_status_list_new(repo.Handle, coreOptions))
                {
                    int count = Proxy.git_status_list_entrycount(list);

                    for (int i = 0; i < count; i++)
                    {
                        StatusEntrySafeHandle e     = Proxy.git_status_byindex(list, i);
                        GitStatusEntry        entry = e.MarshalAsGitStatusEntry();

                        GitDiffDelta deltaHeadToIndex    = null;
                        GitDiffDelta deltaIndexToWorkDir = null;

                        if (entry.HeadToIndexPtr != IntPtr.Zero)
                        {
                            deltaHeadToIndex = entry.HeadToIndexPtr.MarshalAs <GitDiffDelta>();
                        }
                        if (entry.IndexToWorkDirPtr != IntPtr.Zero)
                        {
                            deltaIndexToWorkDir = entry.IndexToWorkDirPtr.MarshalAs <GitDiffDelta>();
                        }

                        AddStatusEntryForDelta(entry.Status, deltaHeadToIndex, deltaIndexToWorkDir);
                    }

                    isDirty = statusEntries.Any(entry => entry.State != FileStatus.Ignored);
                }
        }
Example #6
0
        private int HunkCallback(IntPtr data, GitDiffDelta delta, GitDiffRange range, IntPtr header, uint headerlen)
        {
            string decodedContent = marshaler.NativeToString(header, headerlen);

            PatchBuilder.AppendFormat("{0}", decodedContent);
            return(0);
        }
Example #7
0
        private void AddFileChange(GitDiffDelta delta)
        {
            var treeEntryChanges = new TreeEntryChanges(delta);

            fileDispatcher[treeEntryChanges.Status](this, treeEntryChanges);
            changes.Add(treeEntryChanges.Path, treeEntryChanges);
        }
Example #8
0
        private TreeEntryChanges AddFileChange(GitDiffDelta delta, GitDiffLineOrigin lineorigin)
        {
            var newFilePath = FilePathMarshaler.FromNative(delta.NewFile.Path);

            if (lineorigin != GitDiffLineOrigin.GIT_DIFF_LINE_FILE_HDR)
            {
                return(this[newFilePath]);
            }

            var oldFilePath = FilePathMarshaler.FromNative(delta.OldFile.Path);
            var newMode     = (Mode)delta.NewFile.Mode;
            var oldMode     = (Mode)delta.OldFile.Mode;
            var newOid      = delta.NewFile.Oid;
            var oldOid      = delta.OldFile.Oid;

            if (delta.Status == ChangeKind.Untracked)
            {
                delta.Status = ChangeKind.Added;
            }

            var diffFile = new TreeEntryChanges(newFilePath, newMode, newOid, delta.Status, oldFilePath, oldMode, oldOid, delta.IsBinary());

            fileDispatcher[delta.Status](this, diffFile);
            changes.Add(newFilePath, diffFile);
            return(diffFile);
        }
Example #9
0
        private int HunkCallback(GitDiffDelta delta, GitDiffHunk hunk, IntPtr payload)
        {
            string decodedContent = LaxUtf8Marshaler.FromBuffer(hunk.Header, (int)hunk.HeaderLen);

            AppendToPatch(decodedContent);
            return(0);
        }
Example #10
0
        private int DataCallback(GitDiffDelta delta, GitDiffRange range, GitDiffLineOrigin lineOrigin, IntPtr content, UIntPtr contentLen, IntPtr payload)
        {
            var filePath = FilePathMarshaler.FromNative(delta.NewFile.Path);

            AddLineChange(this[filePath], lineOrigin);

            return(0);
        }
Example #11
0
        private int PrintCallBack(GitDiffDelta delta, GitDiffRange range, GitDiffLineOrigin lineorigin, IntPtr content, UIntPtr contentlen, IntPtr payload)
        {
            string formattedoutput = Utf8Marshaler.FromNative(content, (int)contentlen);
            var    filePath        = FilePathMarshaler.FromNative(delta.NewFile.Path);

            fullPatchBuilder.Append(formattedoutput);
            this[filePath].AppendToPatch(formattedoutput);

            return(0);
        }
Example #12
0
        private void AddFileChange(GitDiffDelta delta)
        {
            var newFilePath = (string)marshaler.MarshalNativeToManaged(delta.NewFile.Path);
            var oldFilePath = (string)marshaler.MarshalNativeToManaged(delta.OldFile.Path);
            var newMode     = (Mode)delta.NewFile.Mode;
            var oldMode     = (Mode)delta.OldFile.Mode;

            var diffFile = new TreeEntryChanges(newFilePath, newMode, delta.Status, oldFilePath, oldMode, ContentChanges.IsBinaryDelta(delta));

            fileDispatcher[delta.Status](this, diffFile);
            changes.Add(diffFile.Path, diffFile);
        }
Example #13
0
        private int FileCallback(GitDiffDelta delta, float progress, IntPtr payload)
        {
            IsBinaryComparison = delta.IsBinary();

            if (!IsBinaryComparison)
            {
                return(0);
            }

            AppendToPatch("Binary content differ\n");

            return(0);
        }
Example #14
0
        private int PrintCallBack(GitDiffDelta delta, GitDiffRange range, GitDiffLineOrigin lineorigin, IntPtr content, UIntPtr contentlen, IntPtr payload)
        {
            string formattedoutput = Utf8Marshaler.FromNative(content, (int)contentlen);

            TreeEntryChanges currentChange = AddFileChange(delta, lineorigin);

            AddLineChange(currentChange, lineorigin);

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

            return(0);
        }
Example #15
0
        private int FileCallback(IntPtr data, GitDiffDelta delta, float progress)
        {
            IsBinaryComparison = IsBinaryDelta(delta);

            if (!IsBinaryComparison)
            {
                return(0);
            }

            PatchBuilder.Append("Binary content differ\n");

            return(0);
        }
        internal TreeEntryChanges(GitDiffDelta delta)
        {
            Path    = LaxFilePathMarshaler.FromNative(delta.NewFile.Path).Native;
            OldPath = LaxFilePathMarshaler.FromNative(delta.OldFile.Path).Native;

            Mode    = (Mode)delta.NewFile.Mode;
            OldMode = (Mode)delta.OldFile.Mode;
            Oid     = delta.NewFile.Id;
            OldOid  = delta.OldFile.Id;

            Status = (delta.Status == ChangeKind.Untracked || delta.Status == ChangeKind.Ignored)
                ? ChangeKind.Added
                : delta.Status;
        }
        internal TreeEntryChanges(GitDiffDelta delta)
        {
            Path    = LaxFilePathMarshaler.FromNative(delta.NewFile.Path).Native;
            OldPath = LaxFilePathMarshaler.FromNative(delta.OldFile.Path).Native;

            Mode      = (Mode)delta.NewFile.Mode;
            OldMode   = (Mode)delta.OldFile.Mode;
            Oid       = delta.NewFile.Id;
            OldOid    = delta.OldFile.Id;
            Exists    = (delta.NewFile.Flags & GitDiffFlags.GIT_DIFF_FLAG_EXISTS) != 0;
            OldExists = (delta.OldFile.Flags & GitDiffFlags.GIT_DIFF_FLAG_EXISTS) != 0;

            Status = (delta.Status == ChangeKind.Untracked || delta.Status == ChangeKind.Ignored)
                ? ChangeKind.Added
                : delta.Status;
        }
        private void AddStatusEntryForDelta(FileStatus gitStatus, GitDiffDelta deltaHeadToIndex, GitDiffDelta deltaIndexToWorkDir)
        {
            RenameDetails headToIndexRenameDetails    = null;
            RenameDetails indexToWorkDirRenameDetails = null;

            if ((gitStatus & FileStatus.RenamedInIndex) == FileStatus.RenamedInIndex)
            {
                headToIndexRenameDetails =
                    new RenameDetails(LaxFilePathMarshaler.FromNative(deltaHeadToIndex.OldFile.Path).Native,
                                      LaxFilePathMarshaler.FromNative(deltaHeadToIndex.NewFile.Path).Native,
                                      (int)deltaHeadToIndex.Similarity);
            }

            if ((gitStatus & FileStatus.RenamedInWorkdir) == FileStatus.RenamedInWorkdir)
            {
                indexToWorkDirRenameDetails =
                    new RenameDetails(LaxFilePathMarshaler.FromNative(deltaIndexToWorkDir.OldFile.Path).Native,
                                      LaxFilePathMarshaler.FromNative(deltaIndexToWorkDir.NewFile.Path).Native,
                                      (int)deltaIndexToWorkDir.Similarity);
            }

            var filePath = (deltaIndexToWorkDir != null)
                ? LaxFilePathMarshaler.FromNative(deltaIndexToWorkDir.NewFile.Path).Native
                : LaxFilePathMarshaler.FromNative(deltaHeadToIndex.NewFile.Path).Native;

            StatusEntry statusEntry = new StatusEntry(filePath, gitStatus, headToIndexRenameDetails, indexToWorkDirRenameDetails);

            if (gitStatus == FileStatus.Unaltered)
            {
                unaltered.Add(statusEntry);
            }
            else
            {
                foreach (KeyValuePair <FileStatus, Action <RepositoryStatus, StatusEntry> > kvp in dispatcher)
                {
                    if (!gitStatus.HasFlag(kvp.Key))
                    {
                        continue;
                    }

                    kvp.Value(this, statusEntry);
                }
            }

            statusEntries.Add(statusEntry);
        }
Example #19
0
        private int PrintCallBack(IntPtr data, GitDiffDelta delta, GitDiffRange range, GitDiffLineOrigin lineorigin, IntPtr content, uint contentlen)
        {
            string formattedoutput = marshaler.NativeToString(content, contentlen);
            var    currentFilePath = (string)marshaler.MarshalNativeToManaged(delta.NewFile.Path);

            AddLineChange(currentFilePath, lineorigin);

            if (lineorigin == GitDiffLineOrigin.GIT_DIFF_LINE_FILE_HDR)
            {
                AddFileChange(delta);
            }

            changes[currentFilePath].PatchBuilder.Append(formattedoutput);
            fullPatchBuilder.Append(formattedoutput);

            return(0);
        }
Example #20
0
        private void AddFileChange(GitDiffDelta delta)
        {
            var newFilePath = FilePathMarshaler.FromNative(delta.NewFile.Path);

            var oldFilePath = FilePathMarshaler.FromNative(delta.OldFile.Path);
            var newMode     = (Mode)delta.NewFile.Mode;
            var oldMode     = (Mode)delta.OldFile.Mode;
            var newOid      = delta.NewFile.Oid;
            var oldOid      = delta.OldFile.Oid;

            if (delta.Status == ChangeKind.Untracked || delta.Status == ChangeKind.Ignored)
            {
                delta.Status = ChangeKind.Added;
            }

            var diffFile = new TreeEntryChanges(newFilePath, newMode, newOid, delta.Status, oldFilePath, oldMode, oldOid, delta.IsBinary());

            fileDispatcher[delta.Status](this, diffFile);
            changes.Add(newFilePath, diffFile);
        }
Example #21
0
        private int PrintCallBack(GitDiffDelta 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.NewFile.Path != IntPtr.Zero
                ? delta.NewFile.Path
                : delta.OldFile.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++;
                prefix = "+";
                break;

            case GitDiffLineOrigin.GIT_DIFF_LINE_DELETION:
                linesDeleted++;
                currentChange.LinesDeleted++;
                prefix = "-";
                break;
            }

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

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

            return(0);
        }
Example #22
0
        private void AddFileChange(GitDiffDelta delta)
        {
            var treeEntryChanges = new TreeEntryChanges(delta);

            changes.Add(treeEntryChanges.Path, new PatchEntryChanges(delta.IsBinary(), treeEntryChanges));
        }
Example #23
0
 private int FileCallback(GitDiffDelta delta, float progress, IntPtr payload)
 {
     AddFileChange(delta);
     return(0);
 }
Example #24
0
 internal static bool IsBinaryDelta(GitDiffDelta delta)
 {
     //TODO Fix the interop issue on amd64 and use GitDiffDelta.Binary
     return(delta.OldFile.Flags.Has(GitDiffFileFlags.GIT_DIFF_FILE_BINARY) || delta.NewFile.Flags.Has(GitDiffFileFlags.GIT_DIFF_FILE_BINARY));
 }
 public static bool IsBinary(this GitDiffDelta delta)
 {
     return(delta.Flags.HasFlag(GitDiffFlags.GIT_DIFF_FLAG_BINARY));
 }