Skip to content
Merged
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
11 changes: 7 additions & 4 deletions archived/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@
This projects in archive folder has been officially archived. Please note the following:

1. **No Further Development** The projects is no longer actively developed. There will be no new features, enhancements, or updates.
2. **Maintenance Status** We will not be maintaining the project. This includes not addressing any new issues, bugs, or security vulnerabilities that may be discovered.
2. **Maintenance Status** We will not be maintaining this projects. This includes not addressing any new issues, bugs, or security vulnerabilities that may be discovered.
3. **Read-Only** The repository is now in a read-only state. We will not accept any pull requests, changes, or contributions.
4. **Documentation & Issues** Existing documentation and issues will remain accessible for reference, but no new issues can be raised, and existing ones will not be addressed.

## Background & Alternatives

1. *ui* - The ui project will be replaced by a new project named [moon](../moon/README.md).
2. *sync* - There are no replaced plan for the sync project.
3. *build-bazel-tool* - The project will be replaced, but still not have a new project plan.
3. *build-bazel-tool* - The project will be abandon. The mega will use the [Buck2](https://buck2.build) as the build tool.
4. *website* - The website project will be replaced by a new project named [Mars](../mars/README.md) in the feature.
5. *mda* - The mda project still not have a replacement project. For now, we are working on decentralized LLM development.
6. *fuse* - There are an alternate project plan to rewrite the **fuse** within [OSPP](https://summer-ospp.ac.cn) 2024 program, will be named [Scorpion](../scorpio/README.md).
7. *kvcache* - The kvcache project still does not have a replacement project.
8. *p2p* - The p2p project will be replaced by a new project named [Gemini](../gemini/README.md).
9. *git* - The git project will be replaced by a new project named [Mercury](../mercury/README.md).
10. *storage* - The storage project will be replaced by a new project named [Venus](../venus/README.md).

[Optional: Suggest any alternative tools, libraries, or projects that users can consider as a replacement for this project.]

Contact
If you have any questions or need further information, please feel free to reach out to [contact information].
## Contact

If you interested in Mega, you can make an appointment with us on [Google Calendar](https://calendar.app.google/QuBf2sdmf68wVYWL7) to discuss your ideas, questions or problems, and we will share our vision and roadmap with you.
3 changes: 2 additions & 1 deletion libra/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Libra
`libra` is a `Git` Client in `Rust`.

`Libra` is a partial implementation of a **Git** client, developed using **Rust**. Our goal is not to create a 100% replica of Git (for those interested in such a project, please refer to the [gitoxide](https://github.com/Byron/gitoxide)). Instead, `libra` focus on implementing the basic functionalities of Git for learning **Git** and **Rust**. A key feature of `libra` is the replacement of the original **Git** internal storage architecture with **SQLite**.

## Example
```
Expand Down
67 changes: 49 additions & 18 deletions libra/src/command/init.rs
Original file line number Diff line number Diff line change
@@ -1,79 +1,100 @@
//! This module implements the `init` command for the Libra CLI.
//!
//!
//!
// Import necessary standard libraries
use std::{env, fs, io};

// Import necessary libraries from sea_orm
use sea_orm::{ActiveModelTrait, DbConn, DbErr, Set, TransactionTrait};

// Import necessary modules from the internal crate
use crate::internal::db;
use crate::internal::model::{config, reference};
use crate::utils::util::{DATABASE, ROOT_DIR};
use sea_orm::{ActiveModelTrait, DbConn, DbErr, Set, TransactionTrait};
use std::{env, fs, io};

/// Execute the init function
pub async fn execute() {
init().await.unwrap();
}

/// Initialize a new Libra repository
/// This function creates the necessary directories and files for a new Libra repository.
/// It also sets up the database and the initial configuration.
#[allow(dead_code)]
pub async fn init() -> io::Result<()> {
// Get the current directory
let cur_dir = env::current_dir()?;
// Join the current directory with the root directory
let root_dir = cur_dir.join(ROOT_DIR);
// Check if the root directory already exists
if root_dir.exists() {
println!("Already initialized - [{}]", root_dir.display());
return Ok(());
}

// create .libra & sub-dirs
// Create .libra & sub-dirs
let dirs = ["objects/pack", "objects/info", "info"];
for dir in dirs {
fs::create_dir_all(root_dir.join(dir))?;
}
// create info/exclude
// Create info/exclude
// `include_str!` includes the file content while compiling
fs::write(
root_dir.join("info/exclude"),
include_str!("../../template/exclude"),
)?;
// create .libra/description
// Create .libra/description
fs::write(
root_dir.join("description"),
include_str!("../../template/description"),
)?;

// create database: .libra/libra.db
// Create database: .libra/libra.db
let database = root_dir.join(DATABASE);
let conn = db::create_database(database.to_str().unwrap()).await?;

// create config table
// Create config table
init_config(&conn).await.unwrap();

// create HEAD
// Create HEAD
reference::ActiveModel {
name: Set(Some("master".to_owned())),
kind: Set(reference::ConfigKind::Head),
..Default::default() // all others are `NotSet`
}
.insert(&conn)
.await
.unwrap();
.insert(&conn)
.await
.unwrap();

// set .libra as hidden
// Set .libra as hidden
set_dir_hidden(root_dir.to_str().unwrap())?;
println!(
"Initializing empty Libra repository in {}",
root_dir.display()
);

Ok(())
}

/// Initialize the configuration for the Libra repository
/// This function creates the necessary configuration entries in the database.
async fn init_config(conn: &DbConn) -> Result<(), DbErr> {
// Begin a new transaction
let txn = conn.begin().await?;

// Define the configuration entries for non-Windows systems
#[cfg(not(target_os = "windows"))]
let entries = [
let entries = [
("repositoryformatversion", "0"),
("filemode", "true"),
("bare", "false"),
("logallrefupdates", "true"),
];

// Define the configuration entries for Windows systems
#[cfg(target_os = "windows")]
let entries = [
let entries = [
("repositoryformatversion", "0"),
("filemode", "false"), // no filemode on windows
("bare", "false"),
Expand All @@ -82,6 +103,7 @@ async fn init_config(conn: &DbConn) -> Result<(), DbErr> {
("ignorecase", "true"), // ignorecase on windows
];

// Insert each configuration entry into the database
for (key, value) in entries {
// tip: Set(None) == NotSet == default == NULL
let entry = config::ActiveModel {
Expand All @@ -92,32 +114,41 @@ async fn init_config(conn: &DbConn) -> Result<(), DbErr> {
};
entry.insert(&txn).await?;
}
// Commit the transaction
txn.commit().await?;
Ok(())
}

/// Set a directory as hidden on Windows systems
/// This function uses the `attrib` command to set the directory as hidden.
#[cfg(target_os = "windows")]
fn set_dir_hidden(dir: &str) -> io::Result<()> {
use std::process::Command;
Command::new("attrib").arg("+H").arg(dir).spawn()?.wait()?; // 等待命令执行完成
Ok(())
}

/// On Unix-like systems, directories starting with a dot are hidden by default
/// Therefore, this function does nothing.
#[cfg(not(target_os = "windows"))]
fn set_dir_hidden(_dir: &str) -> io::Result<()> {
// on unix-like systems, dotfiles are hidden by default
Ok(())
}

/// Unit tests for the init module
#[cfg(test)]
mod tests {
use super::*;
use super::init;
use crate::utils::test;

/// Test the init function
#[tokio::test]
async fn test_init() {
test::setup_without_libra();
// Set up the test environment without a Libra repository
test::setup_clean_testing_env();

// Run the init function
init().await.unwrap();
// TODO check the result
}
}
}
30 changes: 18 additions & 12 deletions libra/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
//! This is the main entry point for the Libra.
//! It includes the definition of the CLI and the main function.
//!
//!
use clap::{Parser, Subcommand};

mod command;
mod internal;
mod utils;

// The Cli struct represents the root of the command line interface.
#[derive(Parser, Debug)]
#[command(about = "Simulates git commands", version = "1.0")]
#[command(about = "Libra: A partial Git implemented in Rust", version = "0.1.0-pre")]
struct Cli {
#[command(subcommand)]
command: Commands,
}

/// Libra sub commands, similar to git
/// subcommands's excute and args are defined in `command` module
/// THe Commands enum represents the subcommands that can be used with the CLI.
/// subcommand's execute and args are defined in `command` module
#[derive(Subcommand, Debug)]
enum Commands {
// start a working area
// Each variant of the enum represents a subcommand.
// The about attribute provides a brief description of the subcommand.
// The arguments of the subcommand are defined in the command module.

// Init and Clone are the only commands that can be executed without a repository
#[command(about = "Initialize a new repository")]
Init,
#[command(about = "Clone a repository into a new directory")]
Clone(command::clone::CloneArgs),

// work on the current change
// The rest of the commands require a repository to be present
#[command(about = "Add file contents to the index")]
Add(command::add::AddArgs),
#[command(about = "Remove files from the working tree and from the index")]
Rm(command::remove::RemoveArgs),
#[command(about = "Restore working tree files")]
Restore(command::restore::RestoreArgs),

// examine the history and state
#[command(about = "Show the working tree status")]
Status,
#[command(about = "Show commit logs")]
Log(command::log::LogArgs),

// grow, mark and tweak your common history
#[command(about = "List, create, or delete branches")]
Branch(command::branch::BranchArgs),
#[command(about = "Record changes to the repository")]
Expand All @@ -43,9 +49,6 @@ enum Commands {
Switch(command::switch::SwitchArgs),
#[command(about = "Merge changes")]
Merge(command::merge::MergeArgs),

// collaborate
// todo: implement in the future
#[command(about = "Update remote refs along with associated objects")]
Push(command::push::PushArgs),
#[command(about = "Download objects and refs from another repository")]
Expand All @@ -64,6 +67,8 @@ enum Commands {
IndexPack(command::index_pack::IndexPackArgs),
}

// The main function is the entry point of the Libra application.
// It parses the command-line arguments and executes the corresponding function.
#[tokio::main]
async fn main() {
let args = Cli::parse();
Expand Down Expand Up @@ -109,5 +114,6 @@ async fn main() {
#[test]
fn verify_cli() {
use clap::CommandFactory;

Cli::command().debug_assert()
}
Loading