svn 0.1.8

Async Rust SVN client for Subversion svn://, svn+ssh://, and ra_svn workflows.
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
//! Public data types returned by this crate.
//!
//! Most of these types are thin wrappers around the values returned by the
//! `ra_svn` protocol.

use std::collections::BTreeMap;
use std::fmt::{Display, Formatter};

/// A Subversion property list (`name -> raw bytes`).
///
/// Property values can be binary; callers should treat the value as opaque
/// bytes unless they know it is UTF-8.
pub type PropertyList = BTreeMap<String, Vec<u8>>;
/// A map of `path -> mergeinfo` strings as returned by `get-mergeinfo`.
pub type MergeInfoCatalog = BTreeMap<String, String>;

/// Inherited properties for a path.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct InheritedProps {
    /// The repository path these properties apply to.
    pub path: String,
    /// The inherited property list.
    pub props: PropertyList,
}

/// Repository metadata returned by the server.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct RepositoryInfo {
    /// Repository UUID.
    pub uuid: String,
    /// Repository root URL.
    ///
    /// Some older servers may not provide a root URL during handshake; in that
    /// case this is an empty string.
    pub root_url: String,
    /// Server-reported repository capabilities.
    pub capabilities: Vec<String>,
}

/// Information negotiated during the initial handshake.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ServerInfo {
    /// Capability list negotiated during handshake.
    ///
    /// This includes capabilities announced in the initial greeting and any
    /// additional capabilities announced in `repos-info`.
    pub server_caps: Vec<String>,
    /// Repository metadata.
    pub repository: RepositoryInfo,
}

/// A successful commit result returned by [`crate::RaSvnSession::commit`].
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CommitInfo {
    /// The new committed revision number.
    pub new_rev: u64,
    /// Commit date, if provided by the server (usually an RFC3339-ish string).
    pub date: Option<String>,
    /// Commit author, if provided by the server.
    pub author: Option<String>,
    /// Server-reported post-commit error, if any.
    pub post_commit_err: Option<String>,
}

/// Result metadata returned by [`crate::RaSvnSession::get_file_with_result`].
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct GetFileResult {
    /// The revision that was actually served.
    pub rev: u64,
    /// Optional checksum string (as reported by the server).
    pub checksum: Option<String>,
    /// File properties (if requested).
    pub props: PropertyList,
    /// Inherited properties (if requested and supported by the server).
    pub inherited_props: Vec<InheritedProps>,
    /// Number of bytes streamed to the provided output writer.
    pub bytes_written: u64,
}

/// A `(revision, path)` pair as returned by `get-locations`.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LocationEntry {
    /// The revision number.
    pub rev: u64,
    /// Repository-relative path at this revision.
    pub path: String,
}

/// A location segment as returned by `get-location-segments`.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LocationSegment {
    /// Start revision of the segment (inclusive).
    pub range_start: u64,
    /// End revision of the segment (inclusive).
    pub range_end: u64,
    /// Repository path for this segment, or `None` for gaps.
    pub path: Option<String>,
}

/// Controls how mergeinfo may be inherited when requesting mergeinfo.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum MergeInfoInheritance {
    /// Only explicit mergeinfo on the requested paths.
    Explicit,
    /// Include inherited mergeinfo.
    Inherited,
    /// Use the nearest ancestor with mergeinfo.
    NearestAncestor,
}

impl MergeInfoInheritance {
    pub(crate) fn as_word(self) -> &'static str {
        match self {
            Self::Explicit => "explicit",
            Self::Inherited => "inherited",
            Self::NearestAncestor => "nearest-ancestor",
        }
    }
}

/// A single property delta entry (name + new value).
///
/// `value == None` represents deletion of the property.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PropDelta {
    /// Property name.
    pub name: String,
    /// New property value (raw bytes), or `None` to delete.
    pub value: Option<Vec<u8>>,
}

/// A file revision entry as returned by `get-file-revs`.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FileRev {
    /// Repository-relative path.
    pub path: String,
    /// Revision number.
    pub rev: u64,
    /// Revision properties for this revision.
    pub rev_props: PropertyList,
    /// Property deltas for this revision.
    pub prop_deltas: Vec<PropDelta>,
    /// Whether this is a merged revision.
    pub merged_revision: bool,
    /// Raw delta chunks (svndiff) as received from the server.
    pub delta_chunks: Vec<Vec<u8>>,
}

/// A [`FileRev`] entry with materialized file contents.
///
/// This is useful when you want a `get-file-revs` result that is directly
/// consumable without manually applying svndiff chunks.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FileRevContents {
    /// The file-revision metadata and raw delta chunks.
    pub file_rev: FileRev,
    /// The full file contents for this revision.
    pub contents: Vec<u8>,
}

/// One annotated line as returned by [`crate::RaSvnSession::blame_file`].
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct BlameLine {
    /// The revision that last changed this line (best-effort, line-based).
    pub rev: u64,
    /// The author for `rev`, if available in revision properties.
    pub author: Option<String>,
    /// The date for `rev`, if available in revision properties.
    pub date: Option<String>,
    /// The line contents (includes the trailing `\\n` when present).
    pub line: String,
}

/// A lock description as returned by `get-lock(s)` or `lock`.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LockDesc {
    /// Repository-relative path (no leading `/`) that is locked.
    pub path: String,
    /// Opaque lock token.
    pub token: String,
    /// Lock owner.
    pub owner: String,
    /// Optional lock comment.
    pub comment: Option<String>,
    /// Creation date string as reported by the server.
    pub created: String,
    /// Expiration date string as reported by the server, if any.
    pub expires: Option<String>,
}

/// A log entry returned by `log`.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct LogEntry {
    /// Revision number.
    pub rev: u64,
    /// Changed paths list (may be empty if not requested).
    pub changed_paths: Vec<ChangedPath>,
    /// Author, if provided.
    pub author: Option<String>,
    /// Date, if provided.
    pub date: Option<String>,
    /// Commit message, if provided.
    pub message: Option<String>,
    /// Revision properties returned by the server.
    ///
    /// This may be empty if not requested or if the server does not support
    /// custom revision properties via `log`.
    pub rev_props: PropertyList,
    /// Whether this log entry has child entries (merged revisions).
    pub has_children: bool,
    /// Whether this entry represents an invalid revision marker.
    ///
    /// Subversion uses this to mark the end of a merged-revision subtree.
    pub invalid_revnum: bool,
    /// Whether this entry represents a subtractive merge.
    pub subtractive_merge: bool,
}

/// A single path change entry within a [`LogEntry`].
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ChangedPath {
    /// Change action (usually `A`, `D`, `M`, `R`).
    pub action: String,
    /// Changed repository path.
    pub path: String,
    /// Copy source path, if this change was made by a copy.
    pub copy_from_path: Option<String>,
    /// Copy source revision, if this change was made by a copy.
    pub copy_from_rev: Option<u64>,
    /// Node kind, if provided by the server.
    pub node_kind: Option<NodeKind>,
    /// Whether text was modified, if known.
    pub text_mods: Option<bool>,
    /// Whether props were modified, if known.
    pub prop_mods: Option<bool>,
}

/// The kind of a node in the repository.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum NodeKind {
    /// No node exists at the requested path/revision.
    None,
    /// A file node.
    File,
    /// A directory node.
    Dir,
    /// An unknown kind (usually a forward-compatibility fallback).
    Unknown,
}

impl NodeKind {
    pub(crate) fn from_word(word: &str) -> Self {
        match word {
            "none" => Self::None,
            "file" => Self::File,
            "dir" => Self::Dir,
            _ => Self::Unknown,
        }
    }

    /// Returns a stable string representation used in the `ra_svn` protocol.
    pub fn as_str(self) -> &'static str {
        match self {
            Self::None => "none",
            Self::File => "file",
            Self::Dir => "dir",
            Self::Unknown => "unknown",
        }
    }
}

impl Display for NodeKind {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

/// A directory entry as returned by directory listing operations.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct DirEntry {
    /// Entry name (basename).
    pub name: String,
    /// Entry path relative to the listing root.
    pub path: String,
    /// Node kind.
    pub kind: NodeKind,
    /// File size, if provided.
    pub size: Option<u64>,
    /// Whether the node has properties, if provided.
    pub has_props: Option<bool>,
    /// Created revision, if provided.
    pub created_rev: Option<u64>,
    /// Created date, if provided.
    pub created_date: Option<String>,
    /// Last author, if provided.
    pub last_author: Option<String>,
}

/// Result of `get-dir` as returned by [`crate::RaSvnSession::list_dir`].
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct DirListing {
    /// The revision served by the server.
    pub rev: u64,
    /// Directory entries.
    pub entries: Vec<DirEntry>,
}

/// Subversion depth value (used by `list`, `update`, `switch`, `status`, etc.).
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Depth {
    /// Exclude entries (the target itself only).
    Empty,
    /// Include file children.
    Files,
    /// Include immediate children (files and dirs) but not recurse.
    Immediates,
    /// Fully recursive.
    Infinity,
}

impl Depth {
    pub(crate) fn as_word(self) -> &'static str {
        match self {
            Self::Empty => "empty",
            Self::Files => "files",
            Self::Immediates => "immediates",
            Self::Infinity => "infinity",
        }
    }
}

/// Fields to request for directory entries when using the `list` capability.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum DirentField {
    /// Node kind.
    Kind,
    /// File size.
    Size,
    /// Whether properties are present.
    HasProps,
    /// Created revision.
    CreatedRev,
    /// Time / date.
    Time,
    /// Last author.
    LastAuthor,
    /// `word` field (server-specific).
    Word,
}

impl DirentField {
    pub(crate) fn as_word(self) -> &'static str {
        match self {
            Self::Kind => "kind",
            Self::Size => "size",
            Self::HasProps => "has-props",
            Self::CreatedRev => "created-rev",
            Self::Time => "time",
            Self::LastAuthor => "last-author",
            Self::Word => "word",
        }
    }
}

/// A `stat` result entry.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct StatEntry {
    /// Node kind.
    pub kind: NodeKind,
    /// File size, if provided.
    pub size: Option<u64>,
    /// Whether properties are present, if provided.
    pub has_props: Option<bool>,
    /// Created revision, if provided.
    pub created_rev: Option<u64>,
    /// Created date, if provided.
    pub created_date: Option<String>,
    /// Last author, if provided.
    pub last_author: Option<String>,
}

/// A protocol capability that may be announced during handshake.
///
/// Capabilities are used to gate optional protocol features and commands.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Capability {
    /// The mandatory edit pipelining capability.
    EditPipeline,
    /// Support for svndiff1 deltas.
    Svndiff1,
    /// Support for accepting svndiff2 deltas.
    AcceptsSvndiff2,
    /// Support for `absent-dir` / `absent-file` editor commands.
    AbsentEntries,
    /// Support for setting revision properties during commit (`commit-revprops`).
    CommitRevProps,
    /// Support for the `get-mergeinfo` command.
    MergeInfo,
    /// Support for depth-related parameters.
    Depth,
    /// Support for `change-rev-prop2` (`atomic-revprops`).
    AtomicRevProps,
    /// Support for inherited properties (`inherited-props` / `get-iprops`).
    InheritedProps,
    /// Support for requesting revision properties from `log` (`log-revprops`).
    LogRevProps,
    /// Support for partial replay (`partial-replay`).
    PartialReplay,
    /// Support for ephemeral transaction properties (`ephemeral-txnprops`).
    EphemeralTxnProps,
    /// Support for retrieving file revs in reverse order (`get-file-revs-reverse`).
    GetFileRevsReverse,
    /// Support for the `list` command.
    List,
}

impl Capability {
    /// Returns the wire capability word used by the `ra_svn` protocol.
    pub fn as_wire_word(self) -> &'static str {
        match self {
            Self::EditPipeline => "edit-pipeline",
            Self::Svndiff1 => "svndiff1",
            Self::AcceptsSvndiff2 => "accepts-svndiff2",
            Self::AbsentEntries => "absent-entries",
            Self::CommitRevProps => "commit-revprops",
            Self::MergeInfo => "mergeinfo",
            Self::Depth => "depth",
            Self::AtomicRevProps => "atomic-revprops",
            Self::InheritedProps => "inherited-props",
            Self::LogRevProps => "log-revprops",
            Self::PartialReplay => "partial-replay",
            Self::EphemeralTxnProps => "ephemeral-txnprops",
            Self::GetFileRevsReverse => "get-file-revs-reverse",
            Self::List => "list",
        }
    }
}