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
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
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
//! Deprecated working copy access baton API.
//!
//! This module provides the deprecated `svn_wc_adm_access_t` based API.
//! New code should use [`super::Context`] instead.

#[cfg(feature = "ra")]
use super::{box_notify_baton_borrowed, drop_notify_baton_borrowed, wrap_notify_func, Notify};
use super::{CommittedQueue, ConflictChoice, Lock, PropChange};
use crate::{svn_result, with_tmp_pool};
use std::collections::HashMap;

/// Helper to convert a C string pointer to an owned Option<String>.
unsafe fn cstr_to_option(ptr: *const std::ffi::c_char) -> Option<String> {
    if ptr.is_null() {
        None
    } else {
        Some(
            std::ffi::CStr::from_ptr(ptr)
                .to_str()
                .expect("expected valid UTF-8")
                .to_string(),
        )
    }
}

/// A deprecated working copy entry (`svn_wc_entry_t`).
///
/// All fields are owned copies -- safe to use after the access baton is closed.
#[derive(Debug, Clone)]
pub struct Entry {
    /// Entry's name.
    pub name: Option<String>,
    /// Base revision.
    pub revision: crate::Revnum,
    /// URL in repository.
    pub url: Option<String>,
    /// Canonical repository URL.
    pub repos: Option<String>,
    /// Repository UUID.
    pub uuid: Option<String>,
    /// Node kind (file, dir, ...).
    pub kind: crate::NodeKind,
    /// Scheduling (add, delete, replace, ...).
    pub schedule: u32,
    /// Whether this entry is in a copied state.
    pub copied: bool,
    /// Whether this entry has been deleted.
    pub deleted: bool,
    /// Whether this entry is absent (e.g. due to authz restrictions).
    pub absent: bool,
    /// Whether the entries file is incomplete.
    pub incomplete: bool,
    /// Copyfrom URL.
    pub copyfrom_url: Option<String>,
    /// Copyfrom revision.
    pub copyfrom_rev: crate::Revnum,
    /// Old version of conflicted file.
    pub conflict_old: Option<String>,
    /// New version of conflicted file.
    pub conflict_new: Option<String>,
    /// Working version of conflicted file.
    pub conflict_wrk: Option<String>,
    /// Property reject file.
    pub prejfile: Option<String>,
    /// Last up-to-date time for text contents.
    pub text_time: i64,
    /// Last up-to-date time for properties.
    pub prop_time: i64,
    /// Hex MD5 checksum for the untranslated text base file.
    pub checksum: Option<String>,
    /// Last revision this was changed.
    pub cmt_rev: crate::Revnum,
    /// Last date this was changed.
    pub cmt_date: i64,
    /// Last commit author.
    pub cmt_author: Option<String>,
    /// Lock token, or `None` if not locked.
    pub lock_token: Option<String>,
    /// Lock owner, or `None` if not locked.
    pub lock_owner: Option<String>,
    /// Lock comment, or `None` if not locked or no comment.
    pub lock_comment: Option<String>,
    /// Lock creation date, or 0 if not locked.
    pub lock_creation_date: i64,
    /// Whether this entry has any working properties.
    pub has_props: bool,
    /// Whether this entry has property modifications.
    pub has_prop_mods: bool,
    /// Changelist this item belongs to.
    pub changelist: Option<String>,
    /// Size of the file after translation to local representation.
    pub working_size: i64,
    /// Whether a local copy should be kept after deletion.
    pub keep_local: bool,
    /// The depth of this entry.
    pub depth: crate::Depth,
}

impl Entry {
    /// Create an `Entry` by copying all fields from a raw `svn_wc_entry_t` pointer.
    ///
    /// # Safety
    ///
    /// `ptr` must be a valid, non-null pointer to a `svn_wc_entry_t`.
    pub unsafe fn from_raw(ptr: *const subversion_sys::svn_wc_entry_t) -> Self {
        let e = &*ptr;
        Entry {
            name: cstr_to_option(e.name),
            revision: crate::Revnum(e.revision),
            url: cstr_to_option(e.url),
            repos: cstr_to_option(e.repos),
            uuid: cstr_to_option(e.uuid),
            kind: crate::NodeKind::from(e.kind),
            schedule: e.schedule as u32,
            copied: e.copied != 0,
            deleted: e.deleted != 0,
            absent: e.absent != 0,
            incomplete: e.incomplete != 0,
            copyfrom_url: cstr_to_option(e.copyfrom_url),
            copyfrom_rev: crate::Revnum(e.copyfrom_rev),
            conflict_old: cstr_to_option(e.conflict_old),
            conflict_new: cstr_to_option(e.conflict_new),
            conflict_wrk: cstr_to_option(e.conflict_wrk),
            prejfile: cstr_to_option(e.prejfile),
            text_time: e.text_time,
            prop_time: e.prop_time,
            checksum: cstr_to_option(e.checksum),
            cmt_rev: crate::Revnum(e.cmt_rev),
            cmt_date: e.cmt_date,
            cmt_author: cstr_to_option(e.cmt_author),
            lock_token: cstr_to_option(e.lock_token),
            lock_owner: cstr_to_option(e.lock_owner),
            lock_comment: cstr_to_option(e.lock_comment),
            lock_creation_date: e.lock_creation_date,
            has_props: e.has_props != 0,
            has_prop_mods: e.has_prop_mods != 0,
            changelist: cstr_to_option(e.changelist),
            working_size: e.working_size,
            keep_local: e.keep_local != 0,
            depth: crate::Depth::from(e.depth),
        }
    }
}

/// Deprecated working copy status (version 2, wrapping `svn_wc_status2_t`).
///
/// All fields are owned copies.
#[derive(Debug, Clone)]
pub struct Status {
    /// The entry, or `None` if not under version control.
    pub entry: Option<Entry>,
    /// The status of the entry's text.
    pub text_status: u32,
    /// The status of the entry's properties.
    pub prop_status: u32,
    /// Whether the directory is locked (interrupted update).
    pub locked: bool,
    /// Whether the entry is copied (scheduled for addition-with-history).
    pub copied: bool,
    /// Whether the entry is switched.
    pub switched: bool,
    /// The entry's text status in the repository.
    pub repos_text_status: u32,
    /// The entry's property status in the repository.
    pub repos_prop_status: u32,
    /// The URI of the item.
    pub url: Option<String>,
    /// Youngest committed revision, or invalid if not out of date.
    pub ood_last_cmt_rev: crate::Revnum,
    /// Most recent commit date, or 0 if not out of date.
    pub ood_last_cmt_date: i64,
    /// Node kind of the youngest commit.
    pub ood_kind: u32,
    /// User name of the youngest commit author.
    pub ood_last_cmt_author: Option<String>,
    /// Whether the item is a file external.
    pub file_external: bool,
    /// Pristine text status (not masked by other statuses).
    pub pristine_text_status: u32,
    /// Pristine property status (not masked by other statuses).
    pub pristine_prop_status: u32,
}

impl Status {
    /// Create a `Status` by copying all fields from a raw `svn_wc_status2_t` pointer.
    ///
    /// # Safety
    ///
    /// `ptr` must be a valid, non-null pointer to a `svn_wc_status2_t`.
    pub unsafe fn from_raw(ptr: *const subversion_sys::svn_wc_status2_t) -> Self {
        let s = &*ptr;
        let entry = if s.entry.is_null() {
            None
        } else {
            Some(Entry::from_raw(s.entry))
        };
        Status {
            entry,
            text_status: s.text_status as u32,
            prop_status: s.prop_status as u32,
            locked: s.locked != 0,
            copied: s.copied != 0,
            switched: s.switched != 0,
            repos_text_status: s.repos_text_status as u32,
            repos_prop_status: s.repos_prop_status as u32,
            url: cstr_to_option(s.url),
            ood_last_cmt_rev: crate::Revnum(s.ood_last_cmt_rev),
            ood_last_cmt_date: s.ood_last_cmt_date,
            ood_kind: s.ood_kind as u32,
            ood_last_cmt_author: cstr_to_option(s.ood_last_cmt_author),
            file_external: s.file_external != 0,
            pristine_text_status: s.pristine_text_status as u32,
            pristine_prop_status: s.pristine_prop_status as u32,
        }
    }
}

/// Working copy administrative access baton.
///
/// Provides write locking for working copy operations. The `svn_wc_*`
/// functions that modify the working copy require a write lock, which
/// is acquired by opening an `Adm` with `write_lock=true`.
#[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
pub struct Adm {
    ptr: *mut subversion_sys::svn_wc_adm_access_t,
    _pool: apr::Pool<'static>,
}

#[allow(deprecated)]
impl Adm {
    /// Open an access baton for a working copy directory.
    ///
    /// If `write_lock` is true, acquire a write lock on the directory.
    /// `levels_to_lock` controls depth: 0 = just this dir, -1 = infinite.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn open(
        path: &str,
        write_lock: bool,
        levels_to_lock: i32,
    ) -> Result<Self, crate::Error<'static>> {
        let pool = apr::Pool::new();
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let mut adm_access: *mut subversion_sys::svn_wc_adm_access_t = std::ptr::null_mut();
        with_tmp_pool(|_scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_adm_open3(
                    &mut adm_access,
                    std::ptr::null_mut(), // associated
                    path_cstr.as_ptr(),
                    if write_lock { 1 } else { 0 },
                    levels_to_lock,
                    None,                 // cancel_func
                    std::ptr::null_mut(), // cancel_baton
                    pool.as_mut_ptr(),
                )
            };
            svn_result(err)
        })?;
        Ok(Adm {
            ptr: adm_access,
            _pool: pool,
        })
    }

    /// Check whether this baton holds a write lock.
    pub fn is_locked(&self) -> bool {
        unsafe { subversion_sys::svn_wc_adm_locked(self.ptr) != 0 }
    }

    /// Return the path associated with this access baton.
    pub fn access_path(&self) -> &str {
        let cstr = unsafe { subversion_sys::svn_wc_adm_access_path(self.ptr) };
        unsafe { std::ffi::CStr::from_ptr(cstr) }
            .to_str()
            .expect("access path should be valid UTF-8")
    }

    /// Return the internal pointer for use with deprecated svn_wc_* functions.
    pub fn as_ptr(&self) -> *mut subversion_sys::svn_wc_adm_access_t {
        self.ptr
    }

    /// Set a property on a path in the working copy.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn prop_set(
        &self,
        name: &str,
        value: Option<&[u8]>,
        path: &str,
    ) -> Result<(), crate::Error<'static>> {
        let name_cstr = std::ffi::CString::new(name).unwrap();
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let value_svn = value.map(|v| crate::string::BStr::from_bytes(v, &self._pool));
        let value_ptr = value_svn
            .as_ref()
            .map(|v| v.as_ptr() as *const subversion_sys::svn_string_t)
            .unwrap_or(std::ptr::null());
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_prop_set3(
                    name_cstr.as_ptr(),
                    value_ptr,
                    path_cstr.as_ptr(),
                    self.ptr,
                    0,                    // skip_checks
                    None,                 // notify_func
                    std::ptr::null_mut(), // notify_baton
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)
        })
    }

    /// Get a property value for a path in the working copy.
    ///
    /// Returns `None` if the path is not versioned or the property is not set.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn prop_get(
        &self,
        name: &str,
        path: &str,
    ) -> Result<Option<Vec<u8>>, crate::Error<'static>> {
        let name_cstr = std::ffi::CString::new(name).unwrap();
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let mut value: *const subversion_sys::svn_string_t = std::ptr::null();
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_prop_get(
                    &mut value,
                    name_cstr.as_ptr(),
                    path_cstr.as_ptr(),
                    self.ptr,
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)?;
            if value.is_null() {
                Ok(None)
            } else {
                let svn_str = unsafe { &*value };
                let data = unsafe {
                    std::slice::from_raw_parts(svn_str.data as *const u8, svn_str.len as usize)
                };
                Ok(Some(data.to_vec()))
            }
        })
    }

    /// List all properties for a path in the working copy.
    ///
    /// Returns a map of property names to values.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn prop_list(&self, path: &str) -> Result<HashMap<String, Vec<u8>>, crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let mut props: *mut apr::hash::apr_hash_t = std::ptr::null_mut();
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_prop_list(
                    &mut props,
                    path_cstr.as_ptr(),
                    self.ptr,
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)?;
            let mut result = HashMap::new();
            if !props.is_null() {
                let mut hi = unsafe { apr_sys::apr_hash_first(scratch_pool.as_mut_ptr(), props) };
                while !hi.is_null() {
                    let mut key: *const std::ffi::c_void = std::ptr::null();
                    let mut val: *mut std::ffi::c_void = std::ptr::null_mut();
                    let mut klen: apr_sys::apr_ssize_t = 0;
                    unsafe {
                        apr_sys::apr_hash_this(hi, &mut key, &mut klen, &mut val);
                    }
                    let name = unsafe { std::ffi::CStr::from_ptr(key as *const std::ffi::c_char) }
                        .to_str()
                        .expect("property name should be valid UTF-8")
                        .to_string();
                    let svn_str = unsafe { &*(val as *const subversion_sys::svn_string_t) };
                    let data = unsafe {
                        std::slice::from_raw_parts(svn_str.data as *const u8, svn_str.len as usize)
                    };
                    result.insert(name, data.to_vec());
                    hi = unsafe { apr_sys::apr_hash_next(hi) };
                }
            }
            Ok(result)
        })
    }

    /// Add a path to the working copy.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn add(
        &self,
        path: &str,
        copyfrom_url: Option<&str>,
        copyfrom_rev: Option<crate::Revnum>,
    ) -> Result<(), crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let copyfrom_url_cstr = copyfrom_url.map(std::ffi::CString::new).transpose()?;
        let copyfrom_rev_raw = copyfrom_rev.map(|r| r.0).unwrap_or(-1);
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_add3(
                    path_cstr.as_ptr(),
                    self.ptr,
                    subversion_sys::svn_depth_t_svn_depth_infinity,
                    copyfrom_url_cstr
                        .as_ref()
                        .map_or(std::ptr::null(), |c| c.as_ptr()),
                    copyfrom_rev_raw,
                    None,                 // cancel_func
                    std::ptr::null_mut(), // cancel_baton
                    None,                 // notify_func
                    std::ptr::null_mut(), // notify_baton
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)
        })
    }

    /// Delete a path from the working copy.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn delete(&self, path: &str, keep_local: bool) -> Result<(), crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_delete3(
                    path_cstr.as_ptr(),
                    self.ptr,
                    None,                 // cancel_func
                    std::ptr::null_mut(), // cancel_baton
                    None,                 // notify_func
                    std::ptr::null_mut(), // notify_baton
                    if keep_local { 1 } else { 0 },
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)
        })
    }

    /// Copy a path within the working copy.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn copy(&self, src: &str, dst_basename: &str) -> Result<(), crate::Error<'static>> {
        let src_cstr = crate::dirent::to_absolute_cstring(src)?;
        let dst_cstr = std::ffi::CString::new(dst_basename)?;
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_copy2(
                    src_cstr.as_ptr(),
                    self.ptr,
                    dst_cstr.as_ptr(),
                    None,                 // cancel_func
                    std::ptr::null_mut(), // cancel_baton
                    None,                 // notify_func
                    std::ptr::null_mut(), // notify_baton
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)
        })
    }

    /// Check whether a file has a binary svn:mime-type property.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn has_binary_prop(&self, path: &str) -> Result<bool, crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let mut has_binary: subversion_sys::svn_boolean_t = 0;
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_has_binary_prop(
                    &mut has_binary,
                    path_cstr.as_ptr(),
                    self.ptr,
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)?;
            Ok(has_binary != 0)
        })
    }

    /// Check whether a file's text is modified with respect to the base revision.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn text_modified(
        &self,
        path: &str,
        force_comparison: bool,
    ) -> Result<bool, crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let mut modified: subversion_sys::svn_boolean_t = 0;
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_text_modified_p(
                    &mut modified,
                    path_cstr.as_ptr(),
                    if force_comparison { 1 } else { 0 },
                    self.ptr,
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)?;
            Ok(modified != 0)
        })
    }

    /// Check whether a path's properties are modified with respect to the base revision.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn props_modified(&self, path: &str) -> Result<bool, crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let mut modified: subversion_sys::svn_boolean_t = 0;
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_props_modified_p(
                    &mut modified,
                    path_cstr.as_ptr(),
                    self.ptr,
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)?;
            Ok(modified != 0)
        })
    }

    /// Check whether a path is a working copy root.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn is_wc_root(&self, path: &str) -> Result<bool, crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let mut wc_root: subversion_sys::svn_boolean_t = 0;
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_is_wc_root(
                    &mut wc_root,
                    path_cstr.as_ptr(),
                    self.ptr,
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)?;
            Ok(wc_root != 0)
        })
    }

    /// Check whether a path has text, property, or tree conflicts.
    ///
    /// Returns `(text_conflicted, prop_conflicted, tree_conflicted)`.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn conflicted(&self, path: &str) -> Result<(bool, bool, bool), crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let mut text: subversion_sys::svn_boolean_t = 0;
        let mut prop: subversion_sys::svn_boolean_t = 0;
        let mut tree: subversion_sys::svn_boolean_t = 0;
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_conflicted_p2(
                    &mut text,
                    &mut prop,
                    &mut tree,
                    path_cstr.as_ptr(),
                    self.ptr,
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)?;
            Ok((text != 0, prop != 0, tree != 0))
        })
    }

    /// Get the ancestry (URL and revision) for a versioned path.
    ///
    /// Returns `(url, revision)`.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn get_ancestry(
        &self,
        path: &str,
    ) -> Result<(Option<String>, crate::Revnum), crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let mut url: *mut std::ffi::c_char = std::ptr::null_mut();
        let mut rev: subversion_sys::svn_revnum_t = -1;
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_get_ancestry(
                    &mut url,
                    &mut rev,
                    path_cstr.as_ptr(),
                    self.ptr,
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)?;
            let url_str = if url.is_null() {
                None
            } else {
                Some(
                    unsafe { std::ffi::CStr::from_ptr(url) }
                        .to_str()
                        .expect("URL should be valid UTF-8")
                        .to_string(),
                )
            };
            Ok((url_str, crate::Revnum(rev)))
        })
    }

    /// Get the property differences between the working copy and the base revision.
    ///
    /// Returns `(changes, original_props)`.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn get_prop_diffs(
        &self,
        path: &str,
    ) -> Result<(Vec<PropChange>, Option<HashMap<String, Vec<u8>>>), crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        with_tmp_pool(|scratch_pool| {
            let mut propchanges: *mut apr::tables::apr_array_header_t = std::ptr::null_mut();
            let mut original_props: *mut apr::hash::apr_hash_t = std::ptr::null_mut();
            let err = unsafe {
                subversion_sys::svn_wc_get_prop_diffs(
                    &mut propchanges,
                    &mut original_props,
                    path_cstr.as_ptr(),
                    self.ptr,
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)?;
            let changes = if propchanges.is_null() {
                Vec::new()
            } else {
                let array = unsafe {
                    apr::tables::TypedArray::<subversion_sys::svn_prop_t>::from_ptr(propchanges)
                };
                array
                    .iter()
                    .map(|prop| unsafe {
                        let name = std::ffi::CStr::from_ptr(prop.name)
                            .to_str()
                            .expect("Property name is not valid UTF-8")
                            .to_owned();
                        let value = if prop.value.is_null() {
                            None
                        } else {
                            Some(crate::svn_string_helpers::to_vec(&*prop.value))
                        };
                        PropChange { name, value }
                    })
                    .collect()
            };
            let original = if original_props.is_null() {
                None
            } else {
                let prop_hash = unsafe { crate::props::PropHash::from_ptr(original_props) };
                Some(prop_hash.to_hashmap())
            };
            Ok((changes, original))
        })
    }

    /// Mark a missing directory as deleted in the working copy.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn mark_missing_deleted(&self, path: &str) -> Result<(), crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_mark_missing_deleted(
                    path_cstr.as_ptr(),
                    self.ptr,
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)
        })
    }

    /// Set the repository root URL for a path, if not already set.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn maybe_set_repos_root(
        &self,
        path: &str,
        repos: &str,
    ) -> Result<(), crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let repos_cstr = std::ffi::CString::new(repos)?;
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_maybe_set_repos_root(
                    self.ptr,
                    path_cstr.as_ptr(),
                    repos_cstr.as_ptr(),
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)
        })
    }

    /// Add a repository lock to a path in the working copy.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn add_lock(&self, path: &str, lock: &Lock) -> Result<(), crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_add_lock(
                    path_cstr.as_ptr(),
                    lock.as_ptr(),
                    self.ptr,
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)
        })
    }

    /// Remove a repository lock from a path in the working copy.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn remove_lock(&self, path: &str) -> Result<(), crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_remove_lock(
                    path_cstr.as_ptr(),
                    self.ptr,
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)
        })
    }

    /// Remove a path from revision control.
    ///
    /// If `destroy_wf` is true, destroy the working file/directory.
    /// If `instant_error` is true, return an error immediately if a file
    /// is modified rather than trying to continue.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn remove_from_revision_control(
        &self,
        name: &str,
        destroy_wf: bool,
        instant_error: bool,
    ) -> Result<(), crate::Error<'static>> {
        let name_cstr = std::ffi::CString::new(name)?;
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_remove_from_revision_control(
                    self.ptr,
                    name_cstr.as_ptr(),
                    if destroy_wf { 1 } else { 0 },
                    if instant_error { 1 } else { 0 },
                    None,                 // cancel_func
                    std::ptr::null_mut(), // cancel_baton
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)
        })
    }

    /// Resolve a conflict on a path.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn resolved_conflict(
        &self,
        path: &str,
        resolve_text: bool,
        resolve_props: bool,
        resolve_tree: bool,
        depth: crate::Depth,
        conflict_choice: ConflictChoice,
    ) -> Result<(), crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_resolved_conflict4(
                    path_cstr.as_ptr(),
                    self.ptr,
                    if resolve_text { 1 } else { 0 },
                    if resolve_props { 1 } else { 0 },
                    if resolve_tree { 1 } else { 0 },
                    depth.into(),
                    conflict_choice.into(),
                    None,                 // notify_func
                    std::ptr::null_mut(), // notify_baton
                    None,                 // cancel_func
                    std::ptr::null_mut(), // cancel_baton
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)
        })
    }

    /// Revert changes to a path.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn revert(
        &self,
        path: &str,
        depth: crate::Depth,
        use_commit_times: bool,
    ) -> Result<(), crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_revert3(
                    path_cstr.as_ptr(),
                    self.ptr,
                    depth.into(),
                    if use_commit_times { 1 } else { 0 },
                    std::ptr::null(),     // changelist_filter
                    None,                 // cancel_func
                    std::ptr::null_mut(), // cancel_baton
                    None,                 // notify_func
                    std::ptr::null_mut(), // notify_baton
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)
        })
    }

    /// Set the changelist for a path.
    ///
    /// Pass `None` for `changelist` to remove the path from its changelist.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn set_changelist(
        &self,
        path: &str,
        changelist: Option<&str>,
    ) -> Result<(), crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let changelist_cstr = changelist.map(std::ffi::CString::new).transpose()?;
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_set_changelist(
                    path_cstr.as_ptr(),
                    changelist_cstr
                        .as_ref()
                        .map_or(std::ptr::null(), |c| c.as_ptr()),
                    self.ptr,
                    None,                 // cancel_func
                    std::ptr::null_mut(), // cancel_baton
                    None,                 // notify_func
                    std::ptr::null_mut(), // notify_baton
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)
        })
    }

    /// Crop a working copy tree to a given depth.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn crop_tree(
        &self,
        target: &str,
        depth: crate::Depth,
    ) -> Result<(), crate::Error<'static>> {
        let target_cstr = std::ffi::CString::new(target)?;
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_crop_tree(
                    self.ptr,
                    target_cstr.as_ptr(),
                    depth.into(),
                    None,                 // notify_func
                    std::ptr::null_mut(), // notify_baton
                    None,                 // cancel_func
                    std::ptr::null_mut(), // cancel_baton
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)
        })
    }

    /// Merge property changes into a path.
    ///
    /// Applies `propchanges` (a list of `(name, value)` pairs) to `path`.
    /// If `base_merge` is true, changes are applied to base props instead of working props.
    /// If `dry_run` is true, no actual changes are made.
    ///
    /// Returns the notification state for the merge.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn merge_prop_diffs(
        &self,
        path: &str,
        propchanges: &[PropChange],
        base_merge: bool,
        dry_run: bool,
    ) -> Result<u32, crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let mut state: subversion_sys::svn_wc_notify_state_t = 0;
        with_tmp_pool(|scratch_pool| {
            // Build apr_array of svn_prop_t
            let arr = unsafe {
                apr_sys::apr_array_make(
                    scratch_pool.as_mut_ptr(),
                    propchanges.len() as i32,
                    std::mem::size_of::<subversion_sys::svn_prop_t>() as i32,
                )
            };
            for pc in propchanges {
                let name_cstr = std::ffi::CString::new(pc.name.as_str()).unwrap();
                let name_ptr =
                    unsafe { apr_sys::apr_pstrdup(scratch_pool.as_mut_ptr(), name_cstr.as_ptr()) };
                let value_ptr = match &pc.value {
                    Some(v) => {
                        let svn_str = crate::string::BStr::from_bytes(v, scratch_pool);
                        svn_str.as_ptr() as *const subversion_sys::svn_string_t
                    }
                    None => std::ptr::null(),
                };
                let prop = subversion_sys::svn_prop_t {
                    name: name_ptr,
                    value: value_ptr,
                };
                unsafe {
                    let dest = apr_sys::apr_array_push(arr) as *mut subversion_sys::svn_prop_t;
                    *dest = prop;
                }
            }
            let err = unsafe {
                subversion_sys::svn_wc_merge_prop_diffs(
                    &mut state,
                    path_cstr.as_ptr(),
                    self.ptr,
                    arr,
                    if base_merge { 1 } else { 0 },
                    if dry_run { 1 } else { 0 },
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)?;
            Ok(state as u32)
        })
    }

    /// Get a translated version of a file.
    ///
    /// Returns the path to a translated copy of `src`, using the eol-style
    /// and keyword properties of `versioned_file`.
    ///
    /// Flags are a bitmask of `SVN_WC_TRANSLATE_*` constants.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn translated_file(
        &self,
        src: &str,
        versioned_file: &str,
        flags: u32,
    ) -> Result<String, crate::Error<'static>> {
        let src_cstr = crate::dirent::to_absolute_cstring(src)?;
        let versioned_cstr = crate::dirent::to_absolute_cstring(versioned_file)?;
        let mut xlated_path: *const std::ffi::c_char = std::ptr::null();
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_translated_file2(
                    &mut xlated_path,
                    src_cstr.as_ptr(),
                    versioned_cstr.as_ptr(),
                    self.ptr,
                    flags,
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)?;
            Ok(unsafe { std::ffi::CStr::from_ptr(xlated_path) }
                .to_str()
                .expect("path should be valid UTF-8")
                .to_string())
        })
    }

    /// Relocate a working copy from one repository root to another.
    ///
    /// `from` and `to` are the old and new repository URL prefixes.
    /// If `recurse` is true, the relocation applies recursively.
    /// The `validator` function is called with `(uuid, url, root_url)` for each
    /// relocated entry to validate the new URL.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn relocate(
        &self,
        path: &str,
        from: &str,
        to: &str,
        recurse: bool,
        validator: Option<&dyn Fn(&str, &str, &str) -> Result<(), crate::Error<'static>>>,
    ) -> Result<(), crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let from_cstr = std::ffi::CString::new(from)?;
        let to_cstr = std::ffi::CString::new(to)?;

        unsafe extern "C" fn validator_trampoline(
            baton: *mut std::ffi::c_void,
            uuid: *const std::ffi::c_char,
            url: *const std::ffi::c_char,
            root_url: *const std::ffi::c_char,
            _pool: *mut apr_sys::apr_pool_t,
        ) -> *mut subversion_sys::svn_error_t {
            let validator =
                &*(baton as *const &dyn Fn(&str, &str, &str) -> Result<(), crate::Error<'static>>);
            let uuid_str = std::ffi::CStr::from_ptr(uuid).to_str().unwrap();
            let url_str = std::ffi::CStr::from_ptr(url).to_str().unwrap();
            let root_str = std::ffi::CStr::from_ptr(root_url).to_str().unwrap();
            match validator(uuid_str, url_str, root_str) {
                Ok(()) => std::ptr::null_mut(),
                Err(e) => e.into_raw(),
            }
        }

        unsafe extern "C" fn noop_validator(
            _baton: *mut std::ffi::c_void,
            _uuid: *const std::ffi::c_char,
            _url: *const std::ffi::c_char,
            _root_url: *const std::ffi::c_char,
            _pool: *mut apr_sys::apr_pool_t,
        ) -> *mut subversion_sys::svn_error_t {
            std::ptr::null_mut()
        }

        let (func, baton): (
            subversion_sys::svn_wc_relocation_validator3_t,
            *mut std::ffi::c_void,
        ) = match &validator {
            Some(v) => (
                Some(validator_trampoline),
                v as *const _ as *mut std::ffi::c_void,
            ),
            None => (Some(noop_validator), std::ptr::null_mut()),
        };

        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_relocate3(
                    path_cstr.as_ptr(),
                    self.ptr,
                    from_cstr.as_ptr(),
                    to_cstr.as_ptr(),
                    if recurse { 1 } else { 0 },
                    func,
                    baton,
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)
        })
    }

    /// Get a single entry from the working copy.
    ///
    /// Returns `None` if the path is not versioned.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn entry(
        &self,
        path: &str,
        show_hidden: bool,
    ) -> Result<Option<Entry>, crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let mut entry_ptr: *const subversion_sys::svn_wc_entry_t = std::ptr::null();
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_entry(
                    &mut entry_ptr,
                    path_cstr.as_ptr(),
                    self.ptr,
                    if show_hidden { 1 } else { 0 },
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)?;
            if entry_ptr.is_null() {
                Ok(None)
            } else {
                Ok(Some(unsafe { Entry::from_raw(entry_ptr) }))
            }
        })
    }

    /// Read all entries in this directory.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn entries_read(
        &self,
        show_hidden: bool,
    ) -> Result<HashMap<String, Entry>, crate::Error<'static>> {
        let mut entries: *mut apr::hash::apr_hash_t = std::ptr::null_mut();
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_entries_read(
                    &mut entries,
                    self.ptr,
                    if show_hidden { 1 } else { 0 },
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)?;
            let mut result = HashMap::new();
            if !entries.is_null() {
                let mut hi = unsafe { apr_sys::apr_hash_first(scratch_pool.as_mut_ptr(), entries) };
                while !hi.is_null() {
                    let mut key: *const std::ffi::c_void = std::ptr::null();
                    let mut val: *mut std::ffi::c_void = std::ptr::null_mut();
                    let mut klen: apr_sys::apr_ssize_t = 0;
                    unsafe { apr_sys::apr_hash_this(hi, &mut key, &mut klen, &mut val) };
                    let name = unsafe { std::ffi::CStr::from_ptr(key as *const std::ffi::c_char) }
                        .to_str()
                        .expect("entry name should be valid UTF-8")
                        .to_string();
                    let entry =
                        unsafe { Entry::from_raw(val as *const subversion_sys::svn_wc_entry_t) };
                    result.insert(name, entry);
                    hi = unsafe { apr_sys::apr_hash_next(hi) };
                }
            }
            Ok(result)
        })
    }

    /// Get the status of a path (deprecated version 2 API).
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn status(&self, path: &str) -> Result<Status, crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let mut status_ptr: *mut subversion_sys::svn_wc_status2_t = std::ptr::null_mut();
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_status2(
                    &mut status_ptr,
                    path_cstr.as_ptr(),
                    self.ptr,
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)?;
            Ok(unsafe { Status::from_raw(status_ptr) })
        })
    }

    /// Walk entries in the working copy, calling `callback` for each entry.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn walk_entries<F>(
        &self,
        path: &str,
        mut callback: F,
        depth: crate::Depth,
        show_hidden: bool,
    ) -> Result<(), crate::Error<'static>>
    where
        F: FnMut(&str, &Entry) -> Result<(), crate::Error<'static>>,
    {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;

        unsafe extern "C" fn found_entry_trampoline<F>(
            path: *const std::ffi::c_char,
            entry: *const subversion_sys::svn_wc_entry_t,
            walk_baton: *mut std::ffi::c_void,
            _pool: *mut apr_sys::apr_pool_t,
        ) -> *mut subversion_sys::svn_error_t
        where
            F: FnMut(&str, &Entry) -> Result<(), crate::Error<'static>>,
        {
            let callback = &mut *(walk_baton as *mut F);
            let path_str = std::ffi::CStr::from_ptr(path).to_str().unwrap();
            let entry = Entry::from_raw(entry);
            match callback(path_str, &entry) {
                Ok(()) => std::ptr::null_mut(),
                Err(e) => e.into_raw(),
            }
        }

        unsafe extern "C" fn handle_error_trampoline(
            _path: *const std::ffi::c_char,
            err: *mut subversion_sys::svn_error_t,
            _walk_baton: *mut std::ffi::c_void,
            _pool: *mut apr_sys::apr_pool_t,
        ) -> *mut subversion_sys::svn_error_t {
            // Propagate the error as-is
            err
        }

        let callbacks = subversion_sys::svn_wc_entry_callbacks2_t {
            found_entry: Some(found_entry_trampoline::<F>),
            handle_error: Some(handle_error_trampoline),
        };
        let baton = &mut callback as *mut F as *mut std::ffi::c_void;

        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_walk_entries3(
                    path_cstr.as_ptr(),
                    self.ptr,
                    &callbacks,
                    baton,
                    depth.into(),
                    if show_hidden { 1 } else { 0 },
                    None,                 // cancel_func
                    std::ptr::null_mut(), // cancel_baton
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)
        })
    }

    /// Crawl working copy revisions, reporting to a reporter.
    #[cfg(feature = "ra")]
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn crawl_revisions(
        &self,
        path: &str,
        reporter: &crate::ra::WrapReporter,
        restore_files: bool,
        depth: crate::Depth,
        honor_depth_exclude: bool,
        depth_compatibility_trick: bool,
        use_commit_times: bool,
        notify_func: Option<&dyn Fn(&Notify)>,
    ) -> Result<(), crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let notify_baton = notify_func
            .map(|f| box_notify_baton_borrowed(f))
            .unwrap_or(std::ptr::null_mut());

        let result = with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_crawl_revisions4(
                    path_cstr.as_ptr(),
                    self.ptr,
                    reporter.as_ptr(),
                    reporter.as_baton(),
                    if restore_files { 1 } else { 0 },
                    depth.into(),
                    if honor_depth_exclude { 1 } else { 0 },
                    if depth_compatibility_trick { 1 } else { 0 },
                    if use_commit_times { 1 } else { 0 },
                    if notify_func.is_some() {
                        Some(wrap_notify_func)
                    } else {
                        None
                    },
                    notify_baton,
                    std::ptr::null_mut(), // traversal_info
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)
        });

        if !notify_baton.is_null() {
            unsafe { drop_notify_baton_borrowed(notify_baton) };
        }

        result
    }

    /// Transmit local text changes through a delta editor.
    ///
    /// Returns `(tempfile_path, md5_digest)` where `md5_digest` is 16 bytes.
    #[cfg(feature = "delta")]
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn transmit_text_deltas(
        &self,
        path: &str,
        fulltext: bool,
        file_editor: &crate::delta::WrapFileEditor<'_>,
    ) -> Result<(Option<String>, [u8; 16]), crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let mut tempfile: *const std::ffi::c_char = std::ptr::null();
        let mut digest = [0u8; 16]; // APR_MD5_DIGESTSIZE
        let (editor, file_baton) = file_editor.as_raw_parts();
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_transmit_text_deltas2(
                    &mut tempfile,
                    digest.as_mut_ptr(),
                    path_cstr.as_ptr(),
                    self.ptr,
                    if fulltext { 1 } else { 0 },
                    editor,
                    file_baton,
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)?;
            let tempfile_str = unsafe { cstr_to_option(tempfile) };
            Ok((tempfile_str, digest))
        })
    }

    /// Transmit local property changes through a delta editor.
    ///
    /// Looks up the entry for `path` internally.
    #[cfg(feature = "delta")]
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn transmit_prop_deltas(
        &self,
        path: &str,
        file_editor: &crate::delta::WrapFileEditor<'_>,
    ) -> Result<Option<String>, crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let mut tempfile: *const std::ffi::c_char = std::ptr::null();
        let (editor, baton) = file_editor.as_raw_parts();
        with_tmp_pool(|scratch_pool| {
            // Look up the entry to pass to the C function
            let mut entry_ptr: *const subversion_sys::svn_wc_entry_t = std::ptr::null();
            let err = unsafe {
                subversion_sys::svn_wc_entry(
                    &mut entry_ptr,
                    path_cstr.as_ptr(),
                    self.ptr,
                    0, // show_hidden = false
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)?;
            if entry_ptr.is_null() {
                return Err(crate::Error::with_raw_status(
                    subversion_sys::svn_errno_t_SVN_ERR_ENTRY_NOT_FOUND as i32,
                    None,
                    &format!("No entry for '{path}'"),
                ));
            }
            let err = unsafe {
                subversion_sys::svn_wc_transmit_prop_deltas(
                    path_cstr.as_ptr(),
                    self.ptr,
                    entry_ptr,
                    editor,
                    baton,
                    &mut tempfile,
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)?;
            Ok(unsafe { cstr_to_option(tempfile) })
        })
    }

    /// Perform a 3-way file merge.
    ///
    /// Returns the merge outcome.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn merge(
        &self,
        left: &str,
        right: &str,
        merge_target: &str,
        left_label: Option<&str>,
        right_label: Option<&str>,
        target_label: Option<&str>,
        dry_run: bool,
        diff3_cmd: Option<&str>,
        merge_options: &[&str],
        prop_diff: &[PropChange],
    ) -> Result<u32, crate::Error<'static>> {
        let left_cstr = crate::dirent::to_absolute_cstring(left)?;
        let right_cstr = crate::dirent::to_absolute_cstring(right)?;
        let target_cstr = crate::dirent::to_absolute_cstring(merge_target)?;
        let left_label_cstr = left_label.map(std::ffi::CString::new).transpose()?;
        let right_label_cstr = right_label.map(std::ffi::CString::new).transpose()?;
        let target_label_cstr = target_label.map(std::ffi::CString::new).transpose()?;
        let diff3_cmd_cstr = diff3_cmd.map(std::ffi::CString::new).transpose()?;
        let mut merge_outcome: subversion_sys::svn_wc_merge_outcome_t = 0;

        with_tmp_pool(|scratch_pool| {
            // Build merge_options array
            let merge_opts_arr = if merge_options.is_empty() {
                std::ptr::null()
            } else {
                let arr = unsafe {
                    apr_sys::apr_array_make(
                        scratch_pool.as_mut_ptr(),
                        merge_options.len() as i32,
                        std::mem::size_of::<*const std::ffi::c_char>() as i32,
                    )
                };
                for opt in merge_options {
                    let cstr = std::ffi::CString::new(*opt).unwrap();
                    let ptr =
                        unsafe { apr_sys::apr_pstrdup(scratch_pool.as_mut_ptr(), cstr.as_ptr()) };
                    unsafe {
                        let dest = apr_sys::apr_array_push(arr) as *mut *const std::ffi::c_char;
                        *dest = ptr;
                    }
                }
                arr as *const _
            };

            // Build prop_diff array
            let prop_diff_arr = unsafe {
                apr_sys::apr_array_make(
                    scratch_pool.as_mut_ptr(),
                    prop_diff.len() as i32,
                    std::mem::size_of::<subversion_sys::svn_prop_t>() as i32,
                )
            };
            for pc in prop_diff {
                let name_cstr = std::ffi::CString::new(pc.name.as_str()).unwrap();
                let name_ptr =
                    unsafe { apr_sys::apr_pstrdup(scratch_pool.as_mut_ptr(), name_cstr.as_ptr()) };
                let value_ptr = match &pc.value {
                    Some(v) => {
                        let svn_str = crate::string::BStr::from_bytes(v, scratch_pool);
                        svn_str.as_ptr() as *const subversion_sys::svn_string_t
                    }
                    None => std::ptr::null(),
                };
                unsafe {
                    let dest =
                        apr_sys::apr_array_push(prop_diff_arr) as *mut subversion_sys::svn_prop_t;
                    *dest = subversion_sys::svn_prop_t {
                        name: name_ptr,
                        value: value_ptr,
                    };
                }
            }

            let err = unsafe {
                subversion_sys::svn_wc_merge3(
                    &mut merge_outcome,
                    left_cstr.as_ptr(),
                    right_cstr.as_ptr(),
                    target_cstr.as_ptr(),
                    self.ptr,
                    left_label_cstr
                        .as_ref()
                        .map_or(std::ptr::null(), |c| c.as_ptr()),
                    right_label_cstr
                        .as_ref()
                        .map_or(std::ptr::null(), |c| c.as_ptr()),
                    target_label_cstr
                        .as_ref()
                        .map_or(std::ptr::null(), |c| c.as_ptr()),
                    if dry_run { 1 } else { 0 },
                    diff3_cmd_cstr
                        .as_ref()
                        .map_or(std::ptr::null(), |c| c.as_ptr()),
                    merge_opts_arr,
                    prop_diff_arr,
                    None,                 // conflict_func
                    std::ptr::null_mut(), // conflict_baton
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)?;
            Ok(merge_outcome as u32)
        })
    }

    /// Merge properties into a path, with base properties.
    ///
    /// Returns the notification state for the merge.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn merge_props(
        &self,
        path: &str,
        baseprops: &HashMap<String, Vec<u8>>,
        propchanges: &[PropChange],
        base_merge: bool,
        dry_run: bool,
    ) -> Result<u32, crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let mut state: subversion_sys::svn_wc_notify_state_t = 0;
        with_tmp_pool(|scratch_pool| {
            // Build baseprops hash
            let baseprops_hash = unsafe { apr_sys::apr_hash_make(scratch_pool.as_mut_ptr()) };
            for (name, value) in baseprops {
                let name_cstr = std::ffi::CString::new(name.as_str()).unwrap();
                let name_ptr =
                    unsafe { apr_sys::apr_pstrdup(scratch_pool.as_mut_ptr(), name_cstr.as_ptr()) };
                let svn_str = crate::string::BStr::from_bytes(value, scratch_pool);
                unsafe {
                    apr_sys::apr_hash_set(
                        baseprops_hash,
                        name_ptr as *const _,
                        apr_sys::APR_HASH_KEY_STRING as apr_sys::apr_ssize_t,
                        svn_str.as_ptr() as *const _,
                    );
                }
            }

            // Build propchanges array
            let arr = unsafe {
                apr_sys::apr_array_make(
                    scratch_pool.as_mut_ptr(),
                    propchanges.len() as i32,
                    std::mem::size_of::<subversion_sys::svn_prop_t>() as i32,
                )
            };
            for pc in propchanges {
                let name_cstr = std::ffi::CString::new(pc.name.as_str()).unwrap();
                let name_ptr =
                    unsafe { apr_sys::apr_pstrdup(scratch_pool.as_mut_ptr(), name_cstr.as_ptr()) };
                let value_ptr = match &pc.value {
                    Some(v) => {
                        let svn_str = crate::string::BStr::from_bytes(v, scratch_pool);
                        svn_str.as_ptr() as *const subversion_sys::svn_string_t
                    }
                    None => std::ptr::null(),
                };
                unsafe {
                    let dest = apr_sys::apr_array_push(arr) as *mut subversion_sys::svn_prop_t;
                    *dest = subversion_sys::svn_prop_t {
                        name: name_ptr,
                        value: value_ptr,
                    };
                }
            }

            let err = unsafe {
                subversion_sys::svn_wc_merge_props2(
                    &mut state,
                    path_cstr.as_ptr(),
                    self.ptr,
                    baseprops_hash,
                    arr,
                    if base_merge { 1 } else { 0 },
                    if dry_run { 1 } else { 0 },
                    None,                 // conflict_func
                    std::ptr::null_mut(), // conflict_baton
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)?;
            Ok(state as u32)
        })
    }

    /// Queue a path for post-commit processing using this access baton.
    ///
    /// This calls the deprecated `svn_wc_queue_committed` which takes
    /// an `svn_wc_adm_access_t` rather than an `svn_wc_context_t`.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn queue_committed(
        &self,
        path: &str,
        committed_queue: &mut CommittedQueue,
        recurse: bool,
        remove_lock: bool,
        remove_changelist: bool,
        digest: Option<&[u8; 16]>,
    ) -> Result<(), crate::Error<'static>> {
        let path_cstr = crate::dirent::to_absolute_cstring(path)?;
        let mut queue_ptr = committed_queue.as_mut_ptr();
        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_queue_committed(
                    &mut queue_ptr,
                    path_cstr.as_ptr(),
                    self.ptr,
                    if recurse { 1 } else { 0 },
                    std::ptr::null(), // wcprop_changes
                    if remove_lock { 1 } else { 0 },
                    if remove_changelist { 1 } else { 0 },
                    digest.map(|d| d.as_ptr()).unwrap_or(std::ptr::null()),
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)
        })
    }

    /// Process a committed queue using this access baton.
    ///
    /// This calls the deprecated `svn_wc_process_committed_queue` which takes
    /// an `svn_wc_adm_access_t` rather than an `svn_wc_context_t`.
    #[deprecated(note = "Use svn_wc_context_t based APIs where possible")]
    pub fn process_committed_queue(
        &self,
        committed_queue: &mut CommittedQueue,
        new_revnum: crate::Revnum,
        rev_date: Option<&str>,
        rev_author: Option<&str>,
    ) -> Result<(), crate::Error<'static>> {
        let rev_date_cstr = rev_date.map(std::ffi::CString::new).transpose()?;
        let rev_author_cstr = rev_author.map(std::ffi::CString::new).transpose()?;

        with_tmp_pool(|scratch_pool| {
            let err = unsafe {
                subversion_sys::svn_wc_process_committed_queue(
                    committed_queue.as_mut_ptr(),
                    self.ptr,
                    new_revnum.0,
                    rev_date_cstr
                        .as_ref()
                        .map_or(std::ptr::null(), |s| s.as_ptr()),
                    rev_author_cstr
                        .as_ref()
                        .map_or(std::ptr::null(), |s| s.as_ptr()),
                    scratch_pool.as_mut_ptr(),
                )
            };
            svn_result(err)
        })
    }
}

#[allow(deprecated)]
impl Adm {
    /// Explicitly close the access baton, releasing all resources and locks.
    pub fn close(&mut self) {
        if !self.ptr.is_null() {
            unsafe {
                subversion_sys::svn_wc_adm_close2(self.ptr, self._pool.as_mut_ptr());
            }
            self.ptr = std::ptr::null_mut();
        }
    }
}

#[allow(deprecated)]
impl Drop for Adm {
    fn drop(&mut self) {
        self.close();
    }
}