History

[git-transport] refactor

Sebastian Thiel committed 5 years ago

Commit 2342e8a1 parent 957403e3 files · +47 −51Browse files

Unified · Split

3 files
  1. git-transport/src/client/blocking_io/git.rs +45 −6
  2. git-transport/src/client/blocking_io/git/tests.rs +0 −43
  3. git-transport/src/client/blocking_io/http/mod.rs +2 −2
git-transport/src/client/blocking_io/git.rsrenamed from git-transport/src/client/blocking_io/git/mod.rs+45−6
@@ -4,9 +4,8 @@ use bstr::BString; · 3 unmodified lines
4 4
5use git_packetline::PacketLine;5use git_packetline::PacketLine;
6 6
7use crate::client::capabilities;
8use crate::{7use crate::{
9 client::{self, SetServiceResponse},8 client::{self, capabilities, Capabilities, SetServiceResponse},
10 Protocol, Service,9 Protocol, Service,
11};10};
12 11
@@ -46,6 +45,49 @@ pub(crate) mod message { · 33 unmodified lines
46 }45 }
47 out46 out
48 }47 }
48 #[cfg(test)]
49 mod tests {
50 use crate::{client::blocking_io::git, Protocol, Service};
51
52 #[test]
53 fn version_1_without_host_and_version() {
54 assert_eq!(
55 git::message::connect(Service::UploadPack, Protocol::V1, b"hello/world", None),
56 "git-upload-pack hello/world\0"
57 )
58 }
59 #[test]
60 fn version_2_without_host_and_version() {
61 assert_eq!(
62 git::message::connect(Service::UploadPack, Protocol::V2, b"hello\\world", None),
63 "git-upload-pack hello\\world\0\0version=2\0"
64 )
65 }
66 #[test]
67 fn with_host_without_port() {
68 assert_eq!(
69 git::message::connect(
70 Service::UploadPack,
71 Protocol::V1,
72 b"hello\\world",
73 Some(&("host".into(), None))
74 ),
75 "git-upload-pack hello\\world\0host=host\0"
76 )
77 }
78 #[test]
79 fn with_host_with_port() {
80 assert_eq!(
81 git::message::connect(
82 Service::UploadPack,
83 Protocol::V1,
84 b"hello\\world",
85 Some(&("host".into(), Some(404)))
86 ),
87 "git-upload-pack hello\\world\0host=host:404\0"
88 )
89 }
90 }
49}91}
50 92
51/// The way to connect to a process speaking the `git` protocol.93/// The way to connect to a process speaking the `git` protocol.
@@ -91,7 +133,7 @@ where · 39 unmodified lines
91 capabilities,133 capabilities,
92 refs,134 refs,
93 protocol: actual_protocol,135 protocol: actual_protocol,
94 } = capabilities::Capabilities::from_lines_with_version_detection(&mut self.line_provider)?;136 } = Capabilities::from_lines_with_version_detection(&mut self.line_provider)?;
95 Ok(SetServiceResponse {137 Ok(SetServiceResponse {
96 actual_protocol,138 actual_protocol,
97 capabilities,139 capabilities,
@@ -251,6 +293,3 @@ pub mod connect { · 153 unmodified lines
251 }293 }
252}294}
253pub use connect::connect;295pub use connect::connect;
254
255#[cfg(test)]
256mod tests;
git-transport/src/client/blocking_io/git/tests.rs+0−43
@@ -1,43 +0,0 @@
1mod message {
2 use crate::client::blocking_io::git;
3 use crate::{Protocol, Service};
4
5 #[test]
6 fn version_1_without_host_and_version() {
7 assert_eq!(
8 git::message::connect(Service::UploadPack, Protocol::V1, b"hello/world", None),
9 "git-upload-pack hello/world\0"
10 )
11 }
12 #[test]
13 fn version_2_without_host_and_version() {
14 assert_eq!(
15 git::message::connect(Service::UploadPack, Protocol::V2, b"hello\\world", None),
16 "git-upload-pack hello\\world\0\0version=2\0"
17 )
18 }
19 #[test]
20 fn with_host_without_port() {
21 assert_eq!(
22 git::message::connect(
23 Service::UploadPack,
24 Protocol::V1,
25 b"hello\\world",
26 Some(&("host".into(), None))
27 ),
28 "git-upload-pack hello\\world\0host=host\0"
29 )
30 }
31 #[test]
32 fn with_host_with_port() {
33 assert_eq!(
34 git::message::connect(
35 Service::UploadPack,
36 Protocol::V1,
37 b"hello\\world",
38 Some(&("host".into(), Some(404)))
39 ),
40 "git-upload-pack hello\\world\0host=host:404\0"
41 )
42 }
43}
git-transport/src/client/blocking_io/http/mod.rs+2−2
@@ -8,7 +8,7 @@ use git_packetline::PacketLine; · 7 unmodified lines
8pub use traits::{Error, GetResponse, Http, PostResponse};8pub use traits::{Error, GetResponse, Http, PostResponse};
9 9
10use crate::{10use crate::{
11 client::{self, capabilities, ExtendedBufRead, HandleProgress, MessageKind, RequestWriter},11 client::{self, capabilities, Capabilities, ExtendedBufRead, HandleProgress, MessageKind, RequestWriter},
12 Protocol, Service,12 Protocol, Service,
13};13};
14 14
@@ -131,7 +131,7 @@ impl<H: Http> client::Transport for Transport<H> { · 116 unmodified lines
131 capabilities,131 capabilities,
132 refs,132 refs,
133 protocol: actual_protocol,133 protocol: actual_protocol,
134 } = capabilities::Capabilities::from_lines_with_version_detection(line_reader)?;134 } = Capabilities::from_lines_with_version_detection(line_reader)?;
135 self.actual_version = actual_protocol;135 self.actual_version = actual_protocol;
136 self.service = Some(service);136 self.service = Some(service);
137 Ok(client::SetServiceResponse {137 Ok(client::SetServiceResponse {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t