Showing the changes to git-refspec (2 of 2 files). Show all
Unified · Split
| @@ -5,7 +5,7 @@ git init; · 4 unmodified lines | |||
| 5 | 5 | ||
| 6 | function baseline() { | 6 | function baseline() { |
| 7 | { | 7 | { |
| 8 | git fetch -v origin "$@" 2>&1 | tail +2 | 8 | git fetch --dry-run -v origin "$@" 2>&1 | tail +2 |
| 9 | echo specs: "$@" | 9 | echo specs: "$@" |
| 10 | } >> baseline.git | 10 | } >> 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 | ) |
| @@ -12,6 +12,7 @@ fn fetch_only() { · 11 unmodified lines | |||
| 12 | mod baseline { | 12 | mod 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 | } |