Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions crates/grite-daemon/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,7 @@ fn execute_command_inner(
"pull_events": pull_result.events_pulled,
"pull_wal_head": wal_head,
"message": pull_result.message,
"lock_conflicts": lock_conflicts_json(&pull_result.lock_conflicts),
})
} else if do_push && !do_pull {
// Push only with auto-rebase
Expand All @@ -1005,6 +1006,7 @@ fn execute_command_inner(
"push_rebased": push_result.rebased,
"push_events_rebased": push_result.events_rebased,
"message": push_result.message,
"lock_conflicts": lock_conflicts_json(&push_result.lock_conflicts),
})
} else {
// Full sync: pull then push with auto-rebase
Expand All @@ -1020,6 +1022,9 @@ fn execute_command_inner(
"push_rebased": push_result.rebased,
"push_events_rebased": push_result.events_rebased,
"message": format!("{} / {}", pull_result.message, push_result.message),
"lock_conflicts": lock_conflicts_json(
&[pull_result.lock_conflicts, push_result.lock_conflicts].concat(),
),
})
};

Expand All @@ -1034,6 +1039,20 @@ fn execute_command_inner(
}
}

/// Lock conflicts reported by a sync, as JSON
fn lock_conflicts_json(conflicts: &[libgrite_git::LockConflict]) -> serde_json::Value {
conflicts
.iter()
.map(|c| {
serde_json::json!({
"resource": c.resource,
"owner": c.owner,
"expires_in_ms": c.expires_in_ms,
})
})
.collect()
}

/// Convert an IssueProjection to a JSON value with hex-encoded IDs
fn projection_to_json(p: &libgrite_core::types::issue::IssueProjection) -> serde_json::Value {
use libgrite_core::types::ids::id_to_hex;
Expand Down
33 changes: 32 additions & 1 deletion crates/grite/src/commands/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::context::GriteContext;
use crate::output::{output_success, print_human};
use libgrite_core::types::ids::ActorId;
use libgrite_core::{lock::LockCheckResult, GriteError};
use libgrite_git::WalManager;
use libgrite_git::{LockConflict, WalManager};
use serde::Serialize;

/// Check repo lock for push operations
Expand All @@ -31,6 +31,28 @@ fn check_push_lock(cli: &Cli, ctx: &GriteContext) -> Result<(), GriteError> {
}
}

#[derive(Serialize)]
struct LockConflictOutput {
resource: String,
owner: String,
expires_in_ms: u64,
}

/// Report lock conflicts to the user and convert them for JSON output.
fn lock_conflicts(cli: &Cli, conflicts: &[LockConflict]) -> Vec<LockConflictOutput> {
for conflict in conflicts {
print_human(cli, &format!("Lock conflict: {}", conflict));
}
conflicts
.iter()
.map(|c| LockConflictOutput {
resource: c.resource.clone(),
owner: c.owner.clone(),
expires_in_ms: c.expires_in_ms,
})
.collect()
}

#[derive(Serialize)]
struct SyncOutput {
pulled: bool,
Expand All @@ -41,6 +63,7 @@ struct SyncOutput {
push_rebased: bool,
push_events_rebased: usize,
message: String,
lock_conflicts: Vec<LockConflictOutput>,
}

#[derive(Serialize)]
Expand All @@ -49,6 +72,7 @@ struct PullOutput {
events: usize,
wal_head: Option<String>,
message: String,
lock_conflicts: Vec<LockConflictOutput>,
}

#[derive(Serialize)]
Expand All @@ -58,6 +82,7 @@ struct PushOutput {
events_rebased: usize,
backfilled: usize,
message: String,
lock_conflicts: Vec<LockConflictOutput>,
}

pub fn run(cli: &Cli, remote: String, pull_only: bool, push_only: bool) -> Result<(), GriteError> {
Expand Down Expand Up @@ -107,6 +132,7 @@ pub fn run(cli: &Cli, remote: String, pull_only: bool, push_only: bool) -> Resul
success: result.success,
events: result.events_pulled,
wal_head: result.new_wal_head.map(|oid| oid.to_string()),
lock_conflicts: lock_conflicts(cli, &result.lock_conflicts),
message: result.message,
},
);
Expand Down Expand Up @@ -137,6 +163,7 @@ pub fn run(cli: &Cli, remote: String, pull_only: bool, push_only: bool) -> Resul
rebased: result.rebased,
events_rebased: result.events_rebased,
backfilled: 0,
lock_conflicts: lock_conflicts(cli, &result.lock_conflicts),
message: result.message,
},
);
Expand Down Expand Up @@ -181,6 +208,10 @@ pub fn run(cli: &Cli, remote: String, pull_only: bool, push_only: bool) -> Resul
push_success: push_result.success,
push_rebased: push_result.rebased,
push_events_rebased: push_result.events_rebased,
lock_conflicts: lock_conflicts(
cli,
&[pull_result.lock_conflicts, push_result.lock_conflicts].concat(),
),
message: format!("{} / {}", pull_result.message, push_result.message),
},
);
Expand Down
Loading