Parse file's diff and perform some manipulations
use Arch::DiffParser; my $dp = Arch::DiffParser->new; # usable for "annotate" functionality my $changes = $dp->parse_file("f.diff")->changes; $dp->parse($diff_content); $dp->parse("--- f1.c\t2005-02-26\n+++ f2.c\t2005-02-28\n..."); # prints "f1.c, f2.c" printf "%s, %s\n", $dp->filename1, $dp->filename2; # enclose lines in <span class="patch_{mod,orig,line,add,del}"> my $html = $dp->markup_content;
This class provides a limited functionality to parse a single file diff in unified format. Multiple diffs may be parsed sequentially. The parsed data is stored for the last diff, and is replaced on the following parse.
The following class methods are available:
new, parse, parse_file, content, lines, filename1, filename2, mtime1, mtime2, hunks, changes.
Construct the \*(C`Arch::DiffParser\*(C' instanse.
Parse the diff_content and store its parsed data.
Like parse, but read the diff_content from diff_filename.
Return hashref containing certain parsed data. Die if called before any parse methods. The keys are: \*(L"lines\*(R", \*(L"filename1\*(R", \*(L"filename2\*(R", \*(L"mtime1\*(R", \*(L"mtime2\*(R", \*(L"hunks\*(R", \*(L"changes\*(R". The value of \*(L"hunks\*(R" and \*(L"changes\*(R" is arrayref of arrayrefs with 5 elements: [ line-number-1, num-lines-1, line-number-2, num-lines-2, \*(L"lines\*(R"-index ]. A \*(L"hunk\*(R" describes a set of lines containing some combination of unmodified, deleted and added lines, a \*(L"change\*(R" describes an inter-hunk atom that only contains zero or more deleted lines and zero or more added lines.
These methods are just shortcuts for diff_data->{method}. Return content of the last diff. %args keys are \*(L"fileroot1\*(R" and \*(L"fileroot2\*(R"; if given, these will replace the subdirs \*(L"orig\*(R" and \*(L"mod\*(R" that arch usually uses in the filepaths. Like content, but every non-context line is enclosed into markup <span class="patch_name">line</span>, where name is one of \*(L"orig\*(R" (filename1), \*(L"mod\*(R" (filename2), \*(L"line\*(R" (hunk linenums), \*(L"add\*(R" (added), del (deleted). Not implemented yet.
No support for newlines in source file names yet.
Mikhael Goikhman ([email protected]\*(--Perl-GPL/arch-perl\*(--devel).
For more information, see Text::Diff::Unified, Algorithm::Diff.