Skip to content

Commit

Permalink
[clone] first steps towards launching git-upload-pack while…
Browse files Browse the repository at this point in the history
…reusing as much code as possible.
Some refactoring required.
  • Loading branch information
Byron committed Aug 28, 2020
1 parent 52ff13c commit 41f05f1
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Please see _'Development Status'_ for a listing of all crates and their capabili

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

Expand Down
69 changes: 62 additions & 7 deletions git-transport/src/client/file.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
use crate::client::git;
use crate::{
client::{self, git, MessageKind, RequestWriter, SetServiceResponse, WriteMode},
Service,
};
use quick_error::quick_error;
use std::{path::Path, process};
use std::process::Stdio;
use std::{
path::{Path, PathBuf},
process,
};

quick_error! {
#[derive(Debug)]
Expand All @@ -11,9 +18,57 @@ quick_error! {
}
}

pub fn connect(
_path: &Path,
_version: crate::Protocol,
) -> Result<git::Connection<process::ChildStdout, process::ChildStdin>, Error> {
unimplemented!("file connection")
// from https://github.com/git/git/blob/20de7e7e4f4e9ae52e6cc7cfaa6469f186ddb0fa/environment.c#L115:L115
const ENV_VARS_TO_REMOVE: &'static [&'static str] = &[
"GIT_ALTERNATE_OBJECT_DIRECTORIES",
"GIT_CONFIG",
"GIT_CONFIG_PARAMETERS",
"GIT_OBJECT_DIRECTORY",
"GIT_DIR",
"GIT_WORK_TREE",
"GIT_IMPLICIT_WORK_TREE",
"GIT_GRAFT_FILE",
"GIT_INDEX_FILE",
"GIT_NO_REPLACE_OBJECTS",
"GIT_REPLACE_REF_BASE",
"GIT_PREFIX",
"GIT_INTERNAL_SUPER_PREFIX",
"GIT_SHALLOW_FILE",
"GIT_COMMON_DIR",
];

pub struct SpawnProcessOnDemand {
path: PathBuf,
version: crate::Protocol,
connection: Option<git::Connection<process::ChildStdout, process::ChildStdin>>,
}

impl client::Transport for SpawnProcessOnDemand {
fn handshake(&mut self, service: Service) -> Result<SetServiceResponse, client::Error> {
assert!(
self.connection.is_none(),
"cannot handshake twice with the same connection"
);
let mut cmd = std::process::Command::new(service.as_str());
for env_to_remove in ENV_VARS_TO_REMOVE {
cmd.env_remove(env_to_remove);
}
cmd.stderr(Stdio::null()).stdout(Stdio::piped()).stdin(Stdio::piped());
cmd.arg("--strict").arg("--timeout=0");
let child = cmd.spawn()?;
// self.connection = Some(git::Connection {})
unimplemented!("invoke command")
}

fn request(&mut self, write_mode: WriteMode, on_drop: Vec<MessageKind>) -> Result<RequestWriter, client::Error> {
unimplemented!()
}
}

pub fn connect(path: &Path, version: crate::Protocol) -> Result<SpawnProcessOnDemand, std::convert::Infallible> {
Ok(SpawnProcessOnDemand {
path: path.to_owned(),
version,
connection: None,
})
}
4 changes: 4 additions & 0 deletions git-url/tests/parse/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ fn relative_file_path_without_protocol() -> crate::Result {
assert_url(
"../../path/to/git",
url(Protocol::File, None, None, None, b"../../path/to/git", None),
)?;
assert_url(
"path/to/git",
url(Protocol::File, None, None, None, b"path/to/git", None),
)
}

Expand Down
6 changes: 6 additions & 0 deletions tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
* **gixp-pack-receive**
* [ ] hookup `git-protocol` with delegate to allow for receiving full packs
* [ ] **gixp-pack-receive** may optionally write received refs to the specified directory
* [ ] journey tests for each connection method
* [ ] file
* [ ] git
* [ ] ssh
* [ ] https (unauthenticated)
* [ ] https (authenticated)

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

Expand Down

0 comments on commit 41f05f1

Please sign in to comment.