OSS Porter Core Library (oss_porter_core)
This crate provides the foundational logic and functionality for the oss-porter toolset. It handles configuration management, Git interactions, project extraction, state tracking, update processing, and basic checks required for managing the synchronization between internal and public project repositories.
Purpose
This library is primarily consumed by the oss-porter-cli binary crate and potentially other frontends (like a GUI). It encapsulates the core operations in a reusable way. While it can be used directly in other Rust applications needing similar functionality, its API is mainly tailored to the needs of oss-porter.
Modules
The core logic is organized into several modules:
config: Handles loading, parsing, saving, and finding theoss-porter.tomlconfiguration file. Defines theConfigFileandProjectConfigstructs.state: Manages the synchronization state (.oss_porter_state.toml), including reading the last synced commit, writing updates, and committing state changes back to the internal repository.extract: Implements the initial project extraction logic for bothclean_slate(file copy) andpreserve(history filtering viagit-filter-repo) modes. Includes logic to exclude the state file from the extracted output.update: Contains the functions supporting the interactive update workflow:get_internal_commits_since: Finds relevant new commits in the internal repository.get_commit_diff_relative: Generates formatted diffs for review.apply_commit_to_output: Applies changes from a specific internal commit to the output repository using a patch-based approach (git format-patch+git am).
check: Provides functions to perform basic checks on the output repository, such as looking for internal path dependencies inCargo.tomland checking for license file presence.remote: Handles interactions with the public Git remote, specifically thepush_to_remotefunctionality.utils: Contains helper functions, primarily for executing external commands likegitandgit-filter-reporeliably and capturing their output.lib.rs: Defines the top-level structs (ProjectConfig,ConfigFile, etc.) and the mainPorterErrorenum usingthiserror.
Key Structs & Enums
ProjectConfig: Represents the configuration specific to a single project being managed (paths, branches, mode, etc.). Defined inlib.rs. Note: Expectssnake_casekeys when deserialized from TOML.ConfigFile: Represents the entire parsedoss-porter.tomlfile, including global settings and the map of projects. Defined inlib.rs.PorterError: The central error type for all fallible operations within the core library. Defined inlib.rs.HistoryMode: Enum for extraction modes (CleanSlate,Preserve). Defined inlib.rs.CommitInfo: Simple struct holding commit hash and subject, used by the update module. Defined inupdate.rs.ApplyResult: Enum indicating the outcome of attempting to apply a commit/patch (Success,Conflict,Failure). Defined inupdate.rs.ExtractionResult/CheckResult: Structs holding the results of their respective operations. Defined inlib.rs.
Direct Usage Example
While primarily used by the CLI, you could use the core library like this:
use ;
use Path;