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
55
66 function baseline() {
77 {
8− git fetch -v origin "$@" 2>&1 | tail +2
8+ git fetch --dry-run -v origin "$@" 2>&1 | tail +2
99 echo specs: "$@"
1010 } >> baseline.git
1111 }
@@ -33,6 +33,11 @@ git clone --shared ./base clone · 21 unmodified lines
3333 baseline "refs/heads/main"
3434 baseline "heads/main"
3535 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"
3641 baseline "78b1c1be9421b33a49a7a8176d93eeeafa112da1"
3742 baseline "9d2fab1a0ba3585d0bc50922bfdd04ebb59361df"
3843 )
git-refspec/tests/matcher/mod.rs+39−3
@@ -12,6 +12,7 @@ fn fetch_only() { · 11 unmodified lines
1212 mod baseline {
1313 use bstr::{BString, ByteSlice};
1414 use git_hash::ObjectId;
15+ use std::collections::HashMap;
1516
1617 #[derive(Debug)]
1718 pub struct Ref {
@@ -21,6 +22,12 @@ mod baseline { · 3 unmodified lines
2122 pub tag: Option<ObjectId>,
2223 }
2324
25+ #[derive(Debug)]
26+ pub struct Mapping {
27+ pub remote: BString,
28+ pub local: BString,
29+ }
30+
2431 pub fn parse_input() -> crate::Result<Vec<Ref>> {
2532 let dir = git_testtools::scripted_fixture_repo_read_only("match_baseline.sh")?;
2633 let refs_buf = std::fs::read(dir.join("clone").join("remote-refs.list"))?;
@@ -44,8 +51,37 @@ mod baseline { · 17 unmodified lines
4451 }
4552 Ok(out)
4653 }
47− pub fn parse() -> crate::Result {
48− let _ = git_testtools::scripted_fixture_repo_read_only("match_baseline.sh")?;
49− Ok(())
54+
55+ pub fn parse() -> crate::Result<HashMap<Vec<BString>, Vec<Mapping>>> {
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)
5086 }
5187 }

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