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
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ benchmark, and its numbers in the pull request.
End-to-end tests run the `origin` binary with `ORIGIN_CONFIG_DIR` set to a
temporary directory, which holds the user's `config.toml` and node key.
The HTTP tests drive every SDK method against a real server. One fails
while `docs/openapi.json` is stale: `just openapi` rewrites it.
while `docs/openapi.json` is stale: `just openapi` rewrites it. The sync
tests clone, push and fetch through `origin serve` and through local paths;
`tests/common` holds the helpers every end-to-end test shares.

## Commits & Pull Requests
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ origin workspace list | rm <path>
origin op log [-n <count>] # what this node did, operation by operation, in every workspace
origin undo # move this workspace's working copy back one operation
origin watch [--kind <kind>] [--subject <id>] [--since <cursor>] # events, as they happen

origin clone <url> [<path>] [--target <target>] # follow a remote's target, starting a change on its tip
origin remote [<url>] # show or set the remote: http://host:port/<repo>, or a path
origin push [<change>...] # share changes and the ones below them; lands nothing
origin fetch [--target <t>] [--change <id>] # new acceptances, and the records of known changes
origin pull # fetch, then move the working copy onto its target's tip
```

Landing rebases a change onto the target's tip, file by file, checks the
Expand Down Expand Up @@ -81,6 +87,20 @@ op log, one a line starting with a cursor: `statement.issued`,
takes an event name or a statement kind (`core.conflict`, `ci.*`), and
`--since` resumes after a cursor.

A repository can have one remote, a server or another repository's path,
shared by its workspaces. A clone holds the chains of the targets it
follows, `policy` and one other, verified against their authorities' keys,
and the records of the changes it knows, which each `fetch` brings as they
move: it asks the remote's events what moved since the last fetch, so a
fetch that brings nothing is quick however long the history. It fetches
snapshots only when a command reads them, starting with its target's tip.
`push` shares revisions, their files and statements, and refuses a change
the remote has a newer revision of, even one pushed while it sends:
`fetch`, then `converge` it. A statement that needs one the remote lacks
stays, and the push says so. Fetching never changes your files; `pull`
then moves the working copy onto its target's new tip, like a landing
elsewhere does.

Changes are named by a unique prefix of their id, or `@` for the working
copy's. A revision is `@`, a change (for its head), or a unique prefix of
the revision's id. Your name and node key live in `$ORIGIN_CONFIG_DIR`, or
Expand Down
52 changes: 46 additions & 6 deletions apps/origin-src/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use anyhow::{Context, Result};
use clap::error::ErrorKind;
use clap::{Args, CommandFactory, Parser, Subcommand};
use origin_shared::policy::KindPattern;
use origin_shared::{Digest, Inputs, Kind, RepoPath, TargetName, Verdict};
use origin_shared::{ChangeId, Digest, Inputs, Kind, RepoPath, TargetName, Verdict};

use crate::config::UserConfig;
use crate::oplog::Actor;
Expand All @@ -33,6 +33,18 @@ enum Command {
#[arg(default_value = ".")]
path: PathBuf,
},
/// Copy a remote repository: the chains of `policy` and a target, and
/// the target's tip, on which a new change starts. Other snapshots are
/// fetched when something reads them.
Clone {
/// The repository: `http://host[:port]/<repository>`, or a path.
url: String,
/// Where to create it: by default, named after the repository.
path: Option<PathBuf>,
/// The target to follow and start on.
#[arg(short, long, default_value = "main")]
target: TargetName,
},
/// Serve repositories over HTTP, as their authority.
Serve {
/// The server configuration file.
Expand Down Expand Up @@ -166,9 +178,6 @@ enum WorkspaceCommand {
Target(TargetCommand),
/// List the targets, with their tips, authorities and requirements.
Targets,
/// Move the working copy where its change went from another
/// workspace, or onto its target's new tip, with the edits made since.
Pull,
/// Manage workspaces: working copies sharing this repository.
#[command(subcommand)]
Workspace(WorkspacesCommand),
Expand All @@ -178,6 +187,31 @@ enum WorkspaceCommand {
/// Move this workspace's working copy back to where it was before its
/// latest operation. Records and targets stay as they are.
Undo,
/// Show the remote, or set it.
Remote {
/// The new remote: `http://host[:port]/<repository>`, or a path.
url: Option<String>,
},
/// Fetch the remote's new acceptances on the targets followed, and the
/// records of the changes this repository knows. Changes no files.
Fetch {
/// Follow this target too.
#[arg(long)]
target: Vec<TargetName>,
/// Fetch this change too, by its full id.
#[arg(long)]
change: Vec<ChangeId>,
},
/// Fetch, if there's a remote, then move the working copy where its
/// change went, or onto its target's new tip, with the edits made
/// since.
Pull,
/// Share changes with the remote, with the changes below them: their
/// revisions, files and statements. Lands nothing.
Push {
/// The changes: the working copy's by default.
changes: Vec<String>,
},
/// Print events as they happen, one a line, starting with the cursor to
/// resume from. Runs until interrupted.
Watch {
Expand Down Expand Up @@ -449,7 +483,7 @@ impl Cli {
Command::Repo(RepoCommand::Create { path, config }) => {
return ServerConfig::load(&config)?.create_repo(&path);
}
Command::Init { .. } | Command::Workspace(_) => {}
Command::Init { .. } | Command::Clone { .. } | Command::Workspace(_) => {}
}
let config = UserConfig::load()?;
// The op log records the command line, without the program's name,
Expand All @@ -464,6 +498,9 @@ impl Cli {
Command::Init { path } => {
Workspace::init(&path, config, &actor)?;
}
Command::Clone { url, path, target } => {
Workspace::clone(&url, path.as_deref(), &target, config, &actor)?;
}
Command::Workspace(command) => command.run(config, &actor)?,
Command::Serve { .. } | Command::Repo(_) => unreachable!("run above"),
}
Expand Down Expand Up @@ -513,14 +550,17 @@ impl WorkspaceCommand {
workspace.target_new(&name, &from)?;
}
Self::Targets => workspace.targets()?,
Self::Pull => workspace.pull()?,
Self::Workspace(WorkspacesCommand::New { change, path }) => {
workspace.add_workspace(change.as_deref(), path.as_deref())?;
}
Self::Workspace(WorkspacesCommand::List) => workspace.list_workspaces()?,
Self::Workspace(WorkspacesCommand::Rm { path }) => workspace.remove_workspace(&path)?,
Self::Op(OpCommand::Log { limit }) => workspace.op_log(limit)?,
Self::Undo => workspace.undo()?,
Self::Remote { url } => workspace.set_remote(url.as_deref())?,
Self::Fetch { target, change } => workspace.fetch(&target, &change)?,
Self::Pull => workspace.pull()?,
Self::Push { changes } => workspace.push(&changes)?,
Self::Watch {
kind,
subject,
Expand Down
7 changes: 4 additions & 3 deletions apps/origin-src/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
//! however long the history: only without a cursor, or once it expired,
//! are all the changes this node knows compared.
//! - Snapshots don't come with records: [`Sync::need`] fetches one when
//! something reads it, such as a checkout. A snapshot is marked while it's
//! fetched ([`Store::fetching`]), so one whose fetch was interrupted is
//! fetched again rather than taken for whole.
//! something reads it, such as a checkout, so a clone fetches one
//! snapshot, its target's tip. A snapshot is marked while it's fetched
//! ([`Store::fetching`]), so one whose fetch was interrupted is fetched
//! again rather than taken for whole.
//! - **Pushing** shares revisions, with their snapshots, and statements. It
//! never lands anything. It first compares each change's heads with the
//! remote's, and refuses before uploading anything when the remote has a
Expand Down
17 changes: 12 additions & 5 deletions apps/origin-src/src/workspace/land.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,22 @@ impl Workspace {
self.start_on(&mut working_copy, target, description, files)
}

/// `origin pull`: moves the working copy where its change went without
/// it, merging the edits made since: onto the tip of the target it
/// `origin pull`: fetches, if the repository has a remote, then moves
/// the working copy where its change went without it, merging the edits
/// made since: onto the tip of the target it
/// landed on, as a new change, or onto the landing queue's rebase of it.
/// Otherwise rebases it onto the tip of the target its stack is on:
/// once the change below it landed, or once the target it's on moved.
///
/// # Errors
///
/// Fails if the working copy cannot be snapshotted, a file was edited
/// while it moved, or the records cannot be read or written.
/// Fails like [`Workspace::fetch`], or if the working copy cannot be
/// snapshotted, a file was edited while it moved, or the records cannot
/// be read or written.
pub fn pull(&mut self) -> Result<(), WorkspaceError> {
if self.remote()?.is_some() {
self.fetch(&[], &[])?;
}
let mut working_copy = self.save_draft()?;
if self.follow(&mut working_copy)? {
return Ok(());
Expand Down Expand Up @@ -218,6 +223,7 @@ impl Workspace {
.head(target)?
.ok_or_else(|| WorkspaceError::UnknownTarget(target.clone()))?;
let state = self.store.get(tip.acceptance)?.body().state;
self.need(&[state])?;
let tip_label = format!("{target} #{}", tip.seq);
let merge = self.store.merge_marked(
Some(base),
Expand Down Expand Up @@ -318,7 +324,7 @@ impl Workspace {

/// Rebases the working copy, made on `base`, onto the tip of `onto`, as
/// the module explains.
fn rebase_onto_tip(
pub(super) fn rebase_onto_tip(
&mut self,
working_copy: &mut WorkingCopy,
base: TreeId,
Expand All @@ -329,6 +335,7 @@ impl Workspace {
.head(onto)?
.ok_or_else(|| WorkspaceError::UnknownTarget(onto.clone()))?;
let state = self.store.get(tip.acceptance)?.body().state;
self.need(&[state])?;
let current = &working_copy.revision;
let tip_label = format!("{onto} #{}", tip.seq);
let merge = self.store.merge_marked(
Expand Down
Loading