subversion 0.1.10

Rust bindings for Subversion
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
use crate::dirent::AsCanonicalDirent;
use crate::uri::AsCanonicalUri;
use crate::{with_tmp_pool, Depth, Error, Revision};
use std::ffi::CString;
use std::ptr;

/// Options for merge operations
#[derive(Debug, Clone, Default)]
pub struct MergeOptions {
    /// Ignore mergeinfo during the merge
    pub ignore_mergeinfo: bool,
    /// Ignore ancestry when computing differences
    pub diff_ignore_ancestry: bool,
    /// Force deletion of locally modified or unversioned files
    pub force_delete: bool,
    /// Only record the merge, don't apply changes
    pub record_only: bool,
    /// Perform a dry run (no actual changes)
    pub dry_run: bool,
    /// Allow merge into a mixed-revision working copy
    pub allow_mixed_rev: bool,
    /// Additional diff options (e.g., "-b", "-w", "--ignore-eol-style")
    pub diff_options: Vec<String>,
}

/// Perform a three-way merge between two sources
///
/// Merge the changes between `source1` at `revision1` and `source2` at `revision2`
/// into the working copy at `target_wcpath`.
///
/// # Arguments
/// * `source1` - The first source URL or path
/// * `revision1` - The revision of the first source
/// * `source2` - The second source URL or path
/// * `revision2` - The revision of the second source
/// * `target_wcpath` - The target working copy path
/// * `depth` - How deep to recurse
/// * `options` - Merge options
/// * `ctx` - The client context
pub fn merge<S1, S2, T>(
    source1: S1,
    revision1: impl Into<Revision>,
    source2: S2,
    revision2: impl Into<Revision>,
    target_wcpath: T,
    depth: Depth,
    options: &MergeOptions,
    ctx: &mut crate::client::Context,
) -> Result<(), Error<'static>>
where
    S1: AsCanonicalUri,
    S2: AsCanonicalUri,
    T: AsCanonicalDirent,
{
    with_tmp_pool(|pool| unsafe {
        let source1_uri = source1.as_canonical_uri()?;
        let source2_uri = source2.as_canonical_uri()?;
        let target = target_wcpath.as_canonical_dirent()?;

        let source1_cstr = CString::new(source1_uri.as_str())?;
        let source2_cstr = CString::new(source2_uri.as_str())?;
        let target_cstr = CString::new(target.as_str())?;

        let revision1: subversion_sys::svn_opt_revision_t = revision1.into().into();
        let revision2: subversion_sys::svn_opt_revision_t = revision2.into().into();

        // Convert diff options to APR array
        let merge_options = if options.diff_options.is_empty() {
            ptr::null()
        } else {
            let mut arr = apr::tables::TypedArray::<*const std::ffi::c_char>::new(
                pool,
                options.diff_options.len() as i32,
            );
            for opt in &options.diff_options {
                arr.push(apr::strings::pstrdup_raw(opt, pool)? as *const _);
            }
            arr.as_ptr()
        };

        let err = subversion_sys::svn_client_merge5(
            source1_cstr.as_ptr(),
            &revision1,
            source2_cstr.as_ptr(),
            &revision2,
            target_cstr.as_ptr(),
            depth.into(),
            options.ignore_mergeinfo as i32,
            options.diff_ignore_ancestry as i32,
            options.force_delete as i32,
            options.record_only as i32,
            options.dry_run as i32,
            options.allow_mixed_rev as i32,
            merge_options,
            ctx.as_mut_ptr(),
            pool.as_mut_ptr(),
        );

        Error::from_raw(err)
    })
}

/// Perform a peg revision merge
///
/// Merge changes from a source branch identified by `source_path_or_url` at
/// `source_peg_revision` into the target working copy at `target_wcpath`.
///
/// # Arguments
/// * `source` - The source URL or path
/// * `ranges_to_merge` - Optional array of revision ranges to merge (automatic if None)
/// * `source_peg_revision` - The peg revision for the source
/// * `target_wcpath` - The target working copy path  
/// * `depth` - How deep to recurse
/// * `options` - Merge options
/// * `ctx` - The client context
pub fn merge_peg<S, T>(
    source: S,
    ranges_to_merge: Option<&[crate::RevisionRange]>,
    source_peg_revision: impl Into<Revision>,
    target_wcpath: T,
    depth: Depth,
    options: &MergeOptions,
    ctx: &mut crate::client::Context,
) -> Result<(), Error<'static>>
where
    S: AsCanonicalUri,
    T: AsCanonicalDirent,
{
    with_tmp_pool(|pool| unsafe {
        let source_uri = source.as_canonical_uri()?;
        let target = target_wcpath.as_canonical_dirent()?;

        let source_cstr = CString::new(source_uri.as_str())?;
        let target_cstr = CString::new(target.as_str())?;

        let peg_revision: subversion_sys::svn_opt_revision_t = source_peg_revision.into().into();

        // Convert revision ranges to APR array if provided
        let ranges_array =
            if let Some(ranges) = ranges_to_merge {
                let mut arr = apr::tables::TypedArray::<
                    *mut subversion_sys::svn_opt_revision_range_t,
                >::new(pool, ranges.len() as i32);
                for range in ranges {
                    let range_ptr: *mut subversion_sys::svn_opt_revision_range_t = pool.calloc();
                    (*range_ptr).start = range.start.into();
                    (*range_ptr).end = range.end.into();
                    arr.push(range_ptr);
                }
                arr.as_ptr()
            } else {
                ptr::null()
            };

        // Convert diff options to APR array
        let merge_options = if options.diff_options.is_empty() {
            ptr::null()
        } else {
            let mut arr = apr::tables::TypedArray::<*const std::ffi::c_char>::new(
                pool,
                options.diff_options.len() as i32,
            );
            for opt in &options.diff_options {
                arr.push(apr::strings::pstrdup_raw(opt, pool)? as *const _);
            }
            arr.as_ptr()
        };

        let err = subversion_sys::svn_client_merge_peg5(
            source_cstr.as_ptr(),
            ranges_array,
            &peg_revision,
            target_cstr.as_ptr(),
            depth.into(),
            options.ignore_mergeinfo as i32,
            options.diff_ignore_ancestry as i32,
            options.force_delete as i32,
            options.record_only as i32,
            options.dry_run as i32,
            options.allow_mixed_rev as i32,
            merge_options,
            ctx.as_mut_ptr(),
            pool.as_mut_ptr(),
        );

        Error::from_raw(err)
    })
}

/// Get merge information about what has been merged into a path
///
/// Returns a hash of merge source URLs to revision range lists
pub fn get_merged_mergeinfo<P>(
    path_or_url: P,
    peg_revision: impl Into<Revision>,
    ctx: &mut crate::client::Context,
) -> Result<std::collections::HashMap<String, Vec<crate::RevisionRange>>, Error<'_>>
where
    P: AsCanonicalUri,
{
    with_tmp_pool(|pool| unsafe {
        let path = path_or_url.as_canonical_uri()?;
        let path_cstr = CString::new(path.as_str())?;
        let peg_rev: subversion_sys::svn_opt_revision_t = peg_revision.into().into();

        let mut mergeinfo_ptr = ptr::null_mut();

        let err = subversion_sys::svn_client_mergeinfo_get_merged(
            &mut mergeinfo_ptr,
            path_cstr.as_ptr(),
            &peg_rev,
            ctx.as_mut_ptr(),
            pool.as_mut_ptr(),
        );

        Error::from_raw(err)?;

        if mergeinfo_ptr.is_null() {
            return Ok(std::collections::HashMap::new());
        }

        // Use MergeinfoHash to safely convert the hash
        let mergeinfo_hash = MergeinfoHash::from_ptr(mergeinfo_ptr);
        Ok(mergeinfo_hash.to_hashmap())
    })
}

/// A conflict that occurred during a merge operation
#[derive(Debug, Clone)]
pub struct MergeConflict {
    /// The path that has a conflict
    pub path: String,
    /// The type of conflict
    pub conflict_type: ConflictType,
    /// Base revision of the conflict
    pub base_revision: Option<crate::Revnum>,
    /// Their revision of the conflict
    pub their_revision: Option<crate::Revnum>,
    /// My revision of the conflict
    pub my_revision: Option<crate::Revnum>,
}

/// Type of conflict that can occur during merge
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ConflictType {
    /// Text content conflict
    Text,
    /// Property conflict
    Property,
    /// Tree structure conflict (add/delete/move)
    Tree,
}

/// Result of a conflict resolution
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ConflictResolution {
    /// Use the local version (mine)
    Mine,
    /// Use the incoming version (theirs)
    Theirs,
    /// Use the base version
    Base,
    /// Mark as resolved, custom resolution was applied
    Working,
    /// Postpone resolution
    Postpone,
}

/// A safe wrapper for APR hashes containing mergeinfo (path -> rangelist mappings)
///
/// This wrapper encapsulates the common pattern of working with mergeinfo hashes
/// from Subversion's C API, reducing unsafe code and providing convenient
/// conversion methods.
pub struct MergeinfoHash<'a> {
    inner: apr::hash::TypedHash<'a, apr_sys::apr_array_header_t>,
}

impl<'a> MergeinfoHash<'a> {
    /// Create a MergeinfoHash from a raw APR hash pointer
    ///
    /// # Safety
    /// The caller must ensure that:
    /// - `ptr` is a valid APR hash containing rangelist arrays
    /// - The hash and its contents remain valid for the lifetime of this wrapper
    pub unsafe fn from_ptr(ptr: *mut apr_sys::apr_hash_t) -> Self {
        Self {
            inner: apr::hash::TypedHash::<apr_sys::apr_array_header_t>::from_ptr(ptr),
        }
    }

    /// Convert the mergeinfo to a `HashMap<String, Vec<RevisionRange>>`
    pub fn to_hashmap(&self) -> std::collections::HashMap<String, Vec<crate::RevisionRange>> {
        self.inner
            .iter()
            .map(|(k, v)| {
                let key = String::from_utf8_lossy(k).into_owned();
                let ranges = unsafe { self.rangelist_to_vec(v as *const _ as *mut _) };
                (key, ranges)
            })
            .collect()
    }

    /// Convert a rangelist array to a Vec<RevisionRange>
    unsafe fn rangelist_to_vec(
        &self,
        rangelist: *mut apr_sys::apr_array_header_t,
    ) -> Vec<crate::RevisionRange> {
        if rangelist.is_null() {
            return Vec::new();
        }

        let rangelist_array =
            apr::tables::TypedArray::<*mut subversion_sys::svn_merge_range_t>::from_ptr(rangelist);

        let mut ranges = Vec::new();
        for range_ptr in rangelist_array.iter() {
            let range = &*range_ptr;
            ranges.push(crate::RevisionRange::new(
                crate::Revision::Number(crate::Revnum(range.start)),
                crate::Revision::Number(crate::Revnum(range.end)),
            ));
        }
        ranges
    }
}

/// Parse mergeinfo from a string representation
///
/// Converts a string in the format "/trunk:1-10,15,20-25" into a mergeinfo hash
pub fn parse_mergeinfo(
    mergeinfo_str: &str,
) -> Result<std::collections::HashMap<String, Vec<crate::RevisionRange>>, Error<'_>> {
    with_tmp_pool(|pool| unsafe {
        let mergeinfo_cstr = CString::new(mergeinfo_str)?;
        let mut mergeinfo_ptr = ptr::null_mut();

        let err = subversion_sys::svn_mergeinfo_parse(
            &mut mergeinfo_ptr,
            mergeinfo_cstr.as_ptr(),
            pool.as_mut_ptr(),
        );

        Error::from_raw(err)?;

        if mergeinfo_ptr.is_null() {
            return Ok(std::collections::HashMap::new());
        }

        let mergeinfo_hash = MergeinfoHash::from_ptr(mergeinfo_ptr);
        Ok(mergeinfo_hash.to_hashmap())
    })
}

/// Convert mergeinfo to a string representation
pub fn mergeinfo_to_string(
    mergeinfo: &std::collections::HashMap<String, Vec<crate::RevisionRange>>,
) -> Result<String, Error<'static>> {
    with_tmp_pool(|pool| unsafe {
        // Create an APR hash from the Rust HashMap
        let hash = apr_sys::apr_hash_make(pool.as_mut_ptr());

        for (path, ranges) in mergeinfo {
            let path_cstr = apr::strings::pstrdup_raw(path, pool)?;

            // Create rangelist array
            let mut rangelist =
                apr::tables::TypedArray::<*mut subversion_sys::svn_merge_range_t>::new(
                    pool,
                    ranges.len() as i32,
                );

            for range in ranges {
                let range_ptr: *mut subversion_sys::svn_merge_range_t = pool.calloc();
                if let (crate::Revision::Number(start), crate::Revision::Number(end)) =
                    (&range.start, &range.end)
                {
                    (*range_ptr).start = start.0;
                    (*range_ptr).end = end.0;
                    (*range_ptr).inheritable = 1;
                    rangelist.push(range_ptr);
                }
            }

            apr_sys::apr_hash_set(
                hash,
                path_cstr as *const std::ffi::c_void,
                apr_sys::APR_HASH_KEY_STRING as isize,
                rangelist.as_ptr() as *mut std::ffi::c_void,
            );
        }

        let mut output_ptr: *mut subversion_sys::svn_string_t = ptr::null_mut();

        let err = subversion_sys::svn_mergeinfo_to_string(&mut output_ptr, hash, pool.as_mut_ptr());

        Error::from_raw(err)?;

        if output_ptr.is_null() {
            Ok(String::new())
        } else {
            let svn_string = &*output_ptr;
            let slice = std::slice::from_raw_parts(svn_string.data as *const u8, svn_string.len);
            Ok(String::from_utf8_lossy(slice).into_owned())
        }
    })
}

/// Calculate the difference between two mergeinfo sets
pub fn mergeinfo_diff(
    mergeinfo1: &std::collections::HashMap<String, Vec<crate::RevisionRange>>,
    mergeinfo2: &std::collections::HashMap<String, Vec<crate::RevisionRange>>,
    consider_inheritance: bool,
) -> Result<
    (
        std::collections::HashMap<String, Vec<crate::RevisionRange>>,
        std::collections::HashMap<String, Vec<crate::RevisionRange>>,
    ),
    Error<'static>,
> {
    with_tmp_pool(|pool| unsafe {
        // Convert Rust HashMaps to APR hashes
        let hash1 = hashmap_to_mergeinfo_hash(mergeinfo1, pool)?;
        let hash2 = hashmap_to_mergeinfo_hash(mergeinfo2, pool)?;

        let mut deleted_ptr = ptr::null_mut();
        let mut added_ptr = ptr::null_mut();

        let err = subversion_sys::svn_mergeinfo_diff2(
            &mut deleted_ptr,
            &mut added_ptr,
            hash1,
            hash2,
            consider_inheritance as i32,
            pool.as_mut_ptr(),
            pool.as_mut_ptr(),
        );

        Error::from_raw(err)?;

        let deleted = MergeinfoHash::from_ptr(deleted_ptr).to_hashmap();
        let added = MergeinfoHash::from_ptr(added_ptr).to_hashmap();

        Ok((deleted, added))
    })
}

/// Merge two mergeinfo sets together
pub fn mergeinfo_merge(
    mergeinfo1: &std::collections::HashMap<String, Vec<crate::RevisionRange>>,
    mergeinfo2: &std::collections::HashMap<String, Vec<crate::RevisionRange>>,
) -> Result<std::collections::HashMap<String, Vec<crate::RevisionRange>>, Error<'static>> {
    with_tmp_pool(|pool| unsafe {
        let hash1 = hashmap_to_mergeinfo_hash(mergeinfo1, pool)?;
        let hash2 = hashmap_to_mergeinfo_hash(mergeinfo2, pool)?;

        let err = subversion_sys::svn_mergeinfo_merge2(
            hash1,
            hash2,
            pool.as_mut_ptr(),
            pool.as_mut_ptr(),
        );

        Error::from_raw(err)?;

        Ok(MergeinfoHash::from_ptr(hash1).to_hashmap())
    })
}

/// Remove a revision range from mergeinfo
pub fn mergeinfo_remove(
    mergeinfo: &mut std::collections::HashMap<String, Vec<crate::RevisionRange>>,
    eraser: &std::collections::HashMap<String, Vec<crate::RevisionRange>>,
    consider_inheritance: bool,
) -> Result<(), Error<'static>> {
    with_tmp_pool(|pool| unsafe {
        let hash = hashmap_to_mergeinfo_hash(mergeinfo, pool)?;
        let eraser_hash = hashmap_to_mergeinfo_hash(eraser, pool)?;

        let err = subversion_sys::svn_mergeinfo_remove2(
            &mut (hash as *mut _),
            eraser_hash,
            hash,
            consider_inheritance as i32,
            pool.as_mut_ptr(),
            pool.as_mut_ptr(),
        );

        Error::from_raw(err)?;

        *mergeinfo = MergeinfoHash::from_ptr(hash).to_hashmap();
        Ok(())
    })
}

/// Intersect two mergeinfo sets
pub fn mergeinfo_intersect(
    mergeinfo1: &std::collections::HashMap<String, Vec<crate::RevisionRange>>,
    mergeinfo2: &std::collections::HashMap<String, Vec<crate::RevisionRange>>,
    consider_inheritance: bool,
) -> Result<std::collections::HashMap<String, Vec<crate::RevisionRange>>, Error<'static>> {
    with_tmp_pool(|pool| unsafe {
        let hash1 = hashmap_to_mergeinfo_hash(mergeinfo1, pool)?;
        let hash2 = hashmap_to_mergeinfo_hash(mergeinfo2, pool)?;

        let mut result_ptr = ptr::null_mut();

        let err = subversion_sys::svn_mergeinfo_intersect2(
            &mut result_ptr,
            hash1,
            hash2,
            consider_inheritance as i32,
            pool.as_mut_ptr(),
            pool.as_mut_ptr(),
        );

        Error::from_raw(err)?;

        Ok(MergeinfoHash::from_ptr(result_ptr).to_hashmap())
    })
}

// Helper function to convert Rust HashMap to APR hash
unsafe fn hashmap_to_mergeinfo_hash<'p>(
    mergeinfo: &std::collections::HashMap<String, Vec<crate::RevisionRange>>,
    pool: &'p apr::Pool<'p>,
) -> Result<*mut apr_sys::apr_hash_t, Error<'static>> {
    let hash = apr_sys::apr_hash_make(pool.as_mut_ptr());

    for (path, ranges) in mergeinfo {
        let path_cstr = apr::strings::pstrdup_raw(path, pool)?;

        let mut rangelist = apr::tables::TypedArray::<*mut subversion_sys::svn_merge_range_t>::new(
            pool,
            ranges.len() as i32,
        );

        for range in ranges {
            let range_ptr: *mut subversion_sys::svn_merge_range_t = pool.calloc();
            if let (crate::Revision::Number(start), crate::Revision::Number(end)) =
                (&range.start, &range.end)
            {
                (*range_ptr).start = start.0;
                (*range_ptr).end = end.0;
                (*range_ptr).inheritable = 1;
                rangelist.push(range_ptr);
            }
        }

        apr_sys::apr_hash_set(
            hash,
            path_cstr as *const std::ffi::c_void,
            apr_sys::APR_HASH_KEY_STRING as isize,
            rangelist.as_ptr() as *mut std::ffi::c_void,
        );
    }

    Ok(hash)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_merge_options_default() {
        let opts = MergeOptions::default();
        assert!(!opts.ignore_mergeinfo);
        assert!(!opts.diff_ignore_ancestry);
        assert!(!opts.force_delete);
        assert!(!opts.record_only);
        assert!(!opts.dry_run);
        assert!(!opts.allow_mixed_rev);
        assert!(opts.diff_options.is_empty());
    }

    #[test]
    fn test_merge_options_builder() {
        let opts = MergeOptions {
            dry_run: true,
            record_only: true,
            diff_options: vec!["-b".to_string(), "-w".to_string()],
            ..Default::default()
        };
        assert!(opts.dry_run);
        assert!(opts.record_only);
        assert_eq!(opts.diff_options.len(), 2);
    }

    #[test]
    fn test_parse_mergeinfo() {
        let mergeinfo = parse_mergeinfo("/trunk:1-10").unwrap();
        assert_eq!(mergeinfo.len(), 1);
        assert!(mergeinfo.contains_key("/trunk"));
        let ranges = &mergeinfo["/trunk"];
        assert_eq!(ranges.len(), 1);
    }

    #[test]
    fn test_mergeinfo_roundtrip() {
        let mergeinfo = parse_mergeinfo("/trunk:1-10").unwrap();
        let s = mergeinfo_to_string(&mergeinfo).unwrap();
        assert_eq!(s, "/trunk:1-10");
    }

    #[test]
    fn test_mergeinfo_diff() {
        let mi1 = parse_mergeinfo("/trunk:1-10").unwrap();
        let mi2 = parse_mergeinfo("/trunk:5-15").unwrap();

        let (deleted, added) = mergeinfo_diff(&mi1, &mi2, false).unwrap();
        // deleted = in mi1 but not mi2, added = in mi2 but not mi1
        assert!(deleted.contains_key("/trunk"));
        assert!(added.contains_key("/trunk"));
    }

    #[test]
    fn test_mergeinfo_merge() {
        let mi1 = parse_mergeinfo("/trunk:1-10").unwrap();
        let mi2 = parse_mergeinfo("/trunk:11-20").unwrap();

        let merged = mergeinfo_merge(&mi1, &mi2).unwrap();
        assert!(merged.contains_key("/trunk"));
        let s = mergeinfo_to_string(&merged).unwrap();
        assert_eq!(s, "/trunk:1-20");
    }

    #[test]
    fn test_mergeinfo_intersect() {
        let mi1 = parse_mergeinfo("/trunk:1-10").unwrap();
        let mi2 = parse_mergeinfo("/trunk:5-15").unwrap();

        let intersection = mergeinfo_intersect(&mi1, &mi2, false).unwrap();
        assert!(intersection.contains_key("/trunk"));
        let s = mergeinfo_to_string(&intersection).unwrap();
        assert_eq!(s, "/trunk:5-10");
    }
}