1
+ //! See [GitSource].
2
+
1
3
use crate :: core:: source:: { MaybePackage , QueryKind , Source , SourceId } ;
2
4
use crate :: core:: GitReference ;
3
5
use crate :: core:: { Dependency , Package , PackageId , Summary } ;
@@ -13,18 +15,71 @@ use std::fmt::{self, Debug, Formatter};
13
15
use std:: task:: Poll ;
14
16
use url:: Url ;
15
17
18
+ /// `GitSource` contains one or more packages gathering from a Git repository.
19
+ /// Under the hood it uses [`PathSource`] to discover packages inside the
20
+ /// repository.
21
+ ///
22
+ /// ## Filesystem layout
23
+ ///
24
+ /// During a successful `GitSource` download, at least two Git repositories are
25
+ /// created: one is the shared Git database of this remote, and the other is the
26
+ /// Git checkout to a specific revision, which contains the actual files to be
27
+ /// compiled. Multiple checkouts can be cloned from a single Git database.
28
+ ///
29
+ /// Those repositories are located at Cargo's Git cache directory
30
+ /// `$CARGO_HOME/git`. The file tree of the cache directory roughly looks like:
31
+ ///
32
+ /// ```text
33
+ /// $CARGO_HOME/git/
34
+ /// ├── checkouts/
35
+ /// │ ├── gimli-a0d193bd15a5ed96/
36
+ /// │ │ ├── 8e73ef0/ # Git short ID for a certain revision
37
+ /// │ │ ├── a2a4b78/
38
+ /// │ │ └── e33d1ac/
39
+ /// │ ├── log-c58e1db3de7c154d-shallow/
40
+ /// │ │ └── 11eda98/
41
+ /// └── db/
42
+ /// ├── gimli-a0d193bd15a5ed96/
43
+ /// └── log-c58e1db3de7c154d-shallow/
44
+ /// ```
45
+ ///
46
+ /// For more on Git cache directory, see ["Cargo Home"] in The Cargo Book.
47
+ ///
48
+ /// For more on the directory format `<pkg>-<hash>[-shallow]`, see [`ident`]
49
+ /// and [`ident_shallow`].
50
+ ///
51
+ /// ## Locked to a revision
52
+ ///
53
+ /// Once a `GitSource` is fetched, it will resolve to a specific commit revision.
54
+ /// This is often mentioned as "locked revision" (`locked_rev`) throughout the
55
+ /// codebase. The revision is written into `Cargo.lock`. This is essential since
56
+ /// we want to ensure a package can compiles with the same set of files when
57
+ /// a `Cargo.lock` is present. With the `locked_rev` provided, `GitSource` can
58
+ /// precisely fetch the same revision from the Git repository.
59
+ ///
60
+ /// ["Cargo Home"]: https://doc.rust-lang.org/nightly/cargo/guide/cargo-home.html#directories
16
61
pub struct GitSource < ' cfg > {
62
+ /// The git remote which we're going to fetch from.
17
63
remote : GitRemote ,
64
+ /// The Git reference from the manifest file.
18
65
manifest_reference : GitReference ,
66
+ /// The revision which a git source is locked to.
67
+ /// This is expected to be set after the Git repository is fetched.
19
68
locked_rev : Option < git2:: Oid > ,
69
+ /// The unique identifier of this source.
20
70
source_id : SourceId ,
71
+ /// The underlying path source to discover packages inside the Git repository.
21
72
path_source : Option < PathSource < ' cfg > > ,
73
+ /// The identifer of this source for Cargo's Git cache directory.
74
+ /// See [`ident`] for more.
22
75
ident : String ,
23
76
config : & ' cfg Config ,
77
+ /// Disables status messages.
24
78
quiet : bool ,
25
79
}
26
80
27
81
impl < ' cfg > GitSource < ' cfg > {
82
+ /// Creates a git source for the given [`SourceId`].
28
83
pub fn new ( source_id : SourceId , config : & ' cfg Config ) -> CargoResult < GitSource < ' cfg > > {
29
84
assert ! ( source_id. is_git( ) , "id is not git, id={}" , source_id) ;
30
85
@@ -59,10 +114,14 @@ impl<'cfg> GitSource<'cfg> {
59
114
Ok ( source)
60
115
}
61
116
117
+ /// Gets the remote repository URL.
62
118
pub fn url ( & self ) -> & Url {
63
119
self . remote . url ( )
64
120
}
65
121
122
+ /// Returns the packages discovered by this source. It may fetch the Git
123
+ /// repository as well as walk the filesystem if package informations
124
+ /// haven't yet updated.
66
125
pub fn read_packages ( & mut self ) -> CargoResult < Vec < Package > > {
67
126
if self . path_source . is_none ( ) {
68
127
self . invalidate_cache ( ) ;
@@ -72,7 +131,8 @@ impl<'cfg> GitSource<'cfg> {
72
131
}
73
132
}
74
133
75
- /// Create an identifier from a URL, essentially turning `proto://host/path/repo` into `repo-<hash-of-url>`.
134
+ /// Create an identifier from a URL,
135
+ /// essentially turning `proto://host/path/repo` into `repo-<hash-of-url>`.
76
136
fn ident ( id : & SourceId ) -> String {
77
137
let ident = id
78
138
. canonical_url ( )
@@ -86,10 +146,12 @@ fn ident(id: &SourceId) -> String {
86
146
format ! ( "{}-{}" , ident, short_hash( id. canonical_url( ) ) )
87
147
}
88
148
89
- /// Like `ident()`, but appends `-shallow` to it, turning `proto://host/path/repo` into `repo-<hash-of-url>-shallow`.
149
+ /// Like [`ident()`], but appends `-shallow` to it, turning
150
+ /// `proto://host/path/repo` into `repo-<hash-of-url>-shallow`.
90
151
///
91
- /// It's important to separate shallow from non-shallow clones for reasons of backwards compatibility - older
92
- /// cargo's aren't necessarily handling shallow clones correctly.
152
+ /// It's important to separate shallow from non-shallow clones for reasons of
153
+ /// backwards compatibility --- older cargo's aren't necessarily handling
154
+ /// shallow clones correctly.
93
155
fn ident_shallow ( id : & SourceId , is_shallow : bool ) -> String {
94
156
let mut ident = ident ( id) ;
95
157
if is_shallow {
0 commit comments