History

[clone] move packet-line code into own crate

This is when I learned that there is also a long-running processes format that uses packet-line to communicate. Thus it doesn't belong in transport anymore, which was the previous 'best fit'. Since it's a serialization format, setting up its own crate makes quite some sense.

Sebastian Thiel committed 6 years ago

Commit 879af671 parent bba0a4727 files · +77 −45Browse files

Unified · Split

27 files
  1. Cargo.lock +13 −3
  2. Cargo.toml +1 −0
  3. Makefile +2 −0
  4. README.md +3 −0
  5. etc/check-package-size.sh +2 −1
  6. etc/release.sh +1 −1
  7. git-packetline/Cargo.toml +27 −0
  8. git-packetline/src/borrowed.rs +1 −1
  9. git-packetline/src/decode.rs +1 −4
  10. git-packetline/src/encode.rs +1 −1
  11. git-packetline/src/lib.rs +12 −1
  12. git-packetline/src/read.rs +1 −1
  13. git-packetline/tests/fixtures/v1/01-clone.combined-output +0 −0
  14. git-packetline/tests/fixtures/v1/01.request +0 −0
  15. git-packetline/tests/fixtures/v1/fetch/01-many-refs.request +0 −0
  16. git-packetline/tests/fixtures/v1/fetch/01-many-refs.response +0 −0
  17. git-packetline/tests/packet_line/decode.rs +4 −5
  18. git-packetline/tests/packet_line/encode.rs +1 −1
  19. git-packetline/tests/packet_line/mod.rs +0 −0
  20. git-packetline/tests/packet_line/read.rs +5 −5
  21. git-packetline/tests/packetline.rs +3 −0
  22. git-protocol/Cargo.toml +1 −1
  23. git-protocol/src/remote_progress.rs +1 −1
  24. git-protocol/tests/remote_progress/mod.rs +1 −1
  25. git-transport/Cargo.toml +0 −4
  26. git-transport/src/lib.rs +0 −16
  27. git-transport/tests/transport.rs +0 −2
Cargo.lock+13−3
@@ -649,13 +649,25 @@ dependencies = [ · 648 unmodified lines
649649 "walkdir",
650650 ]
651651
652+[[package]]
653+name = "git-packetline"
654+version = "0.1.0"
655+dependencies = [
656+ "bstr",
657+ "git-features",
658+ "git-odb",
659+ "hex",
660+ "quick-error 2.0.0",
661+ "serde",
662+]
663+
652664 [[package]]
653665 name = "git-protocol"
654666 version = "0.1.0"
655667 dependencies = [
656668 "bstr",
657669 "btoi",
658− "git-transport",
670+ "git-packetline",
659671 "nom",
660672 "quick-error 2.0.0",
661673 "serde",
@@ -683,9 +695,7 @@ dependencies = [ · 21 unmodified lines
683695 "bstr",
684696 "curl",
685697 "git-features",
686− "git-odb",
687698 "git-url",
688− "hex",
689699 "quick-error 2.0.0",
690700 "serde",
691701 ]
Cargo.toml+1−0
@@ -91,5 +91,6 @@ members = [ · 90 unmodified lines
9191 "git-protocol",
9292 "git-url",
9393 "git-transport",
94+ "git-packetline",
9495 "git-tui",
9596 ]
Makefile+2−0
@@ -83,6 +83,8 @@ check: ## Build all code in suitable configurations · 82 unmodified lines
8383 cd git-object && cargo check --all-features
8484 cd git-odb && cargo check --all-features \
8585 && cargo check
86+ cd git-packetline && cargo check --all-features \
87+ && cargo check
8688 cd git-protocol && cargo check --all-features \
8789 && cargo check
8890 cd git-url && cargo check --all-features \
README.md+3−0
@@ -142,6 +142,9 @@ Please see _'Development Status'_ for a listing of all crates and their capabili · 141 unmodified lines
142142 * [x] initialize
143143 * [ ] Proper configuration depending on platform (e.g. ignorecase, filemode, …)
144144 * [ ] [Signed commits and tags](https://github.com/Byron/gitoxide/issues/12)
145+ * [ ] sparse checkout support
146+ * [ ] .gitignore handling
147+ * [ ] checkout/stage conversions clean + smudge as in .gitattributes
145148 * [ ] read and write all data types
146149 * [ ] rev-parsing and ref history
147150 * [ ] remotes with push and pull
etc/check-package-size.sh+2−1
@@ -22,6 +22,7 @@ indent cargo diet -n --package-size-limit 25KB · 21 unmodified lines
2222 (enter git-object && indent cargo diet -n --package-size-limit 15KB)
2323 (enter git-odb && indent cargo diet -n --package-size-limit 50KB)
2424 (enter git-protocol && indent cargo diet -n --package-size-limit 5KB)
25+(enter git-packetline && indent cargo diet -n --package-size-limit 7KB)
2526 (enter git-repository && indent cargo diet -n --package-size-limit 10KB)
26−(enter git-transport && indent cargo diet -n --package-size-limit 10KB)
27+(enter git-transport && indent cargo diet -n --package-size-limit 5KB)
2728 (enter gitoxide-core && indent cargo diet -n --package-size-limit 10KB)
etc/release.sh+1−1
@@ -4,6 +4,6 @@ set -eu -o pipefail · 3 unmodified lines
44
55 ./etc/check-package-size.sh
66
7−for crate in git-features git-ref git-object git-odb git-repository gitoxide-core .; do
7+for crate in git-features git-ref git-object git-odb git-packetline git-transport git-protocol git-repository gitoxide-core .; do
88 (cd $crate && cargo release "$@")
99 done
git-packetline/Cargo.toml+27−0
@@ -0,0 +1,27 @@
1+[package]
2+name = "git-packetline"
3+version = "0.1.0"
4+repository = "https://github.com/Byron/git-oxide"
5+license = "MIT/Apache-2.0"
6+description = "A WIP crate of the gitoxide project implementing the pkt-line serialization format"
7+authors = ["Sebastian Thiel <sebastian.thiel@icloud.com>"]
8+edition = "2018"
9+include = ["src/**/*"]
10+
11+[lib]
12+doctest = false
13+
14+[features]
15+serde1 = ["serde", "bstr/serde1"]
16+
17+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
18+
19+[dependencies]
20+git-features = { version = "^0.3.0", path = "../git-features" }
21+serde = { version = "1.0.114", optional = true, default-features = false, features = ["std", "derive"]}
22+quick-error = "2.0.0"
23+hex = "0.4.2"
24+bstr = { version = "0.2.13", default-features = false, features = ["std"] }
25+
26+[dev-dependencies]
27+git-odb = { version = "0.3.0", path = "../git-odb" }
git-packetline/src/borrowed.rsrenamed from git-transport/src/packet_line/borrowed.rs+1−1
@@ -1,4 +1,4 @@
1−use crate::packet_line::{encode, Channel};
1+use crate::{encode, Channel};
22 use bstr::BStr;
33 use std::io;
44
git-packetline/src/decode.rsrenamed from git-transport/src/packet_line/decode.rs+1−4
@@ -1,8 +1,5 @@
11 use crate::{
2− packet_line::{
3− DELIMITER_LINE, ERR_PREFIX, FLUSH_LINE, MAX_DATA_LEN, MAX_LINE_LEN, RESPONSE_END_LINE, U16_HEX_BYTES,
4− },
5− PacketLine,
2+ PacketLine, {DELIMITER_LINE, ERR_PREFIX, FLUSH_LINE, MAX_DATA_LEN, MAX_LINE_LEN, RESPONSE_END_LINE, U16_HEX_BYTES},
63 };
74 use bstr::BString;
85 use quick_error::quick_error;
git-packetline/src/encode.rsrenamed from git-transport/src/packet_line/encode.rs+1−1
@@ -1,4 +1,4 @@
1−use crate::packet_line::{Channel, DELIMITER_LINE, ERR_PREFIX, FLUSH_LINE, MAX_DATA_LEN, RESPONSE_END_LINE};
1+use crate::{Channel, DELIMITER_LINE, ERR_PREFIX, FLUSH_LINE, MAX_DATA_LEN, RESPONSE_END_LINE};
22 use quick_error::quick_error;
33 use std::io;
44
git-packetline/src/lib.rsrenamed from git-transport/src/packet_line/mod.rs+12−1
@@ -1,3 +1,4 @@
1+#![forbid(unsafe_code)]
12 pub(crate) const U16_HEX_BYTES: usize = 4;
23 pub(crate) const MAX_DATA_LEN: usize = 65516;
34 pub(crate) const MAX_LINE_LEN: usize = MAX_DATA_LEN + U16_HEX_BYTES;
@@ -14,8 +15,18 @@ pub enum Channel { · 10 unmodified lines
1415 Error = 3,
1516 }
1617
18+#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
19+#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
20+pub struct RemoteProgress<'a> {
21+ #[cfg_attr(feature = "serde1", serde(borrow))]
22+ pub action: &'a bstr::BStr,
23+ pub percent: Option<u32>,
24+ pub step: Option<usize>,
25+ pub max: Option<usize>,
26+}
27+
1728 pub mod borrowed;
18−pub use borrowed::Borrowed;
29+pub use borrowed::Borrowed as PacketLine;
1930
2031 pub mod read;
2132 #[doc(inline)]
git-packetline/src/read.rsrenamed from git-transport/src/packet_line/read.rs+1−1
@@ -1,4 +1,4 @@
1−use crate::packet_line::{
1+use crate::{
22 borrowed::{Band, Text},
33 decode, MAX_DATA_LEN, MAX_LINE_LEN,
44 };
git-packetline/tests/fixtures/v1/01-clone.combined-outputrenamed from git-transport/tests/fixtures/v1/01-clone.combined-output+0−0

File renamed without changes.

git-packetline/tests/fixtures/v1/01.requestrenamed from git-transport/tests/fixtures/v1/01.request+0−0

File renamed without changes.

git-packetline/tests/fixtures/v1/fetch/01-many-refs.requestrenamed from git-transport/tests/fixtures/v1/fetch/01-many-refs.request+0−0

File renamed without changes.

git-packetline/tests/fixtures/v1/fetch/01-many-refs.responserenamed from git-transport/tests/fixtures/v1/fetch/01-many-refs.response+0−0

File renamed without changes.

git-packetline/tests/packet_line/decode.rsrenamed from git-transport/tests/packet_line/decode.rs+4−5
@@ -1,10 +1,9 @@
11 mod streaming {
22 use crate::packet_line::assert_err_display;
33 use bstr::ByteSlice;
4− use git_transport::packet_line::Channel;
5− use git_transport::{
6− packet_line::decode::{self, streaming, Stream},
7− PacketLine,
4+ use git_packetline::{
5+ decode::{self, streaming, Stream},
6+ Channel, PacketLine,
87 };
98
109 fn assert_complete(
@@ -120,7 +119,7 @@ mod streaming { · 109 unmodified lines
120119 }
121120
122121 mod incomplete {
123− use git_transport::packet_line::decode::{self, streaming, Stream};
122+ use git_packetline::decode::{self, streaming, Stream};
124123
125124 fn assert_incomplete(res: Result<Stream, decode::Error>, expected_missing: usize) -> crate::Result {
126125 match res? {
git-packetline/tests/packet_line/encode.rsrenamed from git-transport/tests/packet_line/encode.rs+1−1
@@ -1,7 +1,7 @@
11 mod data_to_write {
22 use crate::packet_line::assert_err_display;
33 use bstr::ByteSlice;
4− use git_transport::packet_line::encode::{
4+ use git_packetline::encode::{
55 data_to_write, delim_to_write, error_to_write, flush_to_write, response_end_to_write, text_to_write,
66 };
77 use std::io;
git-packetline/tests/packet_line/mod.rsrenamed from git-transport/tests/packet_line/mod.rs+0−0

File renamed without changes.

git-packetline/tests/packet_line/read.rsrenamed from git-transport/tests/packet_line/read.rs+5−5
@@ -1,4 +1,4 @@
1−use git_transport::{packet_line, PacketLine};
1+use git_packetline::PacketLine;
22 use std::{io, path::PathBuf};
33
44 fn fixture_path(path: &str) -> PathBuf {
@@ -13,12 +13,12 @@ mod to_read { · 8 unmodified lines
1313 use crate::packet_line::read::{exhaust, fixture_bytes};
1414 use bstr::ByteSlice;
1515 use git_odb::pack;
16− use git_transport::{packet_line, RemoteProgress};
16+ use git_packetline::RemoteProgress;
1717
1818 #[test]
1919 fn read_pack_with_progress_extraction() -> crate::Result {
2020 let buf = fixture_bytes("v1/01-clone.combined-output");
21− let mut rd = packet_line::Reader::new(&buf[..], None);
21+ let mut rd = git_packetline::Reader::new(&buf[..], None);
2222 assert_eq!(exhaust(&mut rd), 2);
2323 rd.reset();
2424 assert_eq!(rd.read_line()??.to_text().0.as_bstr(), b"NAK".as_bstr());
@@ -47,7 +47,7 @@ mod to_read { · 22 unmodified lines
4747 fn read_from_file_and_reader_advancement() -> crate::Result {
4848 let mut bytes = fixture_bytes("v1/fetch/01-many-refs.response");
4949 bytes.extend(fixture_bytes("v1/fetch/01-many-refs.response").into_iter());
50− let mut rd = packet_line::Reader::new(&bytes[..], None);
50+ let mut rd = git_packetline::Reader::new(&bytes[..], None);
5151 assert_eq!(
5252 rd.read_line()??.as_bstr(),
5353 PacketLine::Data(b"7814e8a05a59c0cf5fb186661d1551c75d1299b5 HEAD\0multi_ack thin-pack side-band side-band-64k ofs-delta shallow deepen-since deepen-not deepen-relative no-progress include-tag multi_ack_detailed symref=HEAD:refs/heads/master object-format=sha1 agent=git/2.28.0\n").as_bstr()
@@ -68,7 +68,7 @@ fn read_from_file_and_reader_advancement() -> crate::Result { · 14 unmodified lines
6868 Ok(())
6969 }
7070
71−fn exhaust(rd: &mut packet_line::Reader<&[u8]>) -> i32 {
71+fn exhaust(rd: &mut git_packetline::Reader<&[u8]>) -> i32 {
7272 let mut count = 0;
7373 while let Ok(_) = rd.read_line() {
7474 count += 1;
git-packetline/tests/packetline.rs+3−0
@@ -0,0 +1,3 @@
1+pub type Result = std::result::Result<(), Box<dyn std::error::Error>>;
2+
3+mod packet_line;
git-protocol/Cargo.toml+1−1
@@ -15,7 +15,7 @@ doctest = false · 14 unmodified lines
1515 serde1 = ["serde", "bstr/serde1"]
1616
1717 [dependencies]
18−git-transport = { version = "^0.1.0", path = "../git-transport" }
18+git-packetline = { version = "^0.1.0", path = "../git-packetline" }
1919
2020 quick-error = "2.0.0"
2121 serde = { version = "1.0.114", optional = true, default-features = false, features = ["derive"]}
git-protocol/src/remote_progress.rs+1−1
@@ -1,4 +1,4 @@
1−use git_transport::RemoteProgress;
1+use git_packetline::RemoteProgress;
22 use nom::{
33 bytes::complete::{tag, take_till, take_till1},
44 combinator::{map_res, opt},
git-protocol/tests/remote_progress/mod.rs+1−1
@@ -1,7 +1,7 @@
11 mod parse {
22 use bstr::ByteSlice;
3+ use git_packetline::RemoteProgress;
34 use git_protocol::parse_remote_progress;
4− use git_transport::RemoteProgress;
55
66 #[test]
77 fn a_message_we_dont_understand() {
git-transport/Cargo.toml+0−4
@@ -23,11 +23,7 @@ git-url = { version = "^0.1.0", path = "../git-url" } · 22 unmodified lines
2323
2424 serde = { version = "1.0.114", optional = true, default-features = false, features = ["std", "derive"]}
2525 quick-error = "2.0.0"
26−hex = "0.4.2"
2726 bstr = { version = "0.2.13", default-features = false, features = ["std"] }
2827
2928 # for http-curl
3029 curl = { version = "0.4.31", optional = true, features = ["static-ssl", "static-curl"] }
31−
32−[dev-dependencies]
33−git-odb = { version = "0.3.0", path = "../git-odb" }
git-transport/src/lib.rs+0−16
@@ -1,20 +1,4 @@
11 #![forbid(unsafe_code)]
2−use bstr::BStr;
3−
4−pub mod packet_line;
5−
6−#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
7−#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
8−pub struct RemoteProgress<'a> {
9− #[cfg_attr(feature = "serde1", serde(borrow))]
10− pub action: &'a BStr,
11− pub percent: Option<u32>,
12− pub step: Option<usize>,
13− pub max: Option<usize>,
14−}
15−
16−#[doc(inline)]
17−pub use packet_line::Borrowed as PacketLine;
182
193 #[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
204 #[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
git-transport/tests/transport.rs+0−2
@@ -1,3 +1 @@
11 pub type Result = std::result::Result<(), Box<dyn std::error::Error>>;
2−
3−mod packet_line;