last_modified: don't find_blob; find the commit! #10
1 changed files with 29 additions and 27 deletions
|
@ -463,33 +463,35 @@ module Make (Pclock : Mirage_clock.PCLOCK) = struct
|
||||||
|
|
||||||
let last_modified t key =
|
let last_modified t key =
|
||||||
let open Lwt.Infix in
|
let open Lwt.Infix in
|
||||||
find_blob t key >>=
|
match t.committed, t.head with
|
||||||
Option.fold
|
| None, None ->
|
||||||
~none:(Lwt.return (Error (`Not_found key)))
|
Lwt.return (Error (`Not_found key))
|
||||||
~some:(fun head ->
|
| Some _, _ ->
|
||||||
Store.read_exn t.store head >|= function
|
Lwt.return_ok
|
||||||
| Commit c ->
|
(Option.fold
|
||||||
let author = Git_commit.author c in
|
~none:Ptime.epoch
|
||||||
let secs, tz_offset = author.Git.User.date in
|
~some:Fun.id (Ptime.of_float_s (Int64.to_float (now ()))))
|
||||||
let secs =
|
| None, Some head ->
|
||||||
Option.fold ~none:secs
|
Store.read_exn t.store head >|= function
|
||||||
~some:(fun { Git.User.sign ; hours ; minutes } ->
|
| Commit c ->
|
||||||
let tz_off = Int64.(mul (add (mul (of_int hours) 60L) (of_int minutes)) 60L) in
|
let author = Git_commit.author c in
|
||||||
match sign with
|
let secs, tz_offset = author.Git.User.date in
|
||||||
| `Plus -> Int64.(sub secs tz_off)
|
let secs =
|
||||||
| `Minus -> Int64.(add secs tz_off))
|
Option.fold ~none:secs
|
||||||
tz_offset
|
~some:(fun { Git.User.sign ; hours ; minutes } ->
|
||||||
in
|
let tz_off = Int64.(mul (add (mul (of_int hours) 60L) (of_int minutes)) 60L) in
|
||||||
let ts =
|
match sign with
|
||||||
Option.fold
|
| `Plus -> Int64.(sub secs tz_off)
|
||||||
~none:Ptime.epoch
|
| `Minus -> Int64.(add secs tz_off))
|
||||||
~some:Fun.id (Ptime.of_float_s (Int64.to_float secs))
|
tz_offset
|
||||||
in
|
in
|
||||||
Ok ts
|
let ts =
|
||||||
| _ ->
|
Option.fold
|
||||||
Ok (Option.fold
|
~none:Ptime.epoch
|
||||||
~none:Ptime.epoch
|
~some:Fun.id (Ptime.of_float_s (Int64.to_float secs))
|
||||||
~some:Fun.id (Ptime.of_float_s (Int64.to_float (now ())))))
|
in
|
||||||
|
Ok ts
|
||||||
|
| _ -> assert false
|
||||||
|
|
||||||
let digest t key =
|
let digest t key =
|
||||||
let open Lwt.Infix in
|
let open Lwt.Infix in
|
||||||
|
|
Loading…
Reference in a new issue