Beispiel #1
0
        public virtual int parseBody(Patch script, int end)
        {
            byte[] buf = _file.Buffer;
            int c = RawParseUtils.nextLF(buf, _startOffset), last = c;

            _oldImage.LinesDeleted = 0;
            _oldImage.LinesAdded = 0;

            for (; c < end; last = c, c = RawParseUtils.nextLF(buf, c))
            {
                bool breakScan;
                switch (buf[c])
                {
                    case (byte)' ':
                    case (byte)'\n':
                        LinesContext++;
                        continue;

                    case (byte)'-':
                        _oldImage.LinesDeleted++;
                        continue;

                    case (byte)'+':
                        _oldImage.LinesAdded++;
                        continue;

                    case (byte)'\\': // Matches "\ No newline at end of file"
                        continue;

                    default:
                        breakScan = true;
                        break;
                }

                if (breakScan)
                {
                    break;
                }
            }

            if (last < end && LinesContext + _oldImage.LinesDeleted - 1 == _oldImage.LineCount
                && LinesContext + _oldImage.LinesAdded == NewLineCount
                && RawParseUtils.match(buf, last, Patch.SigFooter) >= 0)
            {
                // This is an extremely common occurrence of "corruption".
                // Users add footers with their signatures After this mark,
                // and git diff adds the git executable version number.
                // Let it slide; the hunk otherwise looked sound.
                //
                _oldImage.LinesDeleted--;
                return last;
            }

            if (LinesContext + _oldImage.LinesDeleted < _oldImage.LineCount)
            {
                int missingCount = _oldImage.LineCount - (LinesContext + _oldImage.LinesDeleted);
                script.error(buf, _startOffset, "Truncated hunk, at least "
                                                + missingCount + " old lines is missing");
            }
            else if (LinesContext + _oldImage.LinesAdded < NewLineCount)
            {
                int missingCount = NewLineCount - (LinesContext + _oldImage.LinesAdded);
                script.error(buf, _startOffset, "Truncated hunk, at least "
                                                + missingCount + " new lines is missing");
            }
            else if (LinesContext + _oldImage.LinesDeleted > _oldImage.LineCount
                     || LinesContext + _oldImage.LinesAdded > NewLineCount)
            {
                string oldcnt = _oldImage.LineCount + ":" + NewLineCount;
                string newcnt = (LinesContext + _oldImage.LinesDeleted) + ":"
                                + (LinesContext + _oldImage.LinesAdded);
                script.warn(buf, _startOffset, "Hunk header " + oldcnt
                                               + " does not match body line count of " + newcnt);
            }

            return c;
        }
Beispiel #2
0
	    public int parseBody(Patch script, int end) {
		    byte[] buf = file.buf;
		    int c = RawParseUtils.nextLF(buf, startOffset), last = c;

		    old.nDeleted = 0;
		    old.nAdded = 0;

            bool break_scan = false;
		    for (; c < end; last = c, c = RawParseUtils.nextLF(buf, c))
            {
			    switch (buf[c])
                {
			    case (byte)' ':
			    case (byte)'\n':
				    nContext++;
				    continue;

			    case (byte)'-':
				    old.nDeleted++;
				    continue;

			    case (byte)'+':
				    old.nAdded++;
				    continue;

			    case (byte)'\\': // Matches "\ No newline at end of file"
				    continue;

			    default:
                    break_scan = true;
				    break;
			    }
                if (break_scan)
                    break;
		    }

		    if (last < end && nContext + old.nDeleted - 1 == old.lineCount
				    && nContext + old.nAdded == newLineCount
				    && RawParseUtils.match(buf, last, Patch.SIG_FOOTER) >= 0)
            {
			    // This is an extremely common occurrence of "corruption".
			    // Users add footers with their signatures after this mark,
			    // and git diff adds the git executable version number.
			    // Let it slide; the hunk otherwise looked sound.
			    //
			    old.nDeleted--;
			    return last;
		    }

		    if (nContext + old.nDeleted < old.lineCount)
            {
			    int missingCount = old.lineCount - (nContext + old.nDeleted);
			    script.error(buf, startOffset, "Truncated hunk, at least "
					    + missingCount + " old lines is missing");

		    }
            else if (nContext + old.nAdded < newLineCount)
            {
			    int missingCount = newLineCount - (nContext + old.nAdded);
			    script.error(buf, startOffset, "Truncated hunk, at least "
					    + missingCount + " new lines is missing");

		    }
            else if (nContext + old.nDeleted > old.lineCount
				    || nContext + old.nAdded > newLineCount)
            {
			    string oldcnt = old.lineCount + ":" + newLineCount;
			    string newcnt = (nContext + old.nDeleted) + ":"
					    + (nContext + old.nAdded);
			    script.warn(buf, startOffset, "Hunk header " + oldcnt
					    + " does not match body line count of " + newcnt);
		    }

		    return c;
	    }