Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 41f05f1

Browse files
committed
[clone] first steps towards launching git-upload-pack while…
…reusing as much code as possible. Some refactoring required.
1 parent 52ff13c commit 41f05f1

4 files changed

Lines changed: 74 additions & 9 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Please see _'Development Status'_ for a listing of all crates and their capabili
127127

128128
### git-transport
129129
* [ ] general purpose `connect(…)` for clients
130-
* [ ] _file://_ and launching service application
130+
* [ ] _file://_ launches service application
131131
* [ ] _ssh://_ launches service application in a remote shell using _ssh_
132132
* [ ] _git://_ establishes a tcp connection to a git daemon
133133
* [x] _http(s)://_ establishes connections to web server
@@ -143,7 +143,7 @@ Please see _'Development Status'_ for a listing of all crates and their capabili
143143
* [x] send values + receive data with sidebands
144144
* [x] V2 handshake
145145
* [x] send command request, receive response with sideband support
146-
* [ ] ~~dumb~~ - _we opt out using this protocol seems too slow to be useful, unless it downloads entire packs for clones?_
146+
* [ ] ~~'dumb'~~ - _we opt out using this protocol seems too slow to be useful, unless it downloads entire packs for clones?_
147147
* [x] authentication failures are communicated by io::ErrorKind::PermissionDenied, allowing other layers to retry
148148
* [ ] API documentation with examples
149149

git-transport/src/client/file.rs

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
use crate::client::git;
1+
use crate::{
2+
client::{self, git, MessageKind, RequestWriter, SetServiceResponse, WriteMode},
3+
Service,
4+
};
25
use quick_error::quick_error;
3-
use std::{path::Path, process};
6+
use std::process::Stdio;
7+
use std::{
8+
path::{Path, PathBuf},
9+
process,
10+
};
411

512
quick_error! {
613
#[derive(Debug)]
@@ -11,9 +18,57 @@ quick_error! {
1118
}
1219
}
1320

14-
pub fn connect(
15-
_path: &Path,
16-
_version: crate::Protocol,
17-
) -> Result<git::Connection<process::ChildStdout, process::ChildStdin>, Error> {
18-
unimplemented!("file connection")
21+
// from https://github.com/git/git/blob/20de7e7e4f4e9ae52e6cc7cfaa6469f186ddb0fa/environment.c#L115:L115
22+
const ENV_VARS_TO_REMOVE: &'static [&'static str] = &[
23+
"GIT_ALTERNATE_OBJECT_DIRECTORIES",
24+
"GIT_CONFIG",
25+
"GIT_CONFIG_PARAMETERS",
26+
"GIT_OBJECT_DIRECTORY",
27+
"GIT_DIR",
28+
"GIT_WORK_TREE",
29+
"GIT_IMPLICIT_WORK_TREE",
30+
"GIT_GRAFT_FILE",
31+
"GIT_INDEX_FILE",
32+
"GIT_NO_REPLACE_OBJECTS",
33+
"GIT_REPLACE_REF_BASE",
34+
"GIT_PREFIX",
35+
"GIT_INTERNAL_SUPER_PREFIX",
36+
"GIT_SHALLOW_FILE",
37+
"GIT_COMMON_DIR",
38+
];
39+
40+
pub struct SpawnProcessOnDemand {
41+
path: PathBuf,
42+
version: crate::Protocol,
43+
connection: Option<git::Connection<process::ChildStdout, process::ChildStdin>>,
44+
}
45+
46+
impl client::Transport for SpawnProcessOnDemand {
47+
fn handshake(&mut self, service: Service) -> Result<SetServiceResponse, client::Error> {
48+
assert!(
49+
self.connection.is_none(),
50+
"cannot handshake twice with the same connection"
51+
);
52+
let mut cmd = std::process::Command::new(service.as_str());
53+
for env_to_remove in ENV_VARS_TO_REMOVE {
54+
cmd.env_remove(env_to_remove);
55+
}
56+
cmd.stderr(Stdio::null()).stdout(Stdio::piped()).stdin(Stdio::piped());
57+
cmd.arg("--strict").arg("--timeout=0");
58+
let child = cmd.spawn()?;
59+
// self.connection = Some(git::Connection {})
60+
unimplemented!("invoke command")
61+
}
62+
63+
fn request(&mut self, write_mode: WriteMode, on_drop: Vec<MessageKind>) -> Result<RequestWriter, client::Error> {
64+
unimplemented!()
65+
}
66+
}
67+
68+
pub fn connect(path: &Path, version: crate::Protocol) -> Result<SpawnProcessOnDemand, std::convert::Infallible> {
69+
Ok(SpawnProcessOnDemand {
70+
path: path.to_owned(),
71+
version,
72+
connection: None,
73+
})
1974
}

git-url/tests/parse/file.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ fn relative_file_path_without_protocol() -> crate::Result {
4646
assert_url(
4747
"../../path/to/git",
4848
url(Protocol::File, None, None, None, b"../../path/to/git", None),
49+
)?;
50+
assert_url(
51+
"path/to/git",
52+
url(Protocol::File, None, None, None, b"path/to/git", None),
4953
)
5054
}
5155

tasks.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
* **gixp-pack-receive**
4747
* [ ] hookup `git-protocol` with delegate to allow for receiving full packs
4848
* [ ] **gixp-pack-receive** may optionally write received refs to the specified directory
49+
* [ ] journey tests for each connection method
50+
* [ ] file
51+
* [ ] git
52+
* [ ] ssh
53+
* [ ] https (unauthenticated)
54+
* [ ] https (authenticated)
4955

5056
### NEXT ITERATION: Fetching _(more analysis needed after previous block)_
5157

0 commit comments

Comments
 (0)