camlspotter avatar camlspotter committed d751d7d

added file identification by inode+dev / md5sum

Comments (0)

Files changed (6)

 cmt.cmi :
 command.cmi :
 dotfile.cmi :
+fileident.cmi :
 locident.cmi :
 name.cmi :
 pathreparse.cmi : spot.cmi
-spot.cmi : utils.cmi
+spot.cmi : utils.cmi ttfold.cmo
 spotconfig.cmi : spotconfig_intf.cmo
 spoteval.cmi : utils.cmi spot.cmi
 spotfile.cmi : spoteval.cmi spot.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
 locident.cmo : locident.cmi
 locident.cmx : locident.cmi
 name.cmo : name.cmi
 treeset.cmx : xset.cmx treeset.cmi
 ttfold.cmo :
 ttfold.cmx :
-ttfold.out.cmo :
-ttfold.out.cmx :
-ttfoldx.cmo :
-ttfoldx.cmx :
 typeFix.cmo : utils.cmi name.cmi typeFix.cmi
 typeFix.cmx : utils.cmx name.cmx typeFix.cmi
 typeexpand.cmo : utils.cmi typeexpand.cmi
 # Requires unix!
 COMPFLAGS= -g $(INCLUDES_DEP) -I +unix
 
-MODULES= utils checksum dotfile xset treeset command typeexpand \
+MODULES= utils checksum fileident dotfile 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.                                        *)
+(*                                                                     *)
+(***********************************************************************)
+
+(* File identity by device+inode or md5sum of contents 
+
+   In Mingw, inode does not work. We use md5sum of the contents instead.
+*)
+
+open Utils
+
+type t = 
+  | Dev_inode of int * int
+  | Md5sum of Digest.t
+
+let get = Hashtbl.memoize (Hashtbl.create 107) (fun path ->
+  let ident = 
+    try
+      let st = Unix.lstat path in
+      if st.Unix.st_ino = 0 then (* Mingw *)
+        Some (Md5sum (Digest.file path))
+      else 
+        Some (Dev_inode (st.Unix.st_dev, st.Unix.st_ino))
+    with
+    | _ -> None
+  in
+  path, ident)
+  
+(***********************************************************************)
+(*                                                                     *)
+(*                            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 identity by device+inode or md5sum of contents 
+
+   In Mingw, inode does not work. We use md5sum of the contents instead.
+*)
+
+type t = 
+  | Dev_inode of int * int 
+  | Md5sum of Digest.t
+
+val get : string -> string * t option
+(** [get path] returns its file identification with cons-hashed path *)
 open Format
 
 let magic_number = "OCamlSpot"
-let ocaml_version = "4.00.0"
+let ocaml_version = "4.00.0" (* 4.00.1 also works *)
 let version = "2.0.1"
 
 (** Kind of ``object`` *)
 module Region : sig
 
   type t = private {
-    fname : string option;
-    (* filename and device/inode. None = "_none_" *)
+    fname : (string * Fileident.t option) option;
     start : Position.t;
     end_ : Position.t
   }
 
   (* CR jfuruse: I heard that inode is not a good idea; mingw has no inode *)
   type t = {
-    fname : string option;
-    (* filename and device/inode. None = "_none_" *)
+    fname : (string * Fileident.t option) option;
     start : Position.t;
     end_ : Position.t
   }
   let fname = function
     | "_none_" -> None
     | s ->
-        (* We need hash-cons-ing to prevent string dupes *)
         let s =
           if Filename.is_relative s then Unix.getcwd () ^/ s
           else s
         in
-        Hashtbl.memoize cache (fun s -> Some s) s
+        Some (Fileident.get s)
 
   let to_string t =
     Printf.sprintf "%s:%s:%s"
-      (match t.fname with Some fname -> fname | None -> "_none_")
+      (match t.fname with Some fname -> fst fname | None -> "_none_")
       (Position.to_string t.start)
       (Position.to_string t.end_)
 
 
 module Region : sig
 
-  type t = private { fname : (string * (int * int) option) option; 
-                     (* filename and device/inode. None = "_none_" *)
+  type t = private { fname : (string * Fileident.t option) option; 
                      start : Position.t; 
                      end_ : Position.t; }
   
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.