Add git repository GC function
parent
371a440b9a
commit
b8e50585cd
|
@ -2208,6 +2208,24 @@ def rename_image():
|
|||
# -----------------------------------------------------------
|
||||
|
||||
|
||||
def git_compact_repository_task(repo, job_id):
|
||||
journal.send("Running function 'git_compact_repository_task'...", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
|
||||
git_repo_path = os.path.join(REPOSITORIES_BASE_PATH, repo + ".git")
|
||||
git_repo = git.Repo(git_repo_path)
|
||||
git_repo.git.config('--global', '--add', 'safe.directory', git_repo_path)
|
||||
|
||||
git_repo.git.gc()
|
||||
|
||||
data = {
|
||||
'job_id': job_id,
|
||||
'success': True
|
||||
}
|
||||
|
||||
journal.send(f"Calling function 'recall_ogcore' (JOB_ID: {job_id}, SUCCESS: True)", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
recall_ogcore(data)
|
||||
|
||||
|
||||
@app.route("/ogrepository/v1/git/repositories", methods=['GET'])
|
||||
def git_list_repositories():
|
||||
"""
|
||||
|
@ -2310,7 +2328,22 @@ def git_backup_repository(repo):
|
|||
|
||||
@app.route("/ogrepository/v1/git/repositories/<string:repo>/compact", methods=['POST'])
|
||||
def git_compact_repository(repo):
|
||||
return jsonify({"error" : "Not implemented"}), 500
|
||||
journal.send("Running endpoint 'Compactar repositorio Git'...", PRIORITY=journal.LOG_INFO, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
|
||||
if not os.path.isdir(REPOSITORIES_BASE_PATH):
|
||||
journal.send(f"Can't list repositories. Repository storage at {REPOSITORIES_BASE_PATH} not found", PRIORITY=journal.LOG_ERROR, SYSLOG_IDENTIFIER="ogrepo-api_DEBUG")
|
||||
return jsonify({"error": "Repository storage not found, git functionality may not be installed."}), 500
|
||||
|
||||
|
||||
job_id = f"GitGC_{''.join(random.choice('0123456789abcdef') for char in range(8))}"
|
||||
threading.Thread(target=git_compact_repository_task, args=(repo, job_id,)).start()
|
||||
|
||||
return jsonify({
|
||||
"success": True,
|
||||
"output": "Compacting...",
|
||||
"job_id": job_id
|
||||
}), 200
|
||||
|
||||
|
||||
@app.route("/ogrepository/v1/git/repositories/<string:repo>/branches", methods=['GET'])
|
||||
def git_get_branches(repo):
|
||||
|
|
Loading…
Reference in New Issue