swh-graph 11.4.1

Compressed in-memory representation of the Software Heritage archive graph
Documentation
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
/*
 * Copyright (C) 2023-2026  The Software Heritage developers
 * See the AUTHORS file at the top-level directory of this distribution
 * License: GNU General Public License version 3, or any later version
 * See top-level LICENSE file for more information
 */

use std::fs::File;
use std::io::{BufWriter, Write};
use std::path::PathBuf;
use std::sync::Mutex;

use anyhow::{anyhow, bail, Context, Result};
use clap::{Parser, Subcommand, ValueEnum};
use dsi_progress_logger::{concurrent_progress_logger, progress_logger, ProgressLog};
use itertools::Itertools;
use mimalloc::MiMalloc;
use rayon::prelude::*;

use swh_graph::map::{MappedPermutation, Permutation};
use swh_graph::mph::SwhidPthash;
use swh_graph::utils::parse_allowed_node_types;
use swh_graph::{NodeType, SWHID};

#[cfg_attr(not(miri), global_allocator)] // Miri does not support Mimalloc
static GLOBAL: MiMalloc = MiMalloc;

#[derive(Parser, Debug)]
#[command(about = "Commands to read ORC files and produce property files and an initial not-very-compressed BVGraph", long_about = None)]
struct Args {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand, Debug)]
enum Commands {
    /// Reads the list of nodes and arcs from the ORC directory and produces lists of
    /// unique SWHIDs in the given directory
    ExtractNodes {
        #[arg(value_enum, long, default_value_t = DatasetFormat::Orc)]
        format: DatasetFormat,
        #[arg(long, default_value = "*")]
        allowed_node_types: String,
        /// Size (in bytes) of each thread's buffer in memory before it sorts and
        /// flushes it to disk.
        ///
        /// Higher values consume more memory during the sorting phase to save
        /// time during the merging phase.
        #[arg(long, default_value = "5000000000")]
        buffer_size: usize,
        dataset_dir: PathBuf,
        target_dir: PathBuf,
    },
    /// Reads the list of nodes and arcs from the ORC directory and produces lists of
    /// unique labels in the given directory
    ExtractLabels {
        #[arg(value_enum, long, default_value_t = DatasetFormat::Orc)]
        format: DatasetFormat,
        #[arg(long, default_value = "*")]
        allowed_node_types: String,
        /// Size (in bytes) of each thread's buffer in memory before it sorts and
        /// flushes it to disk.
        ///
        /// Higher values consume more memory during the sorting phase to save
        /// time during the merging phase.
        #[arg(long, default_value = "5000000000")]
        buffer_size: usize,
        dataset_dir: PathBuf,
    },
    /// Reads the list of authors and committers from the ORC directory and produces lists
    /// unique names (based64-encoded) in the given directory
    ExtractPersons {
        #[arg(value_enum, long, default_value_t = DatasetFormat::Orc)]
        format: DatasetFormat,
        #[arg(long, default_value = "*")]
        allowed_node_types: String,
        /// Size (in bytes) of each thread's buffer in memory before it sorts and
        /// flushes it to disk.
        ///
        /// Higher values consume more memory during the sorting phase to save
        /// time during the merging phase.
        #[arg(long, default_value = "5000000000")]
        buffer_size: usize,
        dataset_dir: PathBuf,
    },
    /// Extracts the full names of authors and committers from the ORC tables containing them.
    ///
    /// All the full names are concatenated into a single byte string that is written to disk.
    /// Another file, that contains the length of each full name, is generated.
    ExtractFullnames {
        #[arg(value_enum, long, default_value_t = DatasetFormat::Orc)]
        format: DatasetFormat,
        #[arg(long)]
        person_function: PathBuf,
        dataset_dir: PathBuf,
        fullnames_path: PathBuf,
        lengths_path: PathBuf,
    },

    /// Reads the list of nodes from the generated unique SWHIDS and counts the number
    /// of nodes of each type
    NodeStats {
        #[arg(value_enum, long, default_value_t = DatasetFormat::Orc)]
        format: DatasetFormat,
        #[arg(long)]
        swhids_dir: PathBuf,
        #[arg(long)]
        target_stats: PathBuf,
        #[arg(long)]
        target_count: PathBuf,
    },
    /// Reads the list of arcs from the ORC directory and counts the number of arcs
    /// of each type
    EdgeStats {
        #[arg(value_enum, long, default_value_t = DatasetFormat::Orc)]
        format: DatasetFormat,
        #[arg(long, default_value = "*")]
        allowed_node_types: String,
        #[arg(long)]
        dataset_dir: PathBuf,
        #[arg(long)]
        target_stats: PathBuf,
        #[arg(long)]
        target_count: PathBuf,
    },

    /// Reads the list of origins and sorts it in a way that related origins are close
    /// to each other in the output order
    BfsRoots {
        #[arg(value_enum, long, default_value_t = DatasetFormat::Orc)]
        format: DatasetFormat,
        #[arg(long, default_value = "*")]
        allowed_node_types: String,
        dataset_dir: PathBuf,
        target: PathBuf,
    },

    /// Reads ORC files and produces a not-very-compressed BVGraph
    Bv {
        #[arg(value_enum, long, default_value_t = DatasetFormat::Orc)]
        format: DatasetFormat,
        #[arg(long, default_value_t = 1)]
        partitions_per_thread: usize,
        #[arg(long, default_value = "*")]
        allowed_node_types: String,
        #[arg(value_enum, long, default_value_t = MphAlgorithm::Pthash)]
        mph_algo: MphAlgorithm,
        #[arg(long)]
        function: PathBuf,
        #[arg(long)]
        num_nodes: usize,
        #[arg(long)]
        /// Permutation to apply after hashing a node with the `function`.
        ///
        /// Providing an initial order (eg. using `swh-graph-compress initial-order`)
        /// can significantly reduce the size of the output graph.
        ///
        /// Defaults to the identity permutation.
        order: Option<PathBuf>,
        dataset_dir: PathBuf,
        target_dir: PathBuf,
    },
    /// Reads ORC files and produces a BVGraph with edge labels
    EdgeLabels {
        #[arg(value_enum, long, default_value_t = DatasetFormat::Orc)]
        format: DatasetFormat,
        #[arg(long, default_value_t = 1)]
        partitions_per_thread: usize,
        #[arg(long, default_value = "*")]
        allowed_node_types: String,
        #[arg(value_enum, long, default_value_t = MphAlgorithm::Pthash)]
        mph_algo: MphAlgorithm,
        #[arg(long)]
        function: PathBuf,
        #[arg(long)]
        order: PathBuf,
        #[arg(long)]
        label_name_mphf: PathBuf,
        #[arg(long)]
        label_name_order: PathBuf,
        #[arg(long)]
        num_nodes: usize,
        #[arg(long, action)]
        transposed: bool,
        dataset_dir: PathBuf,
        target_dir: PathBuf,
    },
    /// Reads the list of nodes from the ORC directory and writes properties of each
    /// node to dedicated files
    NodeProperties {
        #[arg(value_enum, long, default_value_t = DatasetFormat::Orc)]
        format: DatasetFormat,
        #[arg(long, default_value = "*")]
        allowed_node_types: String,
        #[arg(value_enum, long, default_value_t = MphAlgorithm::Pthash)]
        mph_algo: MphAlgorithm,
        #[arg(long)]
        function: PathBuf,
        #[arg(long)]
        person_function: Option<PathBuf>,
        #[arg(long)]
        order: PathBuf,
        #[arg(long)]
        num_nodes: usize,
        dataset_dir: PathBuf,
        target: PathBuf,
    },
}

#[derive(Copy, Clone, Debug, ValueEnum)]
enum MphAlgorithm {
    Pthash,
    Cmph,
}

#[derive(Copy, Clone, Debug, ValueEnum)]
enum DatasetFormat {
    Orc,
}

pub fn main() -> Result<()> {
    let args = Args::parse();

    env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();

    match args.command {
        Commands::ExtractNodes {
            format: DatasetFormat::Orc,
            allowed_node_types,
            buffer_size,
            dataset_dir,
            target_dir,
        } => {
            use std::str::FromStr;
            let allowed_node_types = parse_allowed_node_types(&allowed_node_types)?;

            let expected_node_count =
                swh_graph::compress::stats::estimate_node_count(&dataset_dir, &allowed_node_types)
                    .context("Could not estimate node count")? as usize;
            let expected_edge_count =
                swh_graph::compress::stats::estimate_edge_count(&dataset_dir, &allowed_node_types)
                    .context("Could not estimate edge count")? as usize;

            let mut pl = progress_logger!(
                display_memory = true,
                item_name = "arc",
                local_speed = true,
                expected_updates = Some(expected_node_count + expected_edge_count),
            );
            pl.start("Extracting and sorting SWHIDs");

            std::fs::create_dir(&target_dir)
                .with_context(|| format!("Could not create {}", target_dir.display()))?;

            // Write output in multiple files, so it can be processed in parallel
            // by consumers
            let mut shard_id = 0;
            let mut next_shard = || -> Result<_> {
                let path = target_dir.join(format!("nodes.txt.{shard_id:0>8}.zst"));
                shard_id += 1;
                let file = std::fs::File::create_new(&path)
                    .with_context(|| format!("Could not create {}", path.display()))?;
                let compression_level = 3;
                let zstd_encoder = zstd::stream::write::Encoder::new(file, compression_level)
                    .with_context(|| {
                        format!("Could not create ZSTD encoder for {}", path.display())
                    })?
                    .auto_finish();
                Ok(zstd_encoder)
            };
            let mut writer = next_shard()?;

            // Fetch as UTF-8 encoded arrays
            let swhids = swh_graph::compress::iter_swhids(&dataset_dir, &allowed_node_types)
                .context("Could not read nodes from input dataset")?;
            // Parse (TODO: avoid UTF-8 decoding data we generated ourselves, here)
            let swhids = swhids.map(|swhid| {
                SWHID::from_str(
                    &String::from_utf8(swhid.into_iter().collect()).expect("Non-ASCII SWHID"),
                )
                .expect("Could not parse SWHID")
            });
            // Sort and deduplicate
            let swhids = swh_graph::utils::sort::par_sort_swhids(swhids, pl, buffer_size)
                .context("Could not sort SWHIDs")?;
            // Write
            for (i, swhid) in swhids.enumerate() {
                if i % 100_000_000 == 99_999_999 {
                    writer = next_shard()?;
                }
                writer
                    .write_all(format!("{swhid}\n").as_bytes())
                    .context("Could not write SWHID")?;
            }
        }
        Commands::ExtractLabels {
            format: DatasetFormat::Orc,
            allowed_node_types,
            buffer_size,
            dataset_dir,
        } => {
            let allowed_node_types = parse_allowed_node_types(&allowed_node_types)?;

            let expected_edge_count =
                swh_graph::compress::stats::estimate_edge_count(&dataset_dir, &allowed_node_types)
                    .context("Could not estimate edge count")? as usize;

            let mut pl = progress_logger!(
                display_memory = true,
                item_name = "arc",
                local_speed = true,
                expected_updates = Some(expected_edge_count),
            );
            pl.start("Extracting and sorting labels");

            // Fetch labels data
            let labels = swh_graph::compress::iter_labels(&dataset_dir, &allowed_node_types)
                .context("Could not read labels from input dataset")?;
            // Sort and deduplicate
            let labels = swh_graph::utils::sort::par_sort_strings(labels, pl, buffer_size)
                .context("Could not sort labels")?;
            // Encode as base64
            let base64 = base64_simd::STANDARD;
            let labels = labels.map(|label| {
                base64
                    .encode_to_string(label)
                    .into_bytes()
                    .into_boxed_slice()
            });
            // Write
            for label in labels {
                println!(
                    "{}",
                    String::from_utf8(label.into()).expect("Could not decode line")
                );
            }
        }
        Commands::ExtractPersons {
            format: DatasetFormat::Orc,
            allowed_node_types,
            buffer_size,
            dataset_dir,
        } => {
            let allowed_node_types = parse_allowed_node_types(&allowed_node_types)?;

            let expected_node_count = swh_graph::compress::stats::estimate_node_count(
                &dataset_dir,
                &allowed_node_types
                    .iter()
                    .cloned()
                    .filter(|t| [NodeType::Revision, NodeType::Release].contains(t))
                    .collect::<Vec<_>>(),
            )
            .context("Could not estimate node count from input dataset")?
                as usize;

            let mut pl = progress_logger!(
                display_memory = true,
                item_name = "node",
                local_speed = true,
                expected_updates = Some(expected_node_count),
            );
            pl.start("Extracting and sorting persons");

            let persons = swh_graph::compress::iter_persons(&dataset_dir, &allowed_node_types)
                .context("Could not read persons from input dataset")?;
            // Sort and deduplicate
            let persons = swh_graph::utils::sort::par_sort_strings(persons, pl, buffer_size)
                .context("Could not sort persons")?;
            // Encode as base64
            let base64 = base64_simd::STANDARD;
            let persons = persons.map(|person| {
                base64
                    .encode_to_string(person)
                    .into_bytes()
                    .into_boxed_slice()
            });
            // Write
            for person in persons {
                println!(
                    "{}",
                    String::from_utf8(person.into()).expect("Could not decode line")
                );
            }
        }
        Commands::ExtractFullnames {
            format: DatasetFormat::Orc,
            person_function,
            dataset_dir,
            fullnames_path,
            lengths_path,
        } => {
            use pthash::Phf;

            let person_mph = swh_graph::compress::persons::PersonMphf::load(&person_function)
                .with_context(|| format!("Could not load {}", person_function.display()))?;
            let person_hasher = swh_graph::compress::persons::PersonHasher::new(&person_mph);

            let fullnames = swh_graph::compress::iter_fullnames(&dataset_dir, "person")
                .context("Could not read full names from input dataset")?
                .map(Ok);
            swh_graph::compress::persons::write_fullnames(
                person_hasher,
                fullnames,
                &fullnames_path,
                &lengths_path,
            )?;
        }
        Commands::NodeStats {
            format: DatasetFormat::Orc,
            swhids_dir,
            target_stats,
            target_count,
        } => {
            use swh_graph::compress::zst_dir::*;

            let mut stats_file = File::create(&target_stats)
                .with_context(|| format!("Could not open {}", target_stats.display()))?;
            let mut count_file = File::create(&target_count)
                .with_context(|| format!("Could not open {}", target_count.display()))?;

            let bits_per_line = 20; // A little more than this, actually
            let mut pl = concurrent_progress_logger!(
                display_memory = true,
                item_name = "node",
                local_speed = true,
                expected_updates = Some(swh_graph::utils::dir_size(&swhids_dir)? / bits_per_line),
            );
            pl.start("Computing node stats");

            let stats = par_iter_lines_from_dir(&swhids_dir, pl.clone())
                .map(|line: [u8; 50]| {
                    let ty = NodeType::try_from(&line[6..9]).expect("Unexpected SWHID type");
                    let mut stats = [0usize; NodeType::NUMBER_OF_TYPES];
                    stats[ty as usize] += 1;
                    stats
                })
                .reduce(Default::default, |mut left_1d, right_1d| {
                    for (left, right) in left_1d.iter_mut().zip(right_1d.into_iter()) {
                        *left += right;
                    }
                    left_1d
                });

            pl.done();

            let mut stats_lines = Vec::new();
            let mut total = 0;
            for ty in NodeType::all() {
                stats_lines.push(format!("{} {}\n", ty, stats[ty as usize]));
                total += stats[ty as usize];
            }
            stats_lines.sort();

            stats_file
                .write_all(stats_lines.join("").as_bytes())
                .context("Could not write node stats")?;
            count_file
                .write_all(format!("{total}\n").as_bytes())
                .context("Could not write node count")?;
        }
        Commands::EdgeStats {
            format: DatasetFormat::Orc,
            allowed_node_types,
            dataset_dir,
            target_stats,
            target_count,
        } => {
            let allowed_node_types = parse_allowed_node_types(&allowed_node_types)?;

            let mut stats_file = File::create(&target_stats)
                .with_context(|| format!("Could not open {}", target_stats.display()))?;
            let mut count_file = File::create(&target_count)
                .with_context(|| format!("Could not open {}", target_count.display()))?;

            let mut pl = progress_logger!(
                display_memory = true,
                item_name = "arc",
                local_speed = true,
                expected_updates = Some(
                    swh_graph::compress::stats::estimate_edge_count(
                        &dataset_dir,
                        &allowed_node_types
                    )
                    .context("Could not estimate edge count from input dataset")?
                        as usize
                ),
            );
            pl.start("Computing edge stats");
            let pl = Mutex::new(pl);

            let stats =
                swh_graph::compress::stats::count_edge_types(&dataset_dir, &allowed_node_types)
                    .context("Could not read edges from input dataset")?
                    .map(|stats_2d| {
                        pl.lock().unwrap().update_with_count(
                            stats_2d.map(|stats_1d| stats_1d.iter().sum()).iter().sum(),
                        );
                        stats_2d
                    })
                    .reduce(Default::default, |mut left_2d, right_2d| {
                        for (left_1d, right_1d) in left_2d.iter_mut().zip(right_2d.into_iter()) {
                            for (left, right) in left_1d.iter_mut().zip(right_1d.into_iter()) {
                                *left += right;
                            }
                        }
                        left_2d
                    });

            let mut stats_lines = Vec::new();
            let mut total = 0;
            for src_type in NodeType::all() {
                for dst_type in NodeType::all() {
                    let count = stats[src_type as usize][dst_type as usize];
                    if count != 0 {
                        stats_lines.push(format!("{src_type}:{dst_type} {count}\n"));
                        total += count;
                    }
                }
            }
            stats_lines.sort();

            stats_file
                .write_all(stats_lines.join("").as_bytes())
                .context("Could not write edge stats")?;
            count_file
                .write_all(format!("{total}\n").as_bytes())
                .context("Could not write edge count")?;
        }

        Commands::BfsRoots {
            format: DatasetFormat::Orc,
            allowed_node_types,
            dataset_dir,
            target,
        } => {
            let allowed_node_types = parse_allowed_node_types(&allowed_node_types)?;

            let target_file = File::create(&target)
                .with_context(|| format!("Could not open {}", target.display()))?;
            let mut target_file = BufWriter::new(target_file);

            if allowed_node_types.contains(&NodeType::Origin) {
                log::info!("Reading origins...");
                let mut origins: Vec<_> = swh_graph::compress::iter_origins(&dataset_dir)
                    .context("Could not read origins")?
                    .collect();

                // split each URL by "/", reverse the parts, and join again.
                // So for example, "https://github.com/vigna/webgraph-rs/" becomes
                // "webgraph-rs/vigna/github.com//https:"
                // This allows similar projects to be grouped together (eg. all forks
                // of webgraph-rs).
                log::info!("Sorting origins...");
                #[allow(unstable_name_collisions)] // Itertools::intersperse
                origins.par_sort_unstable_by_key(|(url, _id)| -> String {
                    url.trim_end_matches('/')
                        .split('/')
                        .rev()
                        .intersperse("/")
                        .collect()
                });

                log::info!("Writing origins...");
                for (_url, id) in origins {
                    target_file
                        .write_all(format!("{id}\n").as_bytes())
                        .context("Could not write origin")?;
                }
            }

            target_file.flush().context("Could not flush output file")?;
        }

        Commands::Bv {
            format: DatasetFormat::Orc,
            partitions_per_thread,
            allowed_node_types,
            mph_algo,
            function,
            num_nodes,
            order,
            dataset_dir,
            target_dir,
        } => {
            let allowed_node_types = parse_allowed_node_types(&allowed_node_types)?;

            match mph_algo {
                MphAlgorithm::Pthash => swh_graph::compress::bv::bv::<SwhidPthash>(
                    partitions_per_thread,
                    function,
                    num_nodes,
                    order,
                    dataset_dir,
                    &allowed_node_types,
                    target_dir,
                )?,
                MphAlgorithm::Cmph => {
                    swh_graph::compress::bv::bv::<swh_graph::java_compat::mph::gov::GOVMPH>(
                        partitions_per_thread,
                        function,
                        num_nodes,
                        order,
                        dataset_dir,
                        &allowed_node_types,
                        target_dir,
                    )?
                }
            }
        }

        Commands::EdgeLabels {
            format: DatasetFormat::Orc,
            partitions_per_thread,
            allowed_node_types,
            mph_algo,
            function,
            order,
            label_name_mphf,
            label_name_order,
            num_nodes,
            transposed,
            dataset_dir,
            target_dir,
        } => {
            use pthash::Phf;
            use swh_graph::compress::label_names::{LabelNameHasher, LabelNameMphf};
            let allowed_node_types = parse_allowed_node_types(&allowed_node_types)?;
            let order = MappedPermutation::load_unchecked(&order)
                .with_context(|| format!("Could not load {}", order.display()))?;
            let label_name_mphf = LabelNameMphf::load(&label_name_mphf)
                .with_context(|| format!("Could not load {}", label_name_mphf.display()))?;
            let label_name_order = MappedPermutation::load_unchecked(&label_name_order)
                .with_context(|| format!("Could not load {}", label_name_order.display()))?;
            let label_name_hasher = LabelNameHasher::new(&label_name_mphf, &label_name_order)?;

            let label_width = match mph_algo {
                MphAlgorithm::Pthash => swh_graph::compress::bv::edge_labels::<SwhidPthash>(
                    partitions_per_thread,
                    function,
                    order,
                    label_name_hasher,
                    num_nodes,
                    dataset_dir,
                    &allowed_node_types,
                    transposed,
                    target_dir.as_ref(),
                )?,
                MphAlgorithm::Cmph => {
                    swh_graph::compress::bv::edge_labels::<swh_graph::java_compat::mph::gov::GOVMPH>(
                        partitions_per_thread,
                        function,
                        order,
                        label_name_hasher,
                        num_nodes,
                        dataset_dir,
                        &allowed_node_types,
                        transposed,
                        target_dir.as_ref(),
                    )?
                }
            };

            let mut properties_path = target_dir.to_owned();
            properties_path
                .as_mut_os_string()
                .push("-labelled.properties");
            let properties_file = File::create(&properties_path)
                .with_context(|| format!("Could not create {}", properties_path.display()))?;
            java_properties::write(
                BufWriter::new(properties_file),
                &[
                    (
                        "graphclass".to_string(),
                        "it.unimi.dsi.big.webgraph.labelling.BitStreamArcLabelledImmutableGraph"
                            .to_string(),
                    ),
                    (
                        "labelspec".to_string(),
                        format!(
                            "org.softwareheritage.graph.labels.SwhLabel(DirEntry,{label_width})"
                        ),
                    ),
                    (
                        "underlyinggraph".to_string(),
                        target_dir
                            .file_name()
                            .context("Could not get graph file name")?
                            .to_str()
                            .ok_or_else(|| anyhow!("Could not decode graph file name"))?
                            .to_string(),
                    ),
                ]
                .into_iter()
                .collect(),
            )
            .with_context(|| format!("Could not write {}", properties_path.display()))?;
        }
        Commands::NodeProperties {
            format: DatasetFormat::Orc,
            allowed_node_types,
            mph_algo,
            function,
            person_function,
            order,
            num_nodes,
            dataset_dir,
            target,
        } => {
            use log::info;
            use swh_graph::compress::properties::*;
            use swh_graph::mph::{LoadableSwhidMphf, SwhidMphf};

            let allowed_node_types = parse_allowed_node_types(&allowed_node_types)?;

            info!("Loading permutation");
            let order = MappedPermutation::load_unchecked(order.as_path())
                .with_context(|| format!("Could not load {}", order.display()))?;
            assert_eq!(order.len(), num_nodes);
            info!("Permutation loaded, reading MPH");

            fn f<MPHF: SwhidMphf + Sync>(property_writer: PropertyWriter<MPHF>) -> Result<()> {
                info!("MPH loaded, writing properties");
                info!("[ 0/ 8] author timestamps");
                property_writer
                    .write_author_timestamps()
                    .context("Failed to write author timestamps")?;
                info!("[ 1/ 8] committer timestamps");
                property_writer
                    .write_committer_timestamps()
                    .context("Failed to write committer timestamps")?;
                info!("[ 2/ 8] content lengths");
                property_writer
                    .write_content_lengths()
                    .context("Failed to write content lengths")?;
                info!("[ 3/ 8] content_is_skipped");
                property_writer
                    .write_content_is_skipped()
                    .context("Failed to write content_is_skipped")?;
                info!("[ 4/ 8] author ids");
                property_writer
                    .write_author_ids()
                    .context("Failed to write author ids")?;
                info!("[ 5/ 8] committer ids");
                property_writer
                    .write_committer_ids()
                    .context("Failed to write committer ids")?;
                info!("[ 6/ 8] messages");
                property_writer
                    .write_messages()
                    .context("Failed to write messages")?;
                info!("[ 7/ 8] tag names");
                property_writer
                    .write_tag_names()
                    .context("Failed to write tag names")?;
                info!("[ 8/ 8] done");

                Ok(())
            }

            let person_mph = if allowed_node_types.contains(&NodeType::Revision)
                || allowed_node_types.contains(&NodeType::Release)
            {
                use pthash::Phf;

                let Some(person_function) = person_function else {
                    bail!("--person-function must be provided unless --allowed-node-types is set to contain neither 'rev' nor 'rel'.");
                };
                Some(
                    swh_graph::compress::persons::PersonMphf::load(&person_function)
                        .with_context(|| format!("Could not load {}", person_function.display()))?,
                )
            } else {
                None
            };

            let person_mph = person_mph
                .as_ref()
                .map(swh_graph::compress::persons::PersonHasher::new);

            match mph_algo {
                MphAlgorithm::Pthash => {
                    let swhid_mph = LoadableSwhidMphf::load(function).context("Cannot load mph")?;
                    let property_writer = PropertyWriter {
                        swhid_mph,
                        person_mph,
                        order,
                        num_nodes,
                        dataset_dir,
                        allowed_node_types,
                        target,
                    };
                    f::<SwhidPthash>(property_writer)?;
                }
                MphAlgorithm::Cmph => {
                    let swhid_mph = LoadableSwhidMphf::load(function).context("Cannot load mph")?;
                    let property_writer = PropertyWriter {
                        swhid_mph,
                        person_mph,
                        order,
                        num_nodes,
                        dataset_dir,
                        allowed_node_types,
                        target,
                    };
                    f::<swh_graph::java_compat::mph::gov::GOVMPH>(property_writer)?;
                }
            };
        }
    }

    Ok(())
}