1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
open ExtLib
open Dose_common
module Version = Dose_versioning.Debian
include Util.Logging (struct
let label = "dose_deb.debutil"
end)
let get_source pkg =
match pkg#source with
| ("", None) -> (pkg#name, pkg#version)
| (n, None) -> (n, pkg#version)
| (n, Some v) -> (n, v)
(** [group_by_source universe] returns a hashtbl that maps
(source,sourceversion) -> to a packages list *)
let cluster packagelist =
let th = Hashtbl.create (List.length packagelist) in
List.iter
(fun pkg ->
let packageversion =
Version.compose (Version.strip_epoch_binnmu pkg#version)
in
let realversion = Version.compose (Version.strip_epoch pkg#version) in
let (source, sourceversion) = get_source pkg in
try
let h = Hashtbl.find th (source, sourceversion) in
try
let (l, hi_v) = Hashtbl.find h packageversion in
l := pkg :: !l ;
let new_hi =
if Version.compare hi_v realversion < 0 then hi_v else realversion
in
Hashtbl.replace h packageversion (l, new_hi)
with Not_found ->
Hashtbl.add h packageversion (ref [pkg], realversion)
with Not_found ->
let h = Hashtbl.create 17 in
Hashtbl.add h packageversion (ref [pkg], realversion) ;
Hashtbl.add th (source, sourceversion) h)
packagelist ;
let h = Hashtbl.create (List.length packagelist) in
let i = ref 0 in
Hashtbl.iter
(fun (s, v) thv ->
let l =
Hashtbl.fold
(fun v ({ contents = l }, rv) acc -> (v, rv, l) :: acc)
thv
[]
in
i := !i + List.length l ;
Hashtbl.add h (s, v) l)
th ;
info "Packages: %d" (List.length packagelist) ;
info "Source Clusters: %d" (Hashtbl.length h) ;
info "Binary (effective) Clusters: %d" !i ;
h