Compare commits
10 Commits
8a197e60aa
...
4ff8fb7931
Author | SHA1 | Date | |
---|---|---|---|
4ff8fb7931 | |||
![]() |
fafba9c370 | ||
![]() |
6ab0e86b42 | ||
![]() |
0498b9cb5d | ||
![]() |
694169d815 | ||
![]() |
233c3f7706 | ||
![]() |
8a60567757 | ||
![]() |
6117d6c3c2 | ||
![]() |
28877e603f | ||
![]() |
c56a845f8b |
0
.gitignore
vendored
Normal file
0
.gitignore
vendored
Normal file
@@ -1,75 +0,0 @@
|
||||
# Contributing to Bellande Robotics Sensors Research Innovations Center
|
||||
We're excited that you're interested in contributing to the Bellande Robotics Sensors Research Innovations Center! This document outlines the process for contributing to our organization and this repository!
|
||||
|
||||
## Important Links
|
||||
- Bellande Robotics Sensors Research Innovations Center: [Bellande Robotics Sensors Research Innovations Center](https://github.com/Robotics-Sensors/bellande_robotics_sensors_research_innovations_center_contributor)
|
||||
|
||||
## Table of Contents
|
||||
1. [Contributing to the Organization](#contributing-to-the-organization)
|
||||
- [Creating a Repository](#creating-a-repository)
|
||||
- [Team Requests](#team-requests)
|
||||
- [Security](#security)
|
||||
2. [Contributing to Repositories](#contributing-to-repositories)
|
||||
- [New Features](#new-features)
|
||||
- [Bug Fixes](#bug-fixes)
|
||||
- [Security Issues](#security-issues)
|
||||
- [Other Contributions](#other-contributions)
|
||||
|
||||
## Contributing to the Organization
|
||||
To contribute to the Bellande Robotics Sensors Research Innovations Center organization, please visit our [GitHub page](https://github.com/Robotics-Sensors/bellande_robotics_sensors_research_innovations_center_contributor).
|
||||
|
||||
### Creating a Repository
|
||||
1. Fork the [contributor repository](https://github.com/Robotics-Sensors/bellande_robotics_sensors_research_innovations_center_contributor).
|
||||
2. Create a new branch with a descriptive name for your proposed repository.
|
||||
3. Add a detailed description of the proposed repository in a markdown file.
|
||||
4. Submit a pull request with your proposal.
|
||||
5. Wait for review and approval from the organization administrators.
|
||||
|
||||
### Team Requests
|
||||
1. To request joining a team or creating a new team:
|
||||
- Open an issue in the [contributor repository](https://github.com/Robotics-Sensors/bellande_robotics_sensors_research_innovations_center_contributor).
|
||||
- Use the title format: "Team Request: [Team Name]"
|
||||
- Provide details about your expertise and why you want to join or create the team.
|
||||
2. An administrator will review your request and respond accordingly.
|
||||
|
||||
### Security
|
||||
For organization-wide security concerns:
|
||||
1. Do not publicly disclose the issue.
|
||||
2. Contact the organization administrators directly through a private channel.
|
||||
3. Provide a detailed description of the security concern.
|
||||
|
||||
## Contributing to Repositories
|
||||
### New Features
|
||||
1. Fork the repository you want to contribute to.
|
||||
2. Create a new branch with a descriptive name for your feature.
|
||||
3. Implement your feature, following the project's coding standards and guidelines.
|
||||
4. Write tests for your new feature if applicable.
|
||||
5. Update documentation as necessary.
|
||||
6. Submit a pull request with a clear description of the new feature.
|
||||
|
||||
### Bug Fixes
|
||||
1. Fork the repository containing the bug.
|
||||
2. Create a new branch with a descriptive name for your bug fix.
|
||||
3. Fix the bug and add tests to prevent regression if possible.
|
||||
4. Update documentation if necessary.
|
||||
5. Submit a pull request with a clear description of the bug and your fix.
|
||||
|
||||
### Security Issues
|
||||
For repository-specific security issues:
|
||||
1. Do not publicly disclose the issue.
|
||||
2. Contact the repository maintainers directly through a private channel or request a issue in the reposiroty
|
||||
3. Provide a detailed description of the security vulnerability.
|
||||
4. Wait for further instructions from the maintainers.
|
||||
|
||||
### Other Contributions
|
||||
We welcome other types of contributions, such as:
|
||||
- Documentation improvements
|
||||
- Code refactoring
|
||||
- Performance optimizations- Tooling and infrastructure improvements
|
||||
|
||||
For these contributions, follow a similar process to submitting new features or bug fixes.
|
||||
|
||||
## Code of Conduct
|
||||
Please note that all contributors are expected to adhere to our Code of Conduct. Respectful and inclusive behavior is mandatory for all participants in our project.
|
||||
|
||||
Thank you for contributing to the Bellande Robotics Sensors Research Innovations Center!
|
BIN
Package/python/dist/bellande_probability-0.0.1.tar.gz
vendored
Normal file
BIN
Package/python/dist/bellande_probability-0.0.1.tar.gz
vendored
Normal file
Binary file not shown.
BIN
Package/python/dist/bellande_probability-0.0.2.tar.gz
vendored
Normal file
BIN
Package/python/dist/bellande_probability-0.0.2.tar.gz
vendored
Normal file
Binary file not shown.
BIN
Package/python/dist/bellande_probability-0.0.3.tar.gz
vendored
Normal file
BIN
Package/python/dist/bellande_probability-0.0.3.tar.gz
vendored
Normal file
Binary file not shown.
2
Package/python/publish.sh
Executable file
2
Package/python/publish.sh
Executable file
@@ -0,0 +1,2 @@
|
||||
python setup.py sdist
|
||||
twine upload dist/*
|
43
Package/python/setup.py
Normal file
43
Package/python/setup.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
with open("../../README.md", "r", encoding="utf-8") as fh:
|
||||
long_description = fh.read()
|
||||
|
||||
setup(
|
||||
name="bellande_probability",
|
||||
version="0.0.3",
|
||||
description="Robots Probability",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
author="RonaldsonBellande",
|
||||
author_email="ronaldsonbellande@gmail.com",
|
||||
packages=find_packages(where="src"),
|
||||
package_dir={"": "src"},
|
||||
include_package_data=True,
|
||||
install_requires=[
|
||||
"numpy",
|
||||
],
|
||||
classifiers=[
|
||||
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
|
||||
"Programming Language :: Python",
|
||||
],
|
||||
keywords=["package", "setuptools"],
|
||||
python_requires=">=3.0",
|
||||
extras_require={
|
||||
"dev": ["pytest", "pytest-cov[all]", "mypy", "black"],
|
||||
},
|
||||
package_data={
|
||||
'bellande_probability': ['Bellande_Probability'],
|
||||
},
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'bellande_probability_api = bellande_probability.bellande_probability_api:main',
|
||||
],
|
||||
},
|
||||
project_urls={
|
||||
"Home": "https://github.com/Robotics-Sensors/bellande_probability",
|
||||
"Homepage": "https://github.com/Robotics-Sensors/bellande_probability",
|
||||
"documentation": "https://github.com/Robotics-Sensors/bellande_probability",
|
||||
"repository": "https://github.com/Robotics-Sensors/bellande_probability",
|
||||
},
|
||||
)
|
1
Package/python/src/.gitignore
vendored
Normal file
1
Package/python/src/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
bellande_probability.egg-info
|
0
Package/python/src/__init__.py
Normal file
0
Package/python/src/__init__.py
Normal file
3
Package/python/src/bellande_probabilistic/__init__.py
Normal file
3
Package/python/src/bellande_probabilistic/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
ros_extension
|
||||
"""
|
@@ -0,0 +1,81 @@
|
||||
# Copyright (C) 2024 Bellande Robotics Sensors Research Innovation Center, Ronaldson Bellande
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#!/usr/bin/env python3
|
||||
import requests
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
|
||||
def make_bellande_probability_distribution_request(mu_func, sigma_func, x, dimensions, full_auth=False):
|
||||
base_url = "https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Probability"
|
||||
|
||||
endpoint = f"{base_url}/bellande_probability_full_auth" if full_auth else \
|
||||
f"{base_url}/bellande_probability"
|
||||
|
||||
# Convert string input to list if it's a string
|
||||
if isinstance(x, str):
|
||||
x = json.loads(x)
|
||||
|
||||
auth = {
|
||||
"full_authorization_key": "bellande_web_api_full_auth"
|
||||
} if full_auth else {
|
||||
"authorization_key": "bellande_web_api_opensource"
|
||||
}
|
||||
|
||||
payload = {
|
||||
"mu_func": mu_func,
|
||||
"sigma_func": sigma_func,
|
||||
"x": x,
|
||||
"dimensions": dimensions,
|
||||
"auth": auth
|
||||
}
|
||||
|
||||
headers = {
|
||||
'accept': 'application/json',
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(endpoint, json=payload, headers=headers)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
except requests.RequestException as e:
|
||||
print(f"Error making request: {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Run Bellande Distribution API")
|
||||
parser.add_argument("--mu-func", required=True, help="mu function as string")
|
||||
parser.add_argument("--sigma-func", required=True, help="sigma function as string")
|
||||
parser.add_argument("--x", required=True, help="Input vector as JSON-formatted list")
|
||||
parser.add_argument("--dimensions", type=int, required=True, help="Number of dimensions")
|
||||
parser.add_argument("--full-auth", action="store_true", help="Use full authentication")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
result = make_bellande_probability_distribution_request(
|
||||
args.mu_func,
|
||||
args.sigma_func,
|
||||
args.x,
|
||||
args.dimensions,
|
||||
args.full_auth
|
||||
)
|
||||
|
||||
print(json.dumps(result, indent=2))
|
||||
except json.JSONDecodeError as e:
|
||||
print(f"Error: Invalid JSON format in input - {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
2
Package/rust/.gitignore
vendored
Normal file
2
Package/rust/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
target
|
||||
Cargo.lock
|
24
Package/rust/Cargo.toml
Normal file
24
Package/rust/Cargo.toml
Normal file
@@ -0,0 +1,24 @@
|
||||
[package]
|
||||
name = "bellande_probability"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
authors = ["Bellande Robotics Sensors Research Innovation Center"]
|
||||
description = "A tool for running Bellande Probability calculations via API"
|
||||
license = "GPL-3.0-or-later"
|
||||
repository = "https://github.com/Robotics-Sensors/bellande_probability"
|
||||
readme = "README.md"
|
||||
keywords = ["robotics", "algorithms", "research"]
|
||||
categories = ["science", "algorithms"]
|
||||
|
||||
[dependencies]
|
||||
reqwest = { version = "0.11", features = ["json"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
structopt = "0.3"
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
thiserror = "1.0"
|
||||
anyhow = "1.0"
|
||||
|
||||
[lib]
|
||||
name = "bellande_probability"
|
||||
path = "src/bellande_probability.rs"
|
4
Package/rust/publish.sh
Executable file
4
Package/rust/publish.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
cp ../../README.md .
|
||||
bash ../../git_scripts/push.sh
|
||||
cargo publish
|
||||
rm -f README.md
|
110
Package/rust/src/bellande_probability.rs
Normal file
110
Package/rust/src/bellande_probability.rs
Normal file
@@ -0,0 +1,110 @@
|
||||
// Copyright (C) 2024 Bellande Robotics Sensors Research Innovation Center, Ronaldson Bellande
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use reqwest;
|
||||
use serde_json::{json, Value};
|
||||
use std::error::Error;
|
||||
use structopt::StructOpt;
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
#[structopt(name = "bellande_probability", about = "Bellande Probability Tool")]
|
||||
struct Opt {
|
||||
#[structopt(long, help = "First coordinate as JSON-formatted list")]
|
||||
node0: String,
|
||||
|
||||
#[structopt(long, help = "Second coordinate as JSON-formatted list")]
|
||||
node1: String,
|
||||
|
||||
#[structopt(long, help = "Probability threshold value")]
|
||||
threshold: f64,
|
||||
|
||||
#[structopt(long, help = "Number of dimensions")]
|
||||
dimensions: i32,
|
||||
|
||||
#[structopt(long, help = "Use full authentication")]
|
||||
full_auth: bool,
|
||||
}
|
||||
|
||||
async fn make_bellande_probability_request(
|
||||
node0: Value,
|
||||
node1: Value,
|
||||
threshold: f64,
|
||||
dimensions: i32,
|
||||
full_auth: bool,
|
||||
) -> Result<Value, Box<dyn Error>> {
|
||||
let client = reqwest::Client::new();
|
||||
let base_url = "https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Probability";
|
||||
|
||||
let endpoint = if full_auth {
|
||||
format!("{}/bellande_probability_full_auth", base_url)
|
||||
} else {
|
||||
format!("{}/bellande_probability", base_url)
|
||||
};
|
||||
|
||||
let auth = if full_auth {
|
||||
json!({
|
||||
"full_authorization_key": "bellande_web_api_full_auth"
|
||||
})
|
||||
} else {
|
||||
json!({
|
||||
"authorization_key": "bellande_web_api_opensource"
|
||||
})
|
||||
};
|
||||
|
||||
let payload = json!({
|
||||
"node0": node0,
|
||||
"node1": node1,
|
||||
"threshold": threshold,
|
||||
"dimensions": dimensions,
|
||||
"auth": auth
|
||||
});
|
||||
|
||||
let response = client
|
||||
.post(&endpoint)
|
||||
.header("accept", "application/json")
|
||||
.header("Content-Type", "application/json")
|
||||
.json(&payload)
|
||||
.send()
|
||||
.await?
|
||||
.json::<Value>()
|
||||
.await?;
|
||||
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let opt = Opt::from_args();
|
||||
|
||||
let node0: Value = serde_json::from_str(&opt.node0)
|
||||
.map_err(|e| format!("Error parsing node0: {}", e))?;
|
||||
let node1: Value = serde_json::from_str(&opt.node1)
|
||||
.map_err(|e| format!("Error parsing node1: {}", e))?;
|
||||
|
||||
match make_bellande_probability_request(
|
||||
node0,
|
||||
node1,
|
||||
opt.threshold,
|
||||
opt.dimensions,
|
||||
opt.full_auth
|
||||
).await {
|
||||
Ok(result) => {
|
||||
println!("{}", serde_json::to_string_pretty(&result)?);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error: {}", e);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
66
README.md
66
README.md
@@ -10,32 +10,7 @@
|
||||
# Author, Creator and Maintainer
|
||||
- **Ronaldson Bellande**
|
||||
|
||||
# API HTTP Usability (BELLANDE FORMAT)
|
||||
```
|
||||
# Copyright (C) 2024 Bellande Robotics Sensors Research Innovation Center, Ronaldson Bellande
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
# GNU General Public License v3.0 or later
|
||||
|
||||
url: https://bellande-robotics-sensors-research-innovation-center.org
|
||||
|
||||
endpoint_path:
|
||||
bellande_probabilistic: /api/Bellande_Probabilistic/bellande_probabilistic_nd
|
||||
|
||||
Bellande_Framework_Access_Key: bellande_web_api_opensource
|
||||
```
|
||||
|
||||
# API HTTP Usability (JSON FORMAT)
|
||||
# API Usability
|
||||
```
|
||||
{
|
||||
"license": [
|
||||
@@ -56,12 +31,11 @@ Bellande_Framework_Access_Key: bellande_web_api_opensource
|
||||
],
|
||||
"url": "https://bellande-robotics-sensors-research-innovation-center.org",
|
||||
"endpoint_path": {
|
||||
"bellande_probabilistic": "/api/Bellande_Probabilistic/bellande_probabilistic_nd"
|
||||
"bellande_probabilistic": "/api/Bellande_Probability/bellande_probability"
|
||||
},
|
||||
"Bellande_Framework_Access_Key": "bellande_web_api_opensource"
|
||||
}
|
||||
```
|
||||
|
||||
# API Payload Example
|
||||
```
|
||||
{
|
||||
@@ -81,7 +55,7 @@ Bellande_Framework_Access_Key: bellande_web_api_opensource
|
||||
# Quick Bellande API Testing
|
||||
```
|
||||
curl -X 'POST' \
|
||||
'https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Distribution/bellande_distribution_function_nd' \
|
||||
'https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Probability/bellande_probability' \
|
||||
-H 'accept: application/json' \
|
||||
-H 'Content-Type: application/json' \
|
||||
-d '{
|
||||
@@ -95,6 +69,40 @@ curl -X 'POST' \
|
||||
}'
|
||||
```
|
||||
|
||||
# Bellande Limit Usage
|
||||
|
||||
## Website Crates
|
||||
- https://crates.io/crates/bellande_probability
|
||||
|
||||
### Installation
|
||||
- `cargo add bellande_probability`
|
||||
|
||||
## Website PYPI
|
||||
- https://pypi.org/project/bellande_probability
|
||||
|
||||
### Installation
|
||||
- `$ pip install bellande_probability`
|
||||
|
||||
### Usage
|
||||
```
|
||||
bellande_distribution \
|
||||
--mu-func "i * 2" \
|
||||
--sigma-func "1 + i * 0.1" \
|
||||
--x "[1.0, 2.0, 3.0]" \
|
||||
--dimensions 3
|
||||
```
|
||||
|
||||
### Upgrade (if not upgraded)
|
||||
- `$ pip install --upgrade bellande_probability`
|
||||
|
||||
```
|
||||
Name: bellande_probability
|
||||
Summary: Computes the next step towards a target node
|
||||
Home-page: github.com/RonaldsonBellande/bellande_probability
|
||||
Author: Ronaldson Bellande
|
||||
Author-email: ronaldsonbellande@gmail.com
|
||||
License: GNU General Public License v3.0
|
||||
```
|
||||
|
||||
## Published Paper
|
||||
```
|
||||
|
3
git_scripts/.gitignore
vendored
Normal file
3
git_scripts/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
fix_errors.sh
|
||||
push.sh
|
||||
repository_recal.sh
|
@@ -1,31 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Get the URL from .git/config
|
||||
git_url=$(git config --get remote.origin.url)
|
||||
|
||||
# Check if a URL is found
|
||||
if [ -z "$git_url" ]; then
|
||||
echo "No remote URL found in .git/config."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Clone the repository into a temporary folder
|
||||
git clone "$git_url" tmp_clone
|
||||
|
||||
# Check if the clone was successful
|
||||
if [ $? -eq 0 ]; then
|
||||
# Remove the existing .git directory if it exists
|
||||
if [ -d ".git" ]; then
|
||||
rm -rf .git
|
||||
fi
|
||||
|
||||
# Copy the .git directory from the clone to the current repository
|
||||
cp -r tmp_clone/.git .
|
||||
|
||||
# Remove the clone directory
|
||||
rm -rf tmp_clone
|
||||
|
||||
echo "Repository cloned and .git directory copied successfully."
|
||||
else
|
||||
echo "Failed to clone the repository."
|
||||
fi
|
@@ -1,25 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Git push what is already in the repository
|
||||
git pull --no-edit; git fetch;
|
||||
|
||||
# Exclude specific files and directories
|
||||
EXCLUDES=(".git" ".gitignore" "executable")
|
||||
|
||||
# Find all non-hidden files and directories, excluding any hidden files and directories
|
||||
find . -type f ! -path '*/.*' -print0 | while IFS= read -r -d '' file; do
|
||||
# Check if the file is in the exclude list
|
||||
should_exclude=false
|
||||
for exclude in "${EXCLUDES[@]}"; do
|
||||
if [[ "$(basename "$file")" == "$exclude" ]]; then
|
||||
should_exclude=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# Add file to staging area if it's not excluded
|
||||
if [ "$should_exclude" = false ]; then
|
||||
git add -f "$file"
|
||||
fi
|
||||
done
|
||||
git commit -am "latest pushes"; git push
|
@@ -1,110 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Git push what is already in the repository
|
||||
git pull --no-edit; git fetch; git add .; git commit -am "latest pushes"; git push
|
||||
|
||||
# Get the current directory
|
||||
current_dir=$(pwd)
|
||||
|
||||
# Read the remote repository URL from .git/config
|
||||
remote_repo_url=$(git -C "$current_dir" config --get remote.origin.url)
|
||||
|
||||
# Create a temporary directory for cloning the repository
|
||||
temp_dir=$(mktemp -d)
|
||||
|
||||
# Clone the repository into the temporary directory without using local references
|
||||
git clone --no-local "$current_dir" "$temp_dir"
|
||||
|
||||
# Switch to the temporary directory
|
||||
cd "$temp_dir"
|
||||
|
||||
# Create a temporary file to store the file list
|
||||
tmp_file=$(mktemp)
|
||||
# Create a temporary file to store the processed commits
|
||||
processed_commits_file=$(mktemp)
|
||||
|
||||
# Function to check if a commit has already been processed
|
||||
is_commit_processed() {
|
||||
local commit="$1"
|
||||
|
||||
# Check if the commit is already processed
|
||||
grep -Fxq "$commit" "$processed_commits_file"
|
||||
}
|
||||
|
||||
# Function to mark a commit as processed
|
||||
mark_commit_processed() {
|
||||
local commit="$1"
|
||||
|
||||
# Mark the commit as processed
|
||||
echo "$commit" >> "$processed_commits_file"
|
||||
}
|
||||
|
||||
# Function to check if a file or folder exists in the repository
|
||||
file_exists_in_repo() {
|
||||
local file_path="$1"
|
||||
|
||||
# Check if the file or folder exists in the repository
|
||||
git ls-tree --name-only -r HEAD | grep -Fxq "$file_path"
|
||||
}
|
||||
|
||||
# Function to process the files and folders in each commit
|
||||
process_commit_files() {
|
||||
local commit="$1"
|
||||
|
||||
# Check if the commit has already been processed
|
||||
if is_commit_processed "$commit"; then
|
||||
echo "Commit $commit already processed. Skipping..."
|
||||
return
|
||||
fi
|
||||
|
||||
# Get the list of files and folders in the commit (including subfolders)
|
||||
git ls-tree --name-only -r "$commit" >> "$tmp_file"
|
||||
|
||||
# Process each file or folder in the commit
|
||||
while IFS= read -r line
|
||||
do
|
||||
# Check if the file or folder exists in the current push
|
||||
if file_exists_in_repo "$line"; then
|
||||
echo "Keeping: $line"
|
||||
else
|
||||
echo "Deleting: $line"
|
||||
git filter-repo --path "$line" --invert-paths
|
||||
fi
|
||||
done < "$tmp_file"
|
||||
|
||||
# Mark the commit as processed
|
||||
mark_commit_processed "$commit"
|
||||
|
||||
# Clear the temporary file
|
||||
> "$tmp_file"
|
||||
}
|
||||
|
||||
# Iterate over each commit in the repository
|
||||
git rev-list --all | while IFS= read -r commit
|
||||
do
|
||||
process_commit_files "$commit"
|
||||
done
|
||||
|
||||
# Push the filtered changes to the original repository
|
||||
git remote add origin "$remote_repo_url"
|
||||
git push --force origin main
|
||||
|
||||
# Perform a history rewrite to remove the filtered files
|
||||
git filter-repo --force
|
||||
|
||||
# Fetch the changes from the remote repository
|
||||
git -C "$current_dir" fetch origin
|
||||
|
||||
# Merge the remote changes into the local repository
|
||||
git -C "$current_dir" merge origin/main --no-edit
|
||||
|
||||
# Update the local repository and reduce the size of .git if needed
|
||||
git -C "$current_dir" gc --prune=now
|
||||
git -C "$current_dir" reflog expire --expire=now --all
|
||||
git -C "$current_dir" repack -ad
|
||||
|
||||
# Clean up temporary files and directories
|
||||
cd "$current_dir"
|
||||
rm -rf "$temp_dir"
|
||||
rm "$tmp_file"
|
||||
rm "$processed_commits_file"
|
Reference in New Issue
Block a user