Emmayang7 / google-diff-match-patch

Automatically exported from code.google.com/p/google-diff-match-patch
Apache License 2.0
0 stars 0 forks source link

JavaScript: allow easy way to remove diff/match/patch sections #47

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
In browser-side JavaScript, file size matters a lot. It would be nice if there 
was a well-documented easy way to get rid of the code that wasn't needed for 
Match and Patch if all you care about is the Diff features, for instance.

Original issue reported on code.google.com by philfreo on 4 May 2011 at 10:01

GoogleCodeExporter commented 8 years ago
I can document the process I used a moment ago when I updated my "improved 
github diffs" user script 
(https://github.com/johan/github-improved/blob/master/better-diffs.user.js - or 
direct install link 
https://github.com/johan/github-improved/raw/master/better-diffs.user.js) a 
moment ago, which uses Neil's amazing diff backend without the match and patch 
parts:

 * replace all instances of "diff_match_patch" with "Diff" in javascript/diff_match_patch_uncompressed.js
 * remove all the code from //  MATCH FUNCTIONS to the end of the file
 * wrap the file between a "var Diff = (function(){" and "return new Diff; })()" (without the quotes)
 * prepend a little header comment annotating what revision it's based on, and linking to the source here

That's all. (Step 3 is only necessary if you want to keep identifier leakage to 
just the Diff object, it's really only the three DIFF_DELETE, DIFF_INSERT and 
DIFF_EQUAL constants.)

That said, it would be neat if the three portions were split up into a diff.js, 
a match.js and a patch.js (maybe a main.js too?) with a Makefile that 
recombines them back together into the current form;

Original comment by oyas...@gmail.com on 9 Jun 2011 at 12:55