The long awaited, exhalted huge networking stack change.
parent: tbd commit: 21b6a72
1 | use ; |
2 | use FromStr; |
3 | |
4 | use ; |
5 | |
6 | use crate GiteratedObject; |
7 | |
8 | use ; |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | pub use *; |
15 | pub use *; |
16 | pub use *; |
17 | |
18 | /// A repository, defined by the instance it exists on along with |
19 | /// its owner and name. |
20 | /// |
21 | /// # Textual Format |
22 | /// A repository's textual reference is defined as: |
23 | /// |
24 | /// `{owner: User}/{name: String}@{instance: Instance}` |
25 | /// |
26 | /// # Examples |
27 | /// For the repository named `foo` owned by `barson:giterated.dev` on the instance |
28 | /// `giterated.dev`, the following [`Repository`] initialization would |
29 | /// be valid: |
30 | /// |
31 | /// ``` |
32 | //# use giterated_models::model::repository::Repository; |
33 | //# use giterated_models::model::instance::Instance; |
34 | //# use giterated_models::model::user::User; |
35 | /// let repository = Repository { |
36 | /// owner: User::from_str("barson:giterated.dev").unwrap(), |
37 | /// name: String::from("foo"), |
38 | /// instance: Instance::from_str("giterated.dev").unwrap() |
39 | /// }; |
40 | /// |
41 | /// // This is correct |
42 | /// assert_eq!(Repository::from_str("barson:giterated.dev/[email protected]").unwrap(), repository); |
43 | /// ``` |
44 | |
45 | |
46 | pub owner: User, |
47 | pub name: String, |
48 | /// Instance the repository is on |
49 | pub instance: Instance, |
50 | |
51 | |
52 | |
53 | |
54 | f.write_str |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | "repository" |
61 | |
62 | |
63 | |
64 | Ok |
65 | |
66 | |
67 | |
68 | self.instance.home_uri |
69 | |
70 | |
71 | |
72 | |
73 | type Error = RepositoryParseError; |
74 | |
75 | |
76 | Self from_str |
77 | |
78 | |
79 | |
80 | |
81 | type Err = RepositoryParseError; |
82 | |
83 | |
84 | let mut by_ampersand = s.split; |
85 | let mut path_split = by_ampersand.next .ok_or?.split; |
86 | |
87 | let instance = from_str |
88 | .map_err?; |
89 | let owner = from_str |
90 | .map_err?; |
91 | let name = path_split.next .ok_or?.to_string; |
92 | |
93 | Ok |
94 | instance, |
95 | owner, |
96 | name, |
97 | |
98 | |
99 | |
100 | |
101 | |
102 | |
103 | ; |
104 | |
105 | /// Visibility of the repository to the general eye |
106 | |
107 | |
108 | |
109 | Public, |
110 | Unlisted, |
111 | Private, |
112 | |
113 | |
114 | /// Implements [`Display`] for [`RepositoryVisiblity`] using [`Debug`] |
115 | |
116 | |
117 | write! |
118 | |
119 | |
120 | |
121 | |
122 | |
123 | /// Name of the repository |
124 | /// |
125 | /// This is different than the [`Repository`] name, |
126 | /// which may be a path. |
127 | pub name: String, |
128 | /// Owner of the Repository |
129 | pub owner: User, |
130 | /// Repository description |
131 | pub description: , |
132 | /// Repository visibility |
133 | pub visibility: Visibility, |
134 | /// Default branch of the repository |
135 | pub default_branch: DefaultBranch, |
136 | /// Last commit made to the repository |
137 | pub latest_commit: , |
138 | /// Repository statistics |
139 | pub stats: RepositoryStatistics, |
140 | /// Revision of the displayed tree |
141 | pub tree_rev: , |
142 | /// Repository tree |
143 | pub tree: , |
144 | |
145 | |
146 | /// Generic repository statistics |
147 | |
148 | |
149 | /// Amount of commits made to this branch in the repository |
150 | pub commits: usize, |
151 | /// Amount of branches the repository has |
152 | pub branches: usize, |
153 | /// Amount of tags the repository has |
154 | pub tags: usize, |
155 | |
156 | |
157 | /// Repository branch |
158 | |
159 | |
160 | /// Full reference name |
161 | pub name: String, |
162 | /// Whether the repository is stale or not |
163 | pub stale: bool, |
164 | /// The last commit made to the branch |
165 | pub last_commit: , |
166 | |
167 | |
168 | |
169 | |
170 | /// ID of the file |
171 | pub id: String, |
172 | /// Content of the file |
173 | pub content: , |
174 | /// If the file is binary or not |
175 | pub binary: bool, |
176 | /// File size in bytes |
177 | pub size: usize, |
178 | |
179 | |
180 | |
181 | |
182 | /// "to" side of the diff commit |
183 | pub new_commit: Commit, |
184 | /// Total number of files changed |
185 | pub files_changed: usize, |
186 | /// Total number of insertions |
187 | pub insertions: usize, |
188 | /// Total number of deletions |
189 | pub deletions: usize, |
190 | /// List of changed files |
191 | pub files: , |
192 | |
193 | |
194 | /// Represents the type of change made to a [`RepositoryDiffFile`] |
195 | |
196 | |
197 | /// No changes |
198 | Unmodified, |
199 | Added, |
200 | Deleted, |
201 | /// Content changed between old and new |
202 | Modified, |
203 | /// Renamed between old and new |
204 | Renamed, |
205 | /// Copied from another old entry |
206 | Copied, |
207 | /// Ignored item in workdir |
208 | Ignored, |
209 | /// Untracked item in workdir |
210 | Untracked, |
211 | /// Type of file changed between old and new |
212 | Typechange, |
213 | /// File is unreadable |
214 | Unreadable, |
215 | /// File in the index is conflicted |
216 | Conflicted, |
217 | |
218 | |
219 | |
220 | |
221 | match status |
222 | => Self Unmodified, | Unmodified
223 | => Self Added, | Added
224 | => Self Deleted, | Deleted
225 | => Self Modified, | Modified
226 | => Self Renamed, | Renamed
227 | => Self Copied, | Copied
228 | => Self Ignored, | Ignored
229 | => Self Untracked, | Untracked
230 | => Self Typechange, | Typechange
231 | => Self Unreadable, | Unreadable
232 | => Self Conflicted, | Conflicted
233 | |
234 | |
235 | |
236 | |
237 | /// Represents a single file of a diff |
238 | |
239 | |
240 | /// The type of change made to this file |
241 | pub status: RepositoryDiffFileStatus, |
242 | /// "From" side of the diff, can be nonexistent if file for example got added for the first time |
243 | pub old_file_info: , |
244 | /// "To" side of the diff, can be nonexistent if file got removed |
245 | pub new_file_info: , |
246 | /// Individual chunks of changes in this file |
247 | pub chunks: , |
248 | |
249 | |
250 | /// Represents one side of a file diff [`RepositoryDiffFile`] |
251 | |
252 | |
253 | /// ID of the file |
254 | pub id: String, |
255 | /// Path of the entry relative to the working directory of the repository |
256 | pub path: String, |
257 | /// Size in bytes |
258 | pub size: u64, |
259 | /// If the file is binary or not |
260 | pub binary: bool, |
261 | |
262 | |
263 | /// Represents a single chunk of a file diff [`RepositoryDiffFile`] |
264 | |
265 | |
266 | /// Header of the chunk |
267 | pub header: , |
268 | /// Starting line number of the old file |
269 | pub old_start: u32, |
270 | /// Number of lines in "from" side of this chunk |
271 | pub old_lines: u32, |
272 | /// Starting line number of the new file |
273 | pub new_start: u32, |
274 | /// Number of lines in "to" side of this chunk |
275 | pub new_lines: u32, |
276 | /// Lines of the chunk |
277 | pub lines: , |
278 | |
279 | |
280 | /// Represents the change type of the [`RepositoryChunkLine`], incomplete of what git actually provides. |
281 | |
282 | |
283 | Context, |
284 | Addition, |
285 | Deletion, |
286 | |
287 | |
288 | |
289 | |
290 | match line_type |
291 | => Self Context, | Context
292 | => Self Addition, | Addition
293 | => Self Deletion, | Deletion
294 | _ => Self Context, |
295 | |
296 | |
297 | |
298 | |
299 | /// Represents a single line of a [`RepositoryDiffFileChunk`] |
300 | |
301 | |
302 | /// Type of change the line is |
303 | pub change_type: RepositoryChunkLineType, |
304 | /// Content of the line |
305 | pub content: String, |
306 | /// Line number in old file |
307 | pub old_line_num: , |
308 | /// Line number in new file |
309 | pub new_line_num: , |
310 | |
311 | |
312 | |
313 | |
314 | Tree, |
315 | Blob, |
316 | |
317 | |
318 | /// Stored info for our tree entries |
319 | |
320 | |
321 | /// ID of the tree/blob |
322 | pub id: String, |
323 | /// Name of the tree/blob |
324 | pub name: String, |
325 | /// Type of the tree entry |
326 | pub object_type: RepositoryObjectType, |
327 | /// Git supplies us with the mode at all times, and people like it displayed. |
328 | pub mode: i32, |
329 | /// File size |
330 | pub size: , |
331 | /// Last commit made to the tree/blob |
332 | pub last_commit: , |
333 | |
334 | |
335 | |
336 | // I love you Emilia <3 |
337 | |
338 | Self |
339 | id: id.to_string, |
340 | name: name.to_string, |
341 | object_type, |
342 | mode, |
343 | size: None, |
344 | last_commit: None, |
345 | |
346 | |
347 | |
348 | |
349 | |
350 | |
351 | pub tree_entry: RepositoryTreeEntry, |
352 | pub commit: Commit, |
353 | |
354 | |
355 | /// Info about a git commit |
356 | |
357 | |
358 | /// Unique commit ID |
359 | pub oid: String, |
360 | /// Shortened abbreviated OID |
361 | /// This starts at the git config's "core.abbrev" length (default 7 characters) and |
362 | /// iteratively extends to a longer string if that length is ambiguous. The |
363 | /// result will be unambiguous (at least until new objects are added to the repository). |
364 | pub short_oid: String, |
365 | /// First paragraph of the full message |
366 | pub summary: , |
367 | /// Everything in the full message apart from the first paragraph |
368 | pub body: , |
369 | /// All commit id's of the parents of this commit |
370 | pub parents: , |
371 | /// Who created the commit |
372 | pub author: CommitSignature, |
373 | /// Who committed the commit |
374 | pub committer: CommitSignature, |
375 | /// Time when the commit happened |
376 | pub time: NaiveDateTime, |
377 | |
378 | |
379 | /// Gets all info from [`git2::Commit`] for easy use |
380 | |
381 | |
382 | Self |
383 | oid: commit.id .to_string, |
384 | // This shouldn't ever fail, as we already know the object has an oid. |
385 | short_oid: commit |
386 | .as_object |
387 | .short_id |
388 | .unwrap |
389 | .as_str |
390 | .unwrap |
391 | .to_string, |
392 | summary: commit.summary .map, |
393 | body: commit.body .map, |
394 | parents: commit |
395 | .parents |
396 | .map |
397 | ., |
398 | author: commit.author .into, |
399 | committer: commit.committer .into, |
400 | time: from_timestamp_opt .unwrap, |
401 | |
402 | |
403 | |
404 | |
405 | /// Git commit signature |
406 | |
407 | |
408 | pub name: , |
409 | pub email: , |
410 | pub time: NaiveDateTime, |
411 | |
412 | |
413 | /// Converts the signature from git2 into something usable without explicit lifetimes. |
414 | |
415 | |
416 | Self |
417 | name: signature.name .map, |
418 | email: signature.email .map, |
419 | time: from_timestamp_opt .unwrap, |
420 | |
421 | |
422 | |
423 | |
424 | |
425 | |
426 | pub repository: Repository, |
427 | pub owner: User, |
428 | pub visibility: RepositoryVisibility, |
429 | pub description: , |
430 | pub last_commit: , |
431 | |
432 | |
433 | |
434 | |
435 | pub name: String, |
436 | pub color: String, |
437 | |
438 | |
439 | |
440 | |
441 | pub author: User, |
442 | pub id: u64, |
443 | pub title: String, |
444 | pub contents: String, |
445 | pub labels: , |
446 | |
447 |