let build_info filename =
  let file = string_of_file filename in
  let mark_start = "<<<<<<< "^(Filename.basename filename)^"\n" in
  let len_mark_start = String.length mark_start in
  let start_re = Str.regexp_string mark_start in
  let mark_end = ">>>>>>> [0-9]+\\(\\.[0-9]+\\)*\n" in
  let end_re = Str.regexp mark_end in
  let mark_middle = "=======\n" in
  let len_mark_middle = String.length mark_middle in
  let middle_re = Str.regexp_string mark_middle in
  let info = ref ([] : t list) in
  let rec iter pos =
    try
      let conf_start = Str.search_forward start_re file pos in
      let s = String.sub file pos (conf_start - pos) in
      info := (No_conflict s) :: !info ;
      try
        let conf_end = Str.search_forward end_re file conf_start in
        let matched = Str.matched_string file in
        let len_mark_end = String.length matched in
        let new_pos = conf_end + len_mark_end in
        try
          let conf_middle = Str.search_forward middle_re file conf_start in
          let s1 = String.sub file
              (conf_start + len_mark_start)
              (conf_middle - conf_start - len_mark_start)
          in
          let s2 = String.sub file
              (conf_middle + len_mark_middle)
              (conf_end - conf_middle - len_mark_middle)
          in
          info := (Conflict (s1, s2)) :: !info;
          iter new_pos
        with
          Not_found ->
          prerr_endline (mark_middle^" not found in "^
                         (String.sub file conf_start ((String.length file) - pos - conf_start)));
          raise (Failure "Conflict without middle.")
      with
        Not_found ->
          prerr_endline (mark_end^" not found in "^
                         (String.sub file conf_start ((String.length file) - pos -conf_start)));
          raise (Failure "Conflict not ended.")
    with
      Not_found ->
        (* no more conflict *)
        let s = String.sub file pos ((String.length file) - pos) in
        let i = No_conflict s in
        info := i :: !info
  in
  iter 0;
  List.rev !info