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

Add Phabricator support to git submit #840

Merged
merged 8 commits into from
Mar 12, 2023
Merged
258 changes: 198 additions & 60 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions git-branchless-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ test = true
[dependencies]
anyhow = "1.0.69"
assert_cmd = "2.0.7"
async-trait = "0.1.64"
bstr = "1.3.0"
chashmap = "2.2.2"
chrono = "0.4.19"
color-eyre = "0.6.2"
Expand All @@ -52,28 +54,26 @@ console = "0.15.5"
cursive = { version = "0.20.0", default-features = false }
eden_dag = { package = "esl01-dag", version = "0.3.0" }
eyre = "0.6.8"
git2 = { version = "0.16.1", default-features = false }
futures = "0.3.26"
git-record = { version = "0.3", path = "../git-record" }
git2 = { version = "0.16.1", default-features = false }
indicatif = { version = "0.17.3", features = ["improved_unicode"] }
itertools = "0.10.3"
lazy_static = "1.4.0"
once_cell = "1.17.1"
portable-pty = "0.7.0"
rayon = "1.6.1"
regex = "1.7.1"
rusqlite = { version = "0.28.0", features = ["bundled"] }
serde = { version = "1.0.152", features = ["derive"] }
tempfile = "3.4.0"
textwrap = "0.16.0"
thiserror = "1.0.39"
tracing = "0.1.37"
tracing-chrome = "0.6.0"
tracing-error = "0.2.0"
tracing-subscriber = { version = "=0.3.11", features = ["env-filter"] }
thiserror = "1.0.39"
bstr = "1.3.0"
serde = { version = "1.0.152", features = ["derive"] }
portable-pty = "0.7.0"
vt100 = "0.15.2"
async-trait = "0.1.64"
futures = "0.3.26"

[dev-dependencies]
criterion = { version = "0.4.0", features = ["html_reports"] }
Expand Down
2 changes: 1 addition & 1 deletion git-branchless-lib/bin/testing/regression_test_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn main() -> eyre::Result<()> {
let actual_commit = {
let author = current_commit.get_author();
let committer = current_commit.get_committer();
let message = current_commit.get_message_raw()?;
let message = current_commit.get_message_raw();
let message = message.to_str_lossy();
let parents = current_commit.get_parents();
let actual_oid = repo.create_commit(
Expand Down
12 changes: 7 additions & 5 deletions git-branchless-lib/src/core/effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,19 @@ pub enum OperationType {
InitializeRebase,
MakeGraph,
ProcessEvents,
PushBranches,
PushCommits,
QueryWorkingCopy,
ReadingFromCache,
RebaseCommits,
RepairBranches,
RepairCommits,
RunGitCommand(Arc<String>),
RunTests(Arc<String>),
RunTestOnCommit(Arc<String>),
RunTests(Arc<String>),
SortCommits,
SyncCommits,
UpdateCommitGraph,
UpdateCommits,
WalkCommits,
}

Expand All @@ -70,7 +71,7 @@ impl ToString for OperationType {
OperationType::GetUpstreamPatchIds => "Enumerating patch IDs",
OperationType::InitializeRebase => "Initializing rebase",
OperationType::MakeGraph => "Examining local history",
OperationType::PushBranches => "Pushing branches",
OperationType::PushCommits => "Pushing branches",
OperationType::ProcessEvents => "Processing events",
OperationType::QueryWorkingCopy => "Querying the working copy",
OperationType::ReadingFromCache => "Reading from cache",
Expand All @@ -80,10 +81,11 @@ impl ToString for OperationType {
OperationType::RunGitCommand(command) => {
return format!("Running Git command: {}", &command)
}
OperationType::RunTests(command) => return format!("Running tests: {command}"),
OperationType::RunTestOnCommit(commit) => return format!("Waiting to test {commit}"),
OperationType::RunTests(command) => return format!("Running command: {command}"),
OperationType::RunTestOnCommit(commit) => return format!("Waiting to run on {commit}"),
OperationType::SortCommits => "Sorting commits",
OperationType::SyncCommits => "Syncing commit stacks",
OperationType::UpdateCommits => "Updating commits",
OperationType::UpdateCommitGraph => "Updating commit graph",
OperationType::WalkCommits => "Walking commits",
};
Expand Down
2 changes: 1 addition & 1 deletion git-branchless-lib/src/core/node_descriptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ impl<'a> NodeDescriptor for DifferentialRevisionDescriptor<'a> {
NodeObject::GarbageCollected { oid: _ } => return Ok(None),
};

let diff_number = match extract_diff_number(&commit.get_message_raw()?.to_str_lossy()) {
let diff_number = match extract_diff_number(&commit.get_message_raw().to_str_lossy()) {
Some(diff_number) => diff_number,
None => return Ok(None),
};
Expand Down
36 changes: 35 additions & 1 deletion git-branchless-lib/src/core/repo_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ use color_eyre::Help;
use eyre::Context;
use tracing::instrument;

use crate::git::{Branch, BranchType, NonZeroOid, ReferenceName, Repo};
use crate::git::{
Branch, BranchType, CategorizedReferenceName, ConfigRead, NonZeroOid, ReferenceName, Repo,
};

use super::config::get_main_branch_name;

Expand Down Expand Up @@ -39,6 +41,9 @@ pub trait RepoExt {

/// Get the positions of references in the repository.
fn get_references_snapshot(&self) -> eyre::Result<RepoReferencesSnapshot>;

/// Get the default remote to push to for new branches in this repository.
fn get_default_push_remote(&self) -> eyre::Result<Option<String>>;
}

impl RepoExt for Repo {
Expand Down Expand Up @@ -119,4 +124,33 @@ https://github.com/arxanas/git-branchless/discussions/595 for more details.",
branch_oid_to_names,
})
}

fn get_default_push_remote(&self) -> eyre::Result<Option<String>> {
let main_branch_name = self.get_main_branch()?.get_reference_name()?;
match CategorizedReferenceName::new(&main_branch_name) {
name @ CategorizedReferenceName::LocalBranch { .. } => {
if let Some(main_branch) =
self.find_branch(&name.remove_prefix()?, BranchType::Local)?
{
if let Some(remote_name) = main_branch.get_push_remote_name()? {
return Ok(Some(remote_name));
}
}
}

name @ CategorizedReferenceName::RemoteBranch { .. } => {
let name = name.remove_prefix()?;
if let Some((remote_name, _reference_name)) = name.split_once('/') {
return Ok(Some(remote_name.to_owned()));
}
}

CategorizedReferenceName::OtherRef { .. } => {
// Do nothing.
}
}

let push_default_remote_opt = self.get_readonly_config()?.get("remote.pushDefault")?;
Ok(push_default_remote_opt)
}
}
4 changes: 2 additions & 2 deletions git-branchless-lib/src/core/rewrite/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ mod in_memory {
Err(other) => eyre::bail!(other),
};

let commit_message = commit_to_apply.get_message_raw()?;
let commit_message = commit_to_apply.get_message_raw();
let commit_message = commit_message.to_str().with_context(|| {
eyre::eyre!(
"Could not decode commit message for commit: {:?}",
Expand Down Expand Up @@ -706,7 +706,7 @@ mod in_memory {

let replacement_commit = repo.find_commit_or_fail(*replacement_commit_oid)?;
let replacement_tree = replacement_commit.get_tree()?;
let replacement_message = replacement_commit.get_message_raw()?;
let replacement_message = replacement_commit.get_message_raw();
let replacement_commit_message =
replacement_message.to_str().with_context(|| {
eyre::eyre!(
Expand Down
12 changes: 6 additions & 6 deletions git-branchless-lib/src/git/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ impl<'repo> Commit<'repo> {

/// Get the commit message with some whitespace trimmed.
#[instrument]
pub fn get_message_pretty(&self) -> Result<BString> {
Ok(BString::from(self.inner.message_bytes()))
pub fn get_message_pretty(&self) -> BString {
BString::from(self.inner.message_bytes())
}

/// Get the commit message, without any whitespace trimmed.
#[instrument]
pub fn get_message_raw(&self) -> Result<BString> {
Ok(BString::from(self.inner.message_raw_bytes()))
pub fn get_message_raw(&self) -> BString {
BString::from(self.inner.message_raw_bytes())
}

/// Get the author of this commit.
Expand Down Expand Up @@ -151,7 +151,7 @@ impl<'repo> Commit<'repo> {
/// like `Signed-off-by: foo` which appear at the end of the commit message.
#[instrument]
pub fn get_trailers(&self) -> Result<Vec<(String, String)>> {
let message = self.get_message_raw()?;
let message = self.get_message_raw();
let message = message.to_str().map_err(|_| Error::DecodeUtf8 {
item: "raw message",
})?;
Expand Down Expand Up @@ -249,7 +249,7 @@ impl<'repo> Commit<'repo> {
BaseColor::Green.light(),
),
StyledString::plain(textwrap::indent(
&self.get_message_pretty()?.to_str_lossy(),
&self.get_message_pretty().to_str_lossy(),
" ",
)),
]);
Expand Down
3 changes: 2 additions & 1 deletion git-branchless-lib/src/git/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ impl<'de> Deserialize<'de> for SerializedNonZeroOid {
pub struct SerializedTestResult {
pub command: String,
pub exit_code: i32,
pub fixed_tree_oid: Option<SerializedNonZeroOid>,
pub head_commit_oid: Option<SerializedNonZeroOid>,
pub snapshot_tree_oid: Option<SerializedNonZeroOid>,
#[serde(default)]
pub interactive: bool,
}
Expand Down
8 changes: 8 additions & 0 deletions git-branchless-opts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,14 @@ pub struct SubmitArgs {
#[clap(action, short = 'c', long = "create")]
pub create: bool,

/// If the remote supports it, create code reviews in "draft" mode.
#[clap(action, short = 'd', long = "draft")]
pub draft: bool,

/// What kind of execution strategy to use for tools which need access to the working copy.
#[clap(short = 's', long = "strategy")]
pub strategy: Option<TestExecutionStrategy>,

/// The commits to push. All branches attached to those commits will be
/// pushed.
#[clap(value_parser, default_value = "stack()")]
Expand Down
22 changes: 13 additions & 9 deletions git-branchless-revset/src/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ fn fn_message(ctx: &mut Context, name: &str, args: &[Expr]) -> EvalResult {
name,
args,
Box::new(move |_repo, commit| {
let message = commit.get_message_raw().map_err(PatternError::Repo)?;
let message = commit.get_message_raw();
let message = match message.to_str() {
Ok(message) => message,
Err(err) => {
Expand Down Expand Up @@ -572,7 +572,8 @@ fn fn_tests_passed(ctx: &mut Context, name: &str, args: &[Expr]) -> EvalResult {
let SerializedTestResult {
command,
exit_code,
fixed_tree_oid: _,
head_commit_oid: _,
snapshot_tree_oid: _,
interactive: _,
} = test_result;
exit_code == TEST_SUCCESS_EXIT_CODE && pattern.matches_text(&command)
Expand All @@ -597,7 +598,8 @@ fn fn_tests_failed(ctx: &mut Context, name: &str, args: &[Expr]) -> EvalResult {
let SerializedTestResult {
command,
exit_code,
fixed_tree_oid: _,
head_commit_oid: _,
snapshot_tree_oid: _,
interactive: _,
} = test_result;
exit_code != TEST_SUCCESS_EXIT_CODE
Expand Down Expand Up @@ -625,16 +627,18 @@ fn fn_tests_fixable(ctx: &mut Context, name: &str, args: &[Expr]) -> EvalResult
let SerializedTestResult {
command,
exit_code,
fixed_tree_oid,
head_commit_oid: _,
snapshot_tree_oid,
interactive: _,
} = test_result;
exit_code == TEST_SUCCESS_EXIT_CODE
&& pattern.matches_text(&command)
&& match fixed_tree_oid {
None => false,
Some(SerializedNonZeroOid(fixed_tree_oid)) => {
commit.get_tree_oid() != MaybeZeroOid::NonZero(fixed_tree_oid)
}
&& match (snapshot_tree_oid, commit.get_tree_oid()) {
(
Some(SerializedNonZeroOid(snapshot_tree_oid)),
MaybeZeroOid::NonZero(original_tree_oid),
) => snapshot_tree_oid != original_tree_oid,
(None, _) | (_, MaybeZeroOid::Zero) => false,
}
});
Ok(result)
Expand Down
2 changes: 1 addition & 1 deletion git-branchless-revset/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ mod tests {
.into_iter()
.map(|oid| repo.find_commit_or_fail(oid))
.try_collect()?;
commits.sort_by_key(|commit| (commit.get_message_pretty().unwrap(), commit.get_time()));
commits.sort_by_key(|commit| (commit.get_message_pretty(), commit.get_time()));
Ok(commits)
}

Expand Down
2 changes: 1 addition & 1 deletion git-branchless-reword/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ fn prepare_messages(
let oid = commit.get_short_oid()?;

let original_message = commit
.get_message_raw()?
.get_message_raw()
.to_str()
.with_context(|| {
eyre::eyre!(
Expand Down
11 changes: 9 additions & 2 deletions git-branchless-submit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@ version = "0.7.0"

[dependencies]
cursive_core = "0.3.6"
eden_dag = { package = "esl01-dag", version = "0.2.1" }
eyre = "0.6.8"
git-branchless-invoke = { version = "0.7.0", path = "../git-branchless-invoke" }
git-branchless-opts = { version = "0.7.0", path = "../git-branchless-opts" }
git-branchless-revset = { version = "0.7.0", path = "../git-branchless-revset" }
git-branchless-test = { version = "0.7.0", path = "../git-branchless-test" }
itertools = "0.10.5"
lazy_static = "1.4.0"
lib = { package = "git-branchless-lib", version = "0.7.0", path = "../git-branchless-lib" }
rayon = "1.5.3"
regex = "1.7.1"
serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.93"
thiserror = "1.0.38"
tracing = "0.1.37"

[dev-dependencies]
clap = { version = "4.0.23", features = ["derive"] }
insta = "1.28.0"


Loading