camlspotter avatar camlspotter committed 5214e6d

cached

Comments (0)

Files changed (10)

 cmt.cmi :
 command.cmi :
+compdir.cmi : filepath.cmi
 dotfile.cmi :
 fileident.cmi :
+filepath.cmi :
 locident.cmi :
 name.cmi :
 pathreparse.cmi : spot.cmi
-spot.cmi : utils.cmi ttfold.cmo
+spot.cmi : utils.cmi ttfold.cmo fileident.cmi
 spotconfig.cmi : spotconfig_intf.cmo
 spoteval.cmi : utils.cmi spot.cmi
 spotfile.cmi : spoteval.cmi spot.cmi
 cmt.cmx : utils.cmx cmt.cmi
 command.cmo : command.cmi
 command.cmx : command.cmi
+compdir.cmo : utils.cmi filepath.cmi compdir.cmi
+compdir.cmx : utils.cmx filepath.cmx compdir.cmi
 dotfile.cmo : utils.cmi dotfile.cmi
 dotfile.cmx : utils.cmx dotfile.cmi
 ext.cmo : xprinttyp.cmi xpath.cmi xlongident.cmi xident.cmi
 ext.cmx : xprinttyp.cmx xpath.cmx xlongident.cmx xident.cmx
 fileident.cmo : utils.cmi fileident.cmi
 fileident.cmx : utils.cmx fileident.cmi
+filepath.cmo : utils.cmi filepath.cmi
+filepath.cmx : utils.cmx filepath.cmi
 locident.cmo : locident.cmi
 locident.cmx : locident.cmi
 name.cmo : name.cmi
     spotconfig.cmx spot.cmx pathreparse.cmx ext.cmx command.cmx cmt.cmx
 pathreparse.cmo : utils.cmi spot.cmi locident.cmi ext.cmo pathreparse.cmi
 pathreparse.cmx : utils.cmx spot.cmx locident.cmx ext.cmx pathreparse.cmi
-spot.cmo : utils.cmi ttfold.cmo treeset.cmi ext.cmo cmt.cmi checksum.cmo \
-    spot.cmi
-spot.cmx : utils.cmx ttfold.cmx treeset.cmx ext.cmx cmt.cmx checksum.cmx \
-    spot.cmi
+spot.cmo : utils.cmi ttfold.cmo treeset.cmi fileident.cmi ext.cmo cmt.cmi \
+    checksum.cmo spot.cmi
+spot.cmx : utils.cmx ttfold.cmx treeset.cmx fileident.cmx ext.cmx cmt.cmx \
+    checksum.cmx spot.cmi
 spotconfig.cmo : utils.cmi spot.cmi ext.cmo spotconfig.cmi
 spotconfig.cmx : utils.cmx spot.cmx ext.cmx spotconfig.cmi
 spotconfig_intf.cmo : spot.cmi ext.cmo
 
 - ocamlspot-samewindow: default is now nil. (The author prefers nil!)
 - Cmt.recover_env used too much memory sometimes.
+- File identification in Mingw now uses md5sum instead of useless dev+inode
 
 2.0.1
 --------------
 # Requires unix!
 COMPFLAGS= -g $(INCLUDES_DEP) -I +unix
 
-MODULES= utils checksum fileident dotfile xset treeset command typeexpand \
+MODULES= utils checksum fileident filepath dotfile compdir xset treeset command typeexpand \
 	xlongident name xident xpath locident typeFix xprinttyp ext ttfold cmt spot spoteval spotconfig_intf spotconfig spotfile pathreparse ocamlspot
 
 OBJS=		$(addsuffix .cmo, $(MODULES))
+(***********************************************************************)
+(*                                                                     *)
+(*                            OCamlSpotter                             *)
+(*                                                                     *)
+(*                             Jun FURUSE                              *)
+(*                                                                     *)
+(*   Copyright 2008-2012 Jun Furuse. All rights reserved.              *)
+(*   This file is distributed under the terms of the GNU Library       *)
+(*   General Public License, with the special exception on linking     *)
+(*   described in file LICENSE.                                        *)
+(*                                                                     *)
+(***********************************************************************)
+
+(** ocamlbuild compilation directory tweak *)
+
+open Utils
+
+module FP = Filepath
+
+let comp_dir fp0 =
+  assert (FP.is_absolute fp0);
+
+  let rec f rev_bases fp = 
+    let dir = FP.to_string fp in
+    let ocamlbuild_path = dir ^/ "_build" in
+    let diropt = 
+      if Unix.is_dir ocamlbuild_path then Some ocamlbuild_path
+      else None
+    in
+    match diropt with
+    | Some dir -> Some (FP.(^/) fp (Filename.concats (dir :: List.rev rev_bases)))
+    | None ->
+        if FP.is_root fp then Some fp0
+        else match FP.dirbase fp with
+        | dir, Some base -> f (base :: rev_bases) dir
+        | _ -> assert false
+  in
+  Option.default (f [] fp0) (fun () -> fp0)
+
+let comp_dir = Hashtbl.memoize (Hashtbl.create 107) comp_dir
+
+let src_dir fp0 =
+  assert (FP.is_absolute fp0);
+
+  let rec f rev fp = 
+    match FP.dirbase fp with
+    | dir, Some "_build" -> FP.(^/) dir (Filename.concats (List.rev rev))
+    | _, None -> fp0
+    | dir, Some x -> f (x::rev) dir
+  in
+  
+  f [] fp0
+
+let src_dir = Hashtbl.memoize (Hashtbl.create 107) src_dir
+(***********************************************************************)
+(*                                                                     *)
+(*                            OCamlSpotter                             *)
+(*                                                                     *)
+(*                             Jun FURUSE                              *)
+(*                                                                     *)
+(*   Copyright 2008-2012 Jun Furuse. All rights reserved.              *)
+(*   This file is distributed under the terms of the GNU Library       *)
+(*   General Public License, with the special exception on linking     *)
+(*   described in file LICENSE.                                        *)
+(*                                                                     *)
+(***********************************************************************)
+
+(** ocamlbuild compilation directory tweak *)
+val comp_dir : Filepath.t -> Filepath.t
+val src_dir : Filepath.t -> Filepath.t
   build_dir : string option;
 }
 
+val load : string -> t
+
 val find_and_load : string -> (string * t) option
   (** [find_and_load abspath] searches .ocamlspot file 
       and returns its location (directory) and its contents.
+(***********************************************************************)
+(*                                                                     *)
+(*                            OCamlSpotter                             *)
+(*                                                                     *)
+(*                             Jun FURUSE                              *)
+(*                                                                     *)
+(*   Copyright 2008-2012 Jun Furuse. All rights reserved.              *)
+(*   This file is distributed under the terms of the GNU Library       *)
+(*   General Public License, with the special exception on linking     *)
+(*   described in file LICENSE.                                        *)
+(*                                                                     *)
+(***********************************************************************)
+
+(* File path normalization *)
+
+open Utils
+
+module F = Filename
+
+let get_component : string -> string = 
+  Hashtbl.memoize (Hashtbl.create 1023) (fun x -> x)
+
+let dotdot = get_component ".."
+
+let rec split st path = 
+  let dir  = F.dirname  path in
+  let base = F.basename path in
+  let st = 
+    let base = 
+      if base = ""
+      || base = F.current_dir_name 
+      || base = F.dir_sep || base = "/" then ""
+      else base
+    in
+    get_component base :: st
+  in
+  if dir = F.current_dir_name then false, st
+  else if dir = F.dir_sep || dir = "/" then true, st
+  else split st dir
+
+let split = split []
+      
+let () = 
+  match Sys.os_type with
+  | "Unix" -> 
+      assert (split ""       = (false, [""]));
+      assert (split "."      = (false, [""]));
+      assert (split "/"      = (true, [""]));
+      assert (split "/."     = (true, [""]));
+      assert (split "./"     = (false, [""]));
+      assert (split ".."     = (false, [".."]));
+      assert (split "/.."    = (true, [".."]));
+      assert (split "/.."    = (true, [".."]));
+      assert (split "//"     = (true, [""]));
+      assert (split "///"    = (true, [""]));
+      assert (split "a/"     = (false, ["a"]));
+      assert (split "a/."    = (false, ["a"; ""]));
+      assert (split "a/b"    = (false, ["a"; "b"]));
+      assert (split "a/b/"   = (false, ["a"; "b"]));
+      assert (split "a/b/."  = (false, ["a"; "b"; ""]));
+      assert (split "a//b/." = (false, ["a"; "b"; ""]))
+  | _ -> ()
+
+let rec rev_normalize rev abs = function
+  | [] -> rev
+  | x::xs ->
+      if x = F.dir_sep || x = F.current_dir_name then assert false;
+      if x = F.parent_dir_name then
+        match rev with
+        | [] -> rev_normalize (if abs then [] else [F.parent_dir_name]) abs xs
+        | r::_ when r = F.parent_dir_name -> rev_normalize (x::rev) abs xs
+        | _::rs -> rev_normalize rs abs xs
+      else if x = "" then rev_normalize rev abs xs
+      else rev_normalize (x::rev) abs xs
+      
+let hashcons_list = 
+  let cache = Hashtbl.create 1023 in
+  let rec f xs = Hashtbl.memoize cache (function
+    | [] -> []
+    | x::xs -> x :: f xs) xs
+  in
+  f
+
+let rev_normalize rev abs xs = hashcons_list (rev_normalize rev abs xs)
+
+let () = 
+  assert (rev_normalize [] false [] = []);
+  assert (rev_normalize [] false [""] = []);
+  assert (rev_normalize [] false [""; ""] = []);
+  assert (rev_normalize [] false ["a"; ""] = ["a"]);
+  assert (rev_normalize [] false [""; "a"] = ["a"]);
+  assert (rev_normalize [] false ["a"; ""] == rev_normalize [] false [""; "a"]);
+  assert (rev_normalize [] false ["a"; ".."] = []);
+  assert (rev_normalize [] false ["a"; ".."; "b"] = ["b"]);
+  assert (rev_normalize [] false [".."; "a"] = ["a"; ".."]);
+  assert (rev_normalize [] false [".."; "a"; ".."] = [".."]);
+  assert (rev_normalize [] false [".."; "a"; "b"; ".."; ".."; "c"] = ["c"; ".."]);
+  assert (rev_normalize [] false [".."; "a"; ".."; ".."; "c"] = ["c"; ".."; ".."]);
+  assert (rev_normalize [] true  [".."; "a"] = ["a"]);
+  assert (rev_normalize [] true  [".."; "a"; ".."] = []);
+  assert (rev_normalize [] true  [".."; "a"; "b"; ".."; ".."; "c"] = ["c"]);
+  assert (rev_normalize [] true  [".."; "a"; ".."; ".."; "c"] = ["c"]);
+
+type t = bool * string list
+
+let equal (b1,xs1) (b2,xs2) = b1 = b2 && xs1 == xs2
+
+let compare t1 t2 = if equal t1 t2 then 0 else compare t1 t2
+
+let of_string path = 
+  let abs, xs = split path in
+  abs, rev_normalize [] abs xs
+
+let to_string (abs, rev) =
+  let xs = List.rev rev in
+  let xs = if abs then "" :: xs else xs in
+  if xs = [] then "." else String.concat (F.dir_sep) xs
+
+let is_absolute (abs, _) = abs
+let is_relative (abs, _) = not abs
+
+let root = (true, [])
+let is_root = function 
+  | (true, []) -> true
+  | _ -> false
+
+let dirbase (abs, xs) = match xs with
+  | [] | ".." :: _ -> (abs, xs), None
+  | x::xs -> (abs, xs), Some x
+
+let (^/) (abs, xs) s = 
+  let abs', ys = split s in
+  assert (not abs');
+  abs, rev_normalize xs abs ys
+
+let parent = function
+  | (false, (".."::_ | [] as xs)) -> (false, dotdot :: xs)
+  | (true, []) -> (true, [])
+  | (abs, (_::xs)) -> (abs, xs)
+
+(***********************************************************************)
+(*                                                                     *)
+(*                            OCamlSpotter                             *)
+(*                                                                     *)
+(*                             Jun FURUSE                              *)
+(*                                                                     *)
+(*   Copyright 2008-2012 Jun Furuse. All rights reserved.              *)
+(*   This file is distributed under the terms of the GNU Library       *)
+(*   General Public License, with the special exception on linking     *)
+(*   described in file LICENSE.                                        *)
+(*                                                                     *)
+(***********************************************************************)
+
+(* File path normalization *)
+
+type t
+
+val compare : t -> t -> int
+val equal : t -> t -> bool
+
+val of_string : string -> t
+val to_string : t -> string
+val is_absolute : t -> bool
+val is_relative : t -> bool
+val root : t
+val is_root : t -> bool
+val dirbase : t -> t * string option
+val (^/) : t -> string -> t
+val parent : t -> t
     with
     | Invalid_argument _ -> s, ""
 
+  let concats xs = String.concat dir_sep xs
+
   module Open = struct
     let (^/) p1 p2 =
       if Filename.is_relative p2 then Filename.concat p1 p2 else p2
 module Filename : sig
   include module type of Filename
   val split_extension : string -> string * string
+  val concats : string list -> string
   module Open : sig
     val (^/) : string -> string -> string
   end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.