X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=scripts%2Flib%2Fcocanwiki_diff.ml;h=92386862e0d95b668e171a2db3f945c8d7710a0a;hb=744ad347df455887349c683dd1c57af2b1ac0d28;hp=849a818f4a3cb3020e99525d3623344a8753a057;hpb=20923b33c08fccfca617b21935c4a4f6201593f8;p=cocanwiki.git diff --git a/scripts/lib/cocanwiki_diff.ml b/scripts/lib/cocanwiki_diff.ml index 849a818..9238686 100644 --- a/scripts/lib/cocanwiki_diff.ml +++ b/scripts/lib/cocanwiki_diff.ml @@ -1,7 +1,7 @@ (* COCANWIKI - a wiki written in Objective CAML. * Written by Richard W.M. Jones . * Copyright (C) 2004 Merjis Ltd. - * $Id: cocanwiki_diff.ml,v 1.1 2004/10/21 11:42:05 rich Exp $ + * $Id: cocanwiki_diff.ml,v 1.3 2004/11/01 12:57:53 rich Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,6 +25,7 @@ open Cgi open Printf open Cocanwiki_files +open Cocanwiki (* Convenience code for generating diffs between versions. See diff.ml * and edit.ml which both use this code. @@ -36,19 +37,46 @@ let page_for_diff css sections = content ^ "\n\n") sections)) ^ "CSS:\n\n" ^ css +let le_re = Pcre.regexp "\r?\n" +let le_subst = Pcre.subst "\n" + let diff_cmd old_page new_page = + (* Convert line-endings in the input files from \r\n to \n. Diff + * can get confused by the \r characters, particularly in side-by-side + * mode when asked to expand tabs (-y -t). + *) + let f = Pcre.replace ~rex:le_re ~itempl:le_subst in + let new_page = f new_page in + let old_page = f old_page in + let new_filename = output_tempfile new_page in let old_filename = output_tempfile old_page in - let cmd = sprintf "diff -u %s %s ||:" old_filename new_filename in + (* Side-by-side mode was good, but stupidly implemented. It's + * disabled right now. + *) + let diff_sidebyside = false in + + let options = + if not diff_sidebyside then + "-u" + else + "-y --left-column" in + let options = options ^ " -t -b -B" in + + let cmd = sprintf "diff %s %s %s ||:" options old_filename new_filename in let diff = pget cmd in + (* Remove the temporary files. *) + unlink new_filename; unlink old_filename; + let diff = - match diff with - _ :: _ :: diff -> diff - | diff -> diff in + if not diff_sidebyside then + match diff with + _ :: _ :: diff -> diff + | diff -> diff + else diff in - unlink new_filename; unlink old_filename; String.concat "\n" diff let get_version_for_diff (dbh : Dbi.connection) version = @@ -74,7 +102,7 @@ let get_version_for_diff (dbh : Dbi.connection) version = page ) -let get_diff (dbh : Dbi.connection) hostid page ?old_version ~version () = +let get_diff (dbh : Dbi.connection) hostid page ?old_version ~version ()= let old_version = match old_version with | Some version -> version