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
44
55 use git_packetline::PacketLine;
66
7−use crate::client::capabilities;
87 use crate::{
9− client::{self, SetServiceResponse},
8+ client::{self, capabilities, Capabilities, SetServiceResponse},
109 Protocol, Service,
1110 };
1211
@@ -46,6 +45,49 @@ pub(crate) mod message { · 33 unmodified lines
4645 }
4746 out
4847 }
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+ }
4991 }
5092
5193 /// The way to connect to a process speaking the `git` protocol.
@@ -91,7 +133,7 @@ where · 39 unmodified lines
91133 capabilities,
92134 refs,
93135 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)?;
95137 Ok(SetServiceResponse {
96138 actual_protocol,
97139 capabilities,
@@ -251,6 +293,3 @@ pub mod connect { · 153 unmodified lines
251293 }
252294 }
253295 pub use connect::connect;
254−
255−#[cfg(test)]
256−mod tests;
git-transport/src/client/blocking_io/git/tests.rs+0−43
@@ -1,43 +0,0 @@
1−mod 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
88 pub use traits::{Error, GetResponse, Http, PostResponse};
99
1010 use crate::{
11− client::{self, capabilities, ExtendedBufRead, HandleProgress, MessageKind, RequestWriter},
11+ client::{self, capabilities, Capabilities, ExtendedBufRead, HandleProgress, MessageKind, RequestWriter},
1212 Protocol, Service,
1313 };
1414
@@ -131,7 +131,7 @@ impl<H: Http> client::Transport for Transport<H> { · 116 unmodified lines
131131 capabilities,
132132 refs,
133133 protocol: actual_protocol,
134− } = capabilities::Capabilities::from_lines_with_version_detection(line_reader)?;
134+ } = Capabilities::from_lines_with_version_detection(line_reader)?;
135135 self.actual_version = actual_protocol;
136136 self.service = Some(service);
137137 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