ptlis / diff-parser Goto Github PK
View Code? Open in Web Editor NEWA unified diff parser for PHP
License: MIT License
A unified diff parser for PHP
License: MIT License
Hello! Git generated diff:
diff --git a/file.php b/file.php
index 272b2e4..7a9961d 100644
--- a/file.php
+++ b/file.php
@@ -1,3 +1,6 @@
first line
second line
-third line
\ No newline at end of file
+third line
+fourth line
+
+some other line
Current file content:
first line
second line
third line
fourth line
some other line
Display line numbers:
use ptlis\DiffParser\Parser;
$parser = new Parser();
$changeset = $parser->parseFile('C:/server/projects/dev/master-protect/git-line.diff', Parser::VCS_GIT);
$files = $changeset->getFiles();
foreach ($files as $file) {
$hunks = $file->getHunks();
foreach ($hunks as $hunk) {
$lines = $hunk->getLines();
foreach ($lines as $line) {
echo 'getOriginalLineNo: ' . $line->getOriginalLineNo() . ' getNewLineNo: ' . $line->getNewLineNo() . ' ' . $line->getContent() . "\n";
}
}
}
Output:
getOriginalLineNo: 1 getNewLineNo: 1 first line
getOriginalLineNo: 2 getNewLineNo: 2 second line
getOriginalLineNo: 3 getNewLineNo: -1 third line
getOriginalLineNo: 4 getNewLineNo: 3 No newline at end of file
getOriginalLineNo: -1 getNewLineNo: 4 third line
getOriginalLineNo: -1 getNewLineNo: 5 fourth line
getOriginalLineNo: -1 getNewLineNo: 6
getOriginalLineNo: -1 getNewLineNo: 7 some other line
Why getNewLineNo() gets +1 for line number after "No newline at end of file"? I expected that "third line" is 3, "fourth line" is 4 and "some other line" is 6. Is this a mistake or do I understand something wrong?
This can be configured in git via git config diff.noprefix true
It's appear on windows system with git param core.autocrlf = true. Pattern HUNK_START_REGEX in one line helped
Would like to upgrade a project to PHP 8. Could you release a version that allows installing on PHP 8?
Hi, there is an issue in detecting file modification type.
I've tried with diff containing added, changed and removed files but all files are detected as changed. I think the major issue comes from the UnifiedDiffTokenizer
and the HUNK_START_REGEX
which isn't working with SVN 1.8.
Moreover there is also an issue with the latest SVN version (1.9) which uses (nonexistent) for new files, not (revision 0).
When parsing a SVN diff with a svn property change causes an undefined offset 0 error.
Example SVN diff.
Index: branches/7.0/trunk
===================================================================
--- branches/7.0/trunk (revision 115793)
+++ branches/7.0/trunk (revision 115794)
Property changes on: branches/7.0/trunk
___________________________________________________________________
Modified: svn:mergeinfo
Merged /branches/7.0/dev/7.3.3-5959:r115410-115793
Merged /branches/7.0/dev/7.3.2-5968:r115162-115780
------------------------------------------------------------------------
Your project used to support php 5.6 on version 0.6.0 currently master only supports php 7+ is it possible to create a new branch where php 5.6 is still supported I need to create a PR with a fix on it and my current project is in php 5.6 I will also create the PR against master so the fix is in both branches.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.