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
79 changes: 79 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ thiserror = "2.0.21"
tokio = { version = "1.53.3", features = ["macros", "net", "rt-multi-thread", "signal"] }
toml = "1.1.8"
tracing = "0.1.44"
tracing-subscriber = { version = "0.3.23", features = ["env-filter", "fmt"] }
utoipa = { version = "6.0.0", features = ["axum_extras"] }
utoipa-axum = "0.3.0"
zstd = "0.14.3"
Expand Down
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,46 @@ doesn't land while they're unchanged: edit them, or accept a file as it is
with `origin resolve <path>`. `status` lists those left, and every new
revision, `describe` included, keeps them.

## Serving

A server is a node of its own, hosting repositories without a working
copy, and the authority of their targets: it runs their landing queues,
and packs their small objects once a few thousand pile up loose.

```sh
origin repo create repos/demo # a repository the server orders `policy` and `main` of
origin serve # host the repositories over HTTP
```

Both read `origin-server.toml` (or `--config <file>`), whose paths are
relative to it:

```toml
listen = "127.0.0.1:7878"
node = "hosted" # the server's node name
key = "node.key" # its secret key, created if missing

[repos]
demo = "repos/demo"
```

The HTTP API, under `/api/v1`, puts and fetches records in batches, lists
statements, revisions, targets and their logs, lands changes and targets,
and streams events by long-poll: `GET
/api/v1/repos/<repo>/events?cursor=<n>&wait=30s` answers as soon as there
are events after the cursor, with a JSON batch and the next cursor.
[`docs/openapi.json`](docs/openapi.json) describes it, and
[`origin-client`](crates/origin-client) is its Rust SDK. Nothing
authenticates callers yet.

## Development

```sh
just # format, lint, test, and audit dependencies
just bench # micro-benchmarks
just bench-git # origin against git, with hyperfine (docs/benchmarks.md)
just openapi # rewrite docs/openapi.json after changing the API
just serve # run `origin serve`
```

rustup installs the toolchain `rust-toolchain.toml` pins. The minimum
Expand Down
1 change: 1 addition & 0 deletions apps/origin-src/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ thiserror.workspace = true
tokio.workspace = true
toml.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
utoipa.workspace = true
utoipa-axum.workspace = true
zstd.workspace = true
Expand Down
33 changes: 32 additions & 1 deletion apps/origin-src/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! The `origin` command line: argument parsing. The commands themselves are
//! methods of [`Workspace`], which print their output.
//! methods of [`Workspace`] and [`ServerConfig`], which print their output.

use std::convert::Infallible;
use std::env;
Expand All @@ -14,6 +14,7 @@ use origin_shared::{Digest, Inputs, Kind, RepoPath, TargetName, Verdict};

use crate::config::UserConfig;
use crate::oplog::Actor;
use crate::server::ServerConfig;
use crate::workspace::{Annotated, Payload, Workspace};

/// A modern, git-compatible source control system.
Expand All @@ -32,10 +33,32 @@ enum Command {
#[arg(default_value = ".")]
path: PathBuf,
},
/// Serve repositories over HTTP, as their authority.
Serve {
/// The server configuration file.
#[arg(short, long, default_value = "origin-server.toml")]
config: PathBuf,
},
/// Manage the repositories a server hosts.
#[command(subcommand)]
Repo(RepoCommand),
#[command(flatten)]
Workspace(WorkspaceCommand),
}

#[derive(Debug, Subcommand)]
enum RepoCommand {
/// Create a repository without a working copy for a server to host,
/// with the server's node the authority of `policy` and `main`.
Create {
/// Where to create it.
path: PathBuf,
/// The server configuration file.
#[arg(short, long, default_value = "origin-server.toml")]
config: PathBuf,
},
}

/// Commands run in the repository containing the current directory. Those
/// that read the working copy snapshot it first. Changes are named by a
/// unique prefix of their id, or `@` for the working copy's.
Expand Down Expand Up @@ -421,6 +444,13 @@ impl Cli {
///
/// Fails if the command fails; the error is meant for the user.
pub fn run(self) -> Result<()> {
match self.command {
Command::Serve { config } => return ServerConfig::load(&config)?.serve(),
Command::Repo(RepoCommand::Create { path, config }) => {
return ServerConfig::load(&config)?.create_repo(&path);
}
Command::Init { .. } | Command::Workspace(_) => {}
}
let config = UserConfig::load()?;
// The op log records the command line, without the program's name,
// as text: an argument that isn't UTF-8, such as a path, is never
Expand All @@ -435,6 +465,7 @@ impl Cli {
Workspace::init(&path, config, &actor)?;
}
Command::Workspace(command) => command.run(config, &actor)?,
Command::Serve { .. } | Command::Repo(_) => unreachable!("run above"),
}
Ok(())
}
Expand Down
Loading