Skip to content

Commit 25c14ff

Browse files
committed
plotgitsch: introduce --relative option
fix #50
1 parent 3ca2583 commit 25c14ff

File tree

5 files changed

+31
-20
lines changed

5 files changed

+31
-20
lines changed

plotkicadsch/src/gitFs.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ open DiffFs
44
exception InternalGitError of string
55
exception PathNotFound of string list
66

7-
let make commitish =
7+
let make commitish relative_path =
88
( module struct
99
open Git_unix
1010
module Search = Git.Search.Make (Digestif.SHA1) (Store)
@@ -26,7 +26,9 @@ let make commitish =
2626
try%lwt
2727
let%lwt _ = Lwt_unix.stat new_gitdir in
2828
(* that's a git repo and d is the root *)
29-
Lwt.return (d, b)
29+
Lwt.return (match relative_path with
30+
| None -> (d, b)
31+
| Some p -> (d, String.split_on_char ~sep:'/' p))
3032
with
3133
| UnixLabels.Unix_error (UnixLabels.ENOENT, _, _) ->
3234
let new_d = dirname d in

plotkicadsch/src/kicadDiff.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ let true_fs rootname = TrueFS rootname
1313

1414
type differ = Internal of string | Image_Diff
1515

16-
let fs_mod = function
17-
| GitFS r -> GitFs.make r
18-
| TrueFS r -> TrueFs.make r
16+
let fs_mod s r =
17+
match s with
18+
| GitFS s -> GitFs.make s r
19+
| TrueFS s -> TrueFs.make s r
1920

2021
let is_suffix ~suffix s =
2122
let suff_length = String.length suffix in
@@ -101,7 +102,7 @@ let diff_cmd f t filename =
101102
, [| fc ^ Filename.dir_sep ^ filename
102103
; tc ^ Filename.dir_sep ^ filename |] )
103104

104-
let doit from_fs to_fs file_to_diff differ textdiff libs keep colors zone_color allow_missing_component =
105+
let doit from_fs to_fs file_to_diff differ textdiff libs keep colors zone_color allow_missing_component relative_path =
105106
let module_d =
106107
match differ with
107108
| Image_Diff ->
@@ -110,8 +111,8 @@ let doit from_fs to_fs file_to_diff differ textdiff libs keep colors zone_color
110111
InternalDiff.internal_diff s colors zone_color
111112
in
112113
let module D = (val module_d : Differ) in
113-
let module F = (val (fs_mod from_fs) : Simple_FS) in
114-
let module T = (val (fs_mod to_fs) : Simple_FS) in
114+
let module F = (val (fs_mod from_fs relative_path) : Simple_FS) in
115+
let module T = (val (fs_mod to_fs relative_path) : Simple_FS) in
115116
let module FromP = FSPainter (D.S) (F) in
116117
let module ToP = FSPainter (D.S) (T) in
117118
let file_list =
@@ -147,7 +148,7 @@ let doit from_fs to_fs file_to_diff differ textdiff libs keep colors zone_color
147148
let catch_errors =
148149
Lwt.catch
149150
(fun _ ->
150-
Lwt_io.printf "%s between %s and %s\n" D.doc (doc from_fs) (doc to_fs)
151+
Lwt_io.printf "%s between %s and %s\n" D.doc (doc F.label) (doc T.label)
151152
>>= fun _ -> compare_all )
152153
(function
153154
| GitFs.InternalGitError s ->

plotkicadsch/src/kicadDiff.mli

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ val true_fs: string -> t
1616
(** [doc fs] outputs the doc string of the file system [fs] *)
1717
val doc: t -> string
1818

19-
(** [doit fs_from fs_to filename differ textdiff libs keep colors allow_missing]
20-
performs the diff of [filename] between [fs_from] and [fs_to]
19+
(** [doit fs_from fs_to filename differ textdiff libs keep colors allow_missing relative_path]
20+
performs the diff of [filename] from [relative_path] if present between [fs_from] and [fs_to]
2121
using strategy [differ] and using common [libs] and [colors]
2222
scheme. If [textdiff], then a text diff is shown when no visual
2323
diff, if [keep] then the diff file isn't removed after *)
2424
val doit: t -> t -> string option ->
2525
differ -> bool -> string list -> bool ->
26-
SvgPainter.diff_colors option -> string option -> bool -> unit
26+
SvgPainter.diff_colors option -> string option -> bool -> string option -> unit

plotkicadsch/src/plotgitsch.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,10 +158,16 @@ let zone_color =
158158
let env = Arg.env_var ~doc:"Color for plotting frames around changes" "PLOTGITSCH_CHANGE_COLOR" in
159159
Arg.(value & opt get_zone_color None & info ["z"; "zone"] ~env ~doc ~docv)
160160

161+
let relative_path =
162+
let doc =
163+
"force relative path to git working tree root. Detected automatically from current dir by default" in
164+
let docv = "path" in
165+
Arg.(value & opt (some string) None & info ["r"; "relative"] ~doc ~docv)
166+
161167
let plotgitsch_t =
162168
Term.(
163169
const doit $ from_ref $ to_ref $ diff_of_file $ internal_diff
164-
$ textual_diff $ preloaded_libs $ keep_files $ colors $ zone_color $ continue_on_missing_component)
170+
$ textual_diff $ preloaded_libs $ keep_files $ colors $ zone_color $ continue_on_missing_component $ relative_path)
165171

166172
let info =
167173
let doc =

plotkicadsch/src/trueFs.ml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ open StdLabels
22
open Lwt.Infix
33
open DiffFs
44

5-
let make rootname =
5+
let make rootname relative =
66
( module struct
77

8-
let label = TrueFS rootname
9-
108
let lstrip c s =
119
let rec find_non_c c s n =
1210
if s.[n] != c then
@@ -16,14 +14,18 @@ let make rootname =
1614
in
1715
find_non_c c s 0
1816

19-
let rootname = lstrip '/' rootname
17+
let rootname = (lstrip '/' rootname) ^ (match relative with
18+
| None -> ""
19+
| Some p -> "/" ^ (lstrip '/' p))
20+
21+
let label = TrueFS rootname
22+
2023
let rootlength = (String.length rootname) + 1
2124

2225
let get_content filename =
26+
let filepath = (String.concat ~sep:Filename.dir_sep (rootname::filename)) in
2327
try%lwt
24-
Lwt_io.with_file ~mode:Lwt_io.input
25-
(String.concat ~sep:Filename.dir_sep filename)
26-
Lwt_io.read
28+
Lwt_io.with_file ~mode:Lwt_io.input filepath Lwt_io.read
2729
with
2830
_ -> Lwt.return ""
2931

0 commit comments

Comments
 (0)