Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unnecessarily Cloning, structuring #1905

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
mod upd
sharma-shray authored Nov 19, 2024
commit 630e622eab8085b773060dc9acf3579aac41c1fa
26 changes: 16 additions & 10 deletions src/git_config/mod.rs
Original file line number Diff line number Diff line change
@@ -156,15 +156,21 @@ fn parse_config_from_env_var_value(s: &str) -> HashMap<String, String> {
GIT_CONFIG_PARAMETERS_REGEX
.captures_iter(s)
.map(|captures| {
let key = captures
.get(1)
.or_else(|| captures.get(3))
.map_or("".to_string(), |m| m.as_str().to_string());
let value = captures
.get(2)
.or_else(|| captures.get(4))
.map_or("".to_string(), |m| m.as_str().to_string());
(key, value)
let (i, j) = match (
captures.get(1),
captures.get(2),
captures.get(3),
captures.get(4),
) {
(Some(_), Some(_), None, None) => (1, 2),
(None, None, Some(_), Some(_)) => (3, 4),
_ => (0, 0),
};
if (i, j) == (0, 0) {
("".to_string(), "".to_string())
} else {
(captures[i].to_string(), captures[j].to_string())
}
})
.collect()
}
@@ -292,4 +298,4 @@ mod tests {
);
}
}
}
}