Skip to content

Commit

Permalink
remove is_head from Branch since it is not required for the server logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gschoeni committed Aug 21, 2024
1 parent ca172a4 commit 8b34fa6
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 32 deletions.
29 changes: 25 additions & 4 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "Oxen"
version = "0.18.12"
version = "0.19.0"
edition = "2021"
license-file = "LICENSE"
description = "Oxen is a fast, unstructured data version control, to help version large machine learning datasets written in Rust."
Expand Down Expand Up @@ -49,6 +49,7 @@ comfy-table = "7.0.1"
duckdb = { package = "duckdb", version = "1.0.0", default-features=false, optional=true}
deadqueue = "0.2.4"
derive_more = { version = "1.0.0", features = ["full"] }
dialoguer = "0.11.0"
difference = "2.0.0"
dirs = "5.0.1"
dotenv = "0.15.0"
Expand Down
2 changes: 0 additions & 2 deletions docs/dev/IntegrateServerCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,10 @@ If you would like to see the API with `curl` on the command line you can run the
{
"name": "add-training-data",
"commit_id": "7d6258e0-5956-4695-aa13-6844b3c73e6d",
"is_head": false
},
{
"name": "main",
"commit_id": "11f6c5d5-f683-42b2-9d6e-a82172509eed",
"is_head": true
}
]
}
Expand Down
3 changes: 2 additions & 1 deletion src/cli/src/cmd/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ impl BranchCmd {

pub fn list_branches(&self, repo: &LocalRepository) -> Result<(), OxenError> {
let branches = repositories::branches::list(repo)?;
let current_branch = repositories::branches::current_branch(repo)?;

for branch in branches.iter() {
if branch.is_head {
if current_branch.is_some() && current_branch.as_ref().unwrap().name == branch.name {
let branch_str = format!("* {}", branch.name).green();
println!("{branch_str}")
} else {
Expand Down
1 change: 0 additions & 1 deletion src/lib/src/api/client/workspaces/commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub async fn commit(
let branch = Branch {
name: branch_name.to_string(),
commit_id: commit.id.clone(),
is_head: false
};
api::client::commits::post_push_complete(remote_repo, &branch, &commit.id).await?;
api::client::repositories::post_push(remote_repo, &branch, &commit.id).await?;
Expand Down
12 changes: 1 addition & 11 deletions src/lib/src/core/refs/ref_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ impl RefReader {
Ok(Some(Branch {
name: ref_name,
commit_id: id,
is_head: true,
}))
} else {
Ok(None)
Expand Down Expand Up @@ -145,7 +144,6 @@ impl RefReader {
branch_names.push(Branch {
name: ref_name.clone(),
commit_id: id.clone(),
is_head: (ref_name == head_ref.clone()),
});
}
}
Expand All @@ -163,19 +161,11 @@ impl RefReader {
}

pub fn get_branch_by_name(&self, name: &str) -> Result<Option<Branch>, OxenError> {
// log::debug!("get_branch_by_name {name}");
let maybe_head_id = self.head_commit_id()?;
if maybe_head_id.is_none() {
return Ok(None);
}

let head_commit_id = maybe_head_id.unwrap();
// log::debug!("get_branch_by_name got head_commit_id {}", head_commit_id);
log::debug!("get_branch_by_name {name}");
match self.get_commit_id_for_branch(name) {
Ok(Some(commit_id)) => Ok(Some(Branch {
name: name.to_string(),
commit_id: commit_id.to_string(),
is_head: commit_id == head_commit_id,
})),
Ok(None) => Ok(None),
Err(err) => Err(err),
Expand Down
4 changes: 0 additions & 4 deletions src/lib/src/core/refs/ref_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ impl RefWriter {
Ok(Branch {
name: String::from(name),
commit_id: String::from(commit_id),
is_head: false,
})
}
}
Expand Down Expand Up @@ -148,7 +147,6 @@ impl RefWriter {
branch_names.push(Branch {
name: ref_name.clone(),
commit_id: id.clone(),
is_head: (ref_name == head_ref),
});
}
_ => {
Expand All @@ -170,7 +168,6 @@ impl RefWriter {
Ok(Some(Branch {
name: ref_name,
commit_id: id,
is_head: true,
}))
} else {
Ok(None)
Expand All @@ -187,7 +184,6 @@ impl RefWriter {
Ok(Some(commit_id)) => Ok(Some(Branch {
name: name.to_string(),
commit_id: commit_id.to_string(),
is_head: commit_id == head_commit_id,
})),
Ok(None) => Ok(None),
Err(err) => Err(err),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ impl MerkleTreeNodeData {
self.children.is_empty()
}

/// Check if the node has children
pub fn has_children(&self) -> bool {
!self.children.is_empty()
}

/// Recursively count the total number of vnodes in the tree
pub fn total_vnodes(&self) -> u128 {
let mut count = 0;
Expand Down
25 changes: 22 additions & 3 deletions src/lib/src/core/v0_19_0/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::error::OxenError;
use crate::model::{Branch, LocalRepository, RemoteRepository};
use crate::{api, repositories};

use super::index::merkle_tree::node::MerkleTreeNodeData;
use super::index::merkle_tree::node::{MerkleTreeNodeData, MerkleTreeNodeType};

Check warning on line 6 in src/lib/src/core/v0_19_0/push.rs

View workflow job for this annotation

GitHub Actions / Check

unused import: `MerkleTreeNodeType`

Check failure on line 6 in src/lib/src/core/v0_19_0/push.rs

View workflow job for this annotation

GitHub Actions / Clippy

unused import: `MerkleTreeNodeType`
use super::index::merkle_tree::CommitMerkleTree;

pub async fn push(repo: &LocalRepository) -> Result<Branch, OxenError> {
Expand Down Expand Up @@ -65,13 +65,17 @@ async fn push_to_new_branch(
remote_repo: &RemoteRepository,
branch: &Branch,
) -> Result<(), OxenError> {
// Iterate over the nodes in the commit tree
// Get the commit from the branch
let Some(commit) = repositories::commits::get_by_id(repo, &branch.commit_id)? else {
return Err(OxenError::revision_not_found(
branch.commit_id.clone().into(),
));
};
// Figure out which nodes we need to push
let tree = CommitMerkleTree::from_commit(repo, &commit)?;

//

// Push each node, and all their file children
r_push_node(repo, remote_repo, &tree.root).await?;
// Push the commit
Expand All @@ -85,10 +89,25 @@ async fn r_push_node(
remote_repo: &RemoteRepository,
node: &MerkleTreeNodeData,
) -> Result<(), OxenError> {
// Check if the node exists on the remote
// GET /api/repos/:namespace/:repo_name/tree/nodes/:node_id
// Return the node, with all the unsynced children

// If not exists, create it

// List the children that need to be synced for the node

// If all children exist, return
// This way we don't have to push the same node twice

push_node(repo, remote_repo, node).await?;

for child in &node.children {
Box::pin(r_push_node(repo, remote_repo, child)).await?;
if child.has_children() {
Box::pin(r_push_node(repo, remote_repo, child)).await?;
}
}

Ok(())
}

Expand Down
1 change: 0 additions & 1 deletion src/lib/src/model/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use serde::{Deserialize, Serialize};
pub struct Branch {
pub name: String,
pub commit_id: String,
pub is_head: bool,
}

impl std::fmt::Display for Branch {
Expand Down
2 changes: 1 addition & 1 deletion src/server/src/controllers/branches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub async fn show(req: HttpRequest) -> actix_web::Result<HttpResponse, OxenHttpE
.ok_or(OxenError::remote_branch_not_found(&branch_name))?;

let view = BranchResponse {
status: StatusMessage::resource_created(),
status: StatusMessage::resource_found(),
branch,
};

Expand Down
26 changes: 26 additions & 0 deletions src/server/src/controllers/tree.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use crate::errors::OxenHttpError;
use crate::helpers::get_repo;
use crate::params::{app_data, path_param};

use liboxen::core::v0_10_0::cache::commit_cacher;

use liboxen::error::OxenError;
use liboxen::model::NewCommitBody;
use liboxen::view::workspaces::{ListWorkspaceResponseView, NewWorkspace, WorkspaceResponse};
use liboxen::view::{CommitResponse, StatusMessage, WorkspaceResponseView};
use liboxen::{core::v0_10_0::index, repositories};

use actix_web::{HttpRequest, HttpResponse};

pub mod changes;
pub mod data_frames;
pub mod files;

pub async fn get_node_children(
req: HttpRequest,
body: String,
) -> actix_web::Result<HttpResponse, OxenHttpError> {
// Take in the node id, and return which children are missing

return Ok(HttpResponse::BadRequest().json(StatusMessage::error("Implement me!".to_string())));
}
2 changes: 0 additions & 2 deletions src/server/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,6 @@ impl error::ResponseError for OxenHttpError {
HttpResponse::NotFound().json(error_json)
}
OxenError::BranchNotFound(branch) => {
log::debug!("Branch not found: {}", branch);

let error_json = json!({
"error": {
"type": MSG_RESOURCE_NOT_FOUND,
Expand Down
2 changes: 1 addition & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

use std::path::Path;

use liboxen::command;
use liboxen::error::OxenError;
use liboxen::repositories;
use liboxen::test;

#[test]
Expand Down

0 comments on commit 8b34fa6

Please sign in to comment.