Exemple #1
0
        private static FileDiff ParseDiffHeader(IStringReader reader, ChangeSetDetail merge)
        {
            string fileName = ParseFileName(reader.ReadLine());
            bool   binary   = false;

            while (!reader.Done)
            {
                string line = reader.ReadLine();
                if (line.StartsWith("@@", StringComparison.Ordinal))
                {
                    reader.PutBack(line.Length);
                    break;
                }
                else if (line.StartsWith("GIT binary patch", StringComparison.Ordinal))
                {
                    binary = true;
                }
            }

            if (binary)
            {
                // Skip binary files
                reader.ReadToEnd();
            }

            var diff = new FileDiff(fileName)
            {
                Binary = binary
            };

            // Skip files from merged changesets
            if (merge != null && merge.Files.ContainsKey(fileName))
            {
                return(null);
            }

            return(diff);
        }
Exemple #2
0
        private static FileDiff ParseDiffHeader(IStringReader reader, ChangeSetDetail merge)
        {
            string fileName = ParseFileName(reader.ReadLine());
            bool binary = false;

            while (!reader.Done)
            {
                string line = reader.ReadLine();
                if (line.StartsWith("@@", StringComparison.Ordinal))
                {
                    reader.PutBack(line.Length);
                    break;
                }
                else if (line.StartsWith("GIT binary patch", StringComparison.Ordinal))
                {
                    binary = true;
                }
            }

            if (binary)
            {
                // Skip binary files
                reader.ReadToEnd();
            }

            var diff = new FileDiff(fileName)
            {
                Binary = binary
            };

            // Skip files from merged changesets
            if (merge != null && merge.Files.ContainsKey(fileName))
            {
                return null;
            }

            return diff;
        }
Exemple #3
0
        internal static FileDiff ParseDiffChunk(IStringReader reader, ref ChangeSetDetail merge)
        {
            var diff = ParseDiffHeader(reader, merge);

            if (diff == null)
            {
                return null;
            }

            // Current diff range
            DiffRange currentRange = null;
            int? leftCounter = null;
            int? rightCounter = null;

            // Parse the file diff
            while (!reader.Done)
            {
                int? currentLeft = null;
                int? currentRight = null;
                string line = reader.ReadLine();

                if (line.Equals(@"\ No newline at end of file", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                bool isDiffRange = line.StartsWith("@@", StringComparison.Ordinal);
                ChangeType? changeType = null;

                if (line.StartsWith("+", StringComparison.Ordinal))
                {
                    changeType = ChangeType.Added;
                    currentRight = ++rightCounter;
                    currentLeft = null;
                }
                else if (line.StartsWith("-", StringComparison.Ordinal))
                {
                    changeType = ChangeType.Deleted;
                    currentLeft = ++leftCounter;
                    currentRight = null;
                }
                else if (IsCommitHeader(line))
                {
                    reader.PutBack(line.Length);
                    merge = ParseCommitAndSummary(reader);
                }
                else
                {
                    if (!isDiffRange)
                    {
                        currentLeft = ++leftCounter;
                        currentRight = ++rightCounter;
                    }
                    changeType = ChangeType.None;
                }

                if (changeType != null)
                {
                    var lineDiff = new LineDiff(changeType.Value, line);
                    if (!isDiffRange)
                    {
                        lineDiff.LeftLine = currentLeft;
                        lineDiff.RightLine = currentRight;
                    }

                    diff.Lines.Add(lineDiff);
                }

                if (isDiffRange)
                {
                    // Parse the new diff range
                    currentRange = DiffRange.Parse(line.AsReader());
                    leftCounter = currentRange.LeftFrom - 1;
                    rightCounter = currentRange.RightFrom - 1;
                }
            }

            return diff;
        }
Exemple #4
0
        internal static FileDiff ParseDiffChunk(IStringReader reader, ref ChangeSetDetail merge)
        {
            var diff = ParseDiffHeader(reader, merge);

            if (diff == null)
            {
                return(null);
            }

            // Current diff range
            DiffRange currentRange = null;
            int?      leftCounter  = null;
            int?      rightCounter = null;

            // Parse the file diff
            while (!reader.Done)
            {
                int?   currentLeft  = null;
                int?   currentRight = null;
                string line         = reader.ReadLine();

                if (line.Equals(@"\ No newline at end of file", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                bool       isDiffRange = line.StartsWith("@@", StringComparison.Ordinal);
                ChangeType?changeType  = null;

                if (line.StartsWith("+", StringComparison.Ordinal))
                {
                    changeType   = ChangeType.Added;
                    currentRight = ++rightCounter;
                    currentLeft  = null;
                }
                else if (line.StartsWith("-", StringComparison.Ordinal))
                {
                    changeType   = ChangeType.Deleted;
                    currentLeft  = ++leftCounter;
                    currentRight = null;
                }
                else if (IsCommitHeader(line))
                {
                    reader.PutBack(line.Length);
                    merge = ParseCommitAndSummary(reader);
                }
                else
                {
                    if (!isDiffRange)
                    {
                        currentLeft  = ++leftCounter;
                        currentRight = ++rightCounter;
                    }
                    changeType = ChangeType.None;
                }

                if (changeType != null)
                {
                    var lineDiff = new LineDiff(changeType.Value, line);
                    if (!isDiffRange)
                    {
                        lineDiff.LeftLine  = currentLeft;
                        lineDiff.RightLine = currentRight;
                    }

                    diff.Lines.Add(lineDiff);
                }

                if (isDiffRange)
                {
                    // Parse the new diff range
                    currentRange = DiffRange.Parse(line.AsReader());
                    leftCounter  = currentRange.LeftFrom - 1;
                    rightCounter = currentRange.RightFrom - 1;
                }
            }

            return(diff);
        }