Jane Street

Open Source @ Jane Street

View on GitHub

patdiff example

patdiff is a tool which displays differences between two files. It uses the patience algorithm and display word-by-word diferrences when appropriate instead of just line differences. The full documentation is included in the distribution (repository). Following is an example of output, produced by the command:

$ patdiff writer.ml~109.07.00 writer.ml~109.08.00

The result:

---writer.ml~109.07.00
+++writer.ml~109.08.00
@@@@@@@@@@ -915,29 +915,24 @@@@@@@@@@
  let stderr = lazy (snd (Lazy.force stdout_and_stderr))
  
  let apply_umask perm =
    let umask = Core_unix.umask 0 in
    ignore (Core_unix.umask umask);
    perm land (lnot umask)
  ;;
  
-|let with_file_atomic ?temp_prefix ?perm ?fsync:(do_fsync = false) file ~f =
+|let with_file_atomic ?temp_file ?perm ?fsync:(do_fsync = false) file ~f =
    Async_sys.file_exists file
    >>= fun file_exists ->
    (match file_exists with
    | `Yes -> (Unix.stat file >>| fun stats -> Some stats.Unix.Stats.perm)
    | `No | `Unknown -> return None)
    >>= fun current_file_permissions ->
-|  let prefixed_temp_file =
-|    match temp_prefix with
-|    | None -> file
-|    | Some temp_prefix -> temp_prefix ^ file
-|  in
-|  Unix.mkstemp prefixed_temp_file
+|  Unix.mkstemp (Option.value temp_file ~default:file)
    >>= fun (temp_file, fd) ->
    let t = create fd in
    with_close t (fun () ->
      f t
      >>= fun result ->
      let new_permissions =
        match current_file_permissions with
        | None ->
@@@@@@@@@@ -958,34 +953,34 @@@@@@@@@@
    >>| function
      | Ok () -> result
      | Error exn ->
        don't_wait_for (Unix.unlink temp_file);
        failwiths "Writer.with_file_atomic could not create file"
          (file, exn) <:sexp_of< string * exn >>
  ;;
  
-|let save ?temp_prefix ?perm ?fsync file ~contents =
-|  with_file_atomic ?temp_prefix ?perm ?fsync file ~f:(fun t ->
+|let save ?temp_file ?perm ?fsync file ~contents =
+|  with_file_atomic ?temp_file ?perm ?fsync file ~f:(fun t ->
      write t contents;
      Deferred.unit)
  ;;
  
  let sexp_to_buffer ?(hum = true) ~buf sexp =
    if hum then
      Sexp.to_buffer_hum ~buf sexp
    else
      Sexp.to_buffer_mach ~buf sexp
  ;;
  
-|let save_sexp ?temp_prefix ?perm ?fsync ?hum file sexp =
+|let save_sexp ?temp_file ?perm ?fsync ?hum file sexp =
    let buf = Buffer.create 1 in
    sexp_to_buffer ?hum ~buf sexp;
    Buffer.add_char buf '\n';
-|  save ?temp_prefix ?perm ?fsync file ~contents:(Buffer.contents buf);
+|  save ?temp_file ?perm ?fsync file ~contents:(Buffer.contents buf);
  ;;
  
  let transfer t pipe_r write_f =
    let producers_to_flush_at_close_elt =
      Bag.add t.producers_to_flush_at_close (fun () ->
        Deferred.ignore (Pipe.upstream_flushed pipe_r))
    in
    let consumer =