History

parse basline mapping (#450)

Sebastian Thiel committed 4 years ago

Commit 3000a141 parent fce877f2 files · +45 −4Browse files

Showing the changes to git-refspec (2 of 2 files). Show all

Unified · Split

2 files
  1. git-refspec/tests/fixtures/match_baseline.sh +6 −1
  2. git-refspec/tests/matcher/mod.rs +39 −3
git-refspec/tests/fixtures/match_baseline.sh+6−1
@@ -5,7 +5,7 @@ git init; · 4 unmodified lines
5 5
6function baseline() {6function baseline() {
7 {7 {
8 git fetch -v origin "$@" 2>&1 | tail +28 git fetch --dry-run -v origin "$@" 2>&1 | tail +2
9 echo specs: "$@"9 echo specs: "$@"
10 } >> baseline.git10 } >> baseline.git
11}11}
@@ -33,6 +33,11 @@ git clone --shared ./base clone · 21 unmodified lines
33 baseline "refs/heads/main"33 baseline "refs/heads/main"
34 baseline "heads/main"34 baseline "heads/main"
35 baseline "main"35 baseline "main"
36 baseline "+refs/heads/*:refs/remotes/origin/*"
37 baseline "refs/heads/*:refs/remotes/origin/*" "^main"
38 baseline "^main" "refs/heads/*:refs/remotes/origin/*"
39 baseline "^refs/heads/main" "refs/heads/*:refs/remotes/origin/*"
40 baseline "refs/heads/*:refs/remotes/origin/*" "^refs/heads/main"
36 baseline "78b1c1be9421b33a49a7a8176d93eeeafa112da1"41 baseline "78b1c1be9421b33a49a7a8176d93eeeafa112da1"
37 baseline "9d2fab1a0ba3585d0bc50922bfdd04ebb59361df"42 baseline "9d2fab1a0ba3585d0bc50922bfdd04ebb59361df"
38)43)
git-refspec/tests/matcher/mod.rs+39−3
@@ -12,6 +12,7 @@ fn fetch_only() { · 11 unmodified lines
12mod baseline {12mod baseline {
13 use bstr::{BString, ByteSlice};13 use bstr::{BString, ByteSlice};
14 use git_hash::ObjectId;14 use git_hash::ObjectId;
15 use std::collections::HashMap;
15 16
16 #[derive(Debug)]17 #[derive(Debug)]
17 pub struct Ref {18 pub struct Ref {
@@ -21,6 +22,12 @@ mod baseline { · 3 unmodified lines
21 pub tag: Option<ObjectId>,22 pub tag: Option<ObjectId>,
22 }23 }
23 24
25 #[derive(Debug)]
26 pub struct Mapping {
27 pub remote: BString,
28 pub local: BString,
29 }
30
24 pub fn parse_input() -> crate::Result<Vec<Ref>> {31 pub fn parse_input() -> crate::Result<Vec<Ref>> {
25 let dir = git_testtools::scripted_fixture_repo_read_only("match_baseline.sh")?;32 let dir = git_testtools::scripted_fixture_repo_read_only("match_baseline.sh")?;
26 let refs_buf = std::fs::read(dir.join("clone").join("remote-refs.list"))?;33 let refs_buf = std::fs::read(dir.join("clone").join("remote-refs.list"))?;
@@ -44,8 +51,37 @@ mod baseline { · 17 unmodified lines
44 }51 }
45 Ok(out)52 Ok(out)
46 }53 }
47 pub fn parse() -> crate::Result {54
48 let _ = git_testtools::scripted_fixture_repo_read_only("match_baseline.sh")?;55 pub fn parse() -> crate::Result<HashMap<Vec<BString>, Vec<Mapping>>> {
49 Ok(())56 let dir = git_testtools::scripted_fixture_repo_read_only("match_baseline.sh")?;
57 let buf = std::fs::read(dir.join("clone").join("baseline.git"))?;
58
59 let mut map = HashMap::new();
60 let mut mappings = Vec::new();
61 for line in buf.lines() {
62 if line.ends_with(b"FETCH_HEAD") {
63 continue;
64 }
65 match line.strip_prefix(b"specs: ") {
66 Some(specs) => {
67 let key: Vec<_> = specs.split(|b| *b == b' ').map(BString::from).collect();
68 map.insert(key, std::mem::take(&mut mappings));
69 }
70 None => {
71 let past_note = line.splitn(2, |b| *b == b']').nth(1).unwrap();
72 let mut tokens = past_note.split(|b| *b == b' ').filter(|t| !t.is_empty());
73
74 let lhs = tokens.next().unwrap().trim();
75 drop(tokens.next());
76 let rhs = tokens.next().unwrap().trim();
77 mappings.push(Mapping {
78 remote: lhs.into(),
79 local: rhs.into(),
80 })
81 }
82 }
83 }
84
85 Ok(map)
50 }86 }
51}87}

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