From d048ee782c5698f57db3b06d436b90ccd8d1bde8 Mon Sep 17 00:00:00 2001 From: Vadim Troshchinskiy Date: Mon, 7 Jul 2025 09:56:49 +0200 Subject: [PATCH] refs #2371 hide commits that can't be restored --- api/repo_api.py | 30 +++++++++++++++++++++++++++++- api/swagger.yaml | 19 +++++++++++-------- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/api/repo_api.py b/api/repo_api.py index c52ab95..705a2dc 100644 --- a/api/repo_api.py +++ b/api/repo_api.py @@ -2559,6 +2559,7 @@ def git_get_commits(repo, branch): max_commits = request.args.get('max_commits') or 100 skip_commits = request.args.get('skip') or 0 + filter_commits = (request.args.get('filter_commits') or 1) == 1 git_repo = git.Repo(repo_path) @@ -2580,14 +2581,41 @@ def git_get_commits(repo, branch): hash_to_tag[sha] = hash_to_tag[sha] + [ tag.name ] + first_commit = next(git_repo.iter_commits(reverse=True)) + commits = [] + git_repo.iter_commits() for com in git_repo.iter_commits(branch, max_count = max_commits, skip = skip_commits): tag_list = [] + # Initial check-ins contain only a .gitignore, used to test the repository is working, + # and do a force push to the destination. + # + # We don't want to show this one to the users by default, since it's not a functional + # restoration point. + # + # To make sure users can use git normally, we try to detect it in a slightly paranoid + # manner here. We want to avoid magic markers or to always skip the first commit, in + # case it might actually contain data. + skip_this_commit = False + + # Check: + # * First commit, and we want filtering + # * There's only one blob + # * The one file is .gitignore. + if com == first_commit and filter_commits: + if len(com.tree.blobs) == 1: + for file in com.tree.traverse(depth=1, visit_once=False): + if file.name == ".gitignore" and file.type == "blob": + skip_this_commit = True + + if skip_this_commit: + continue + + if com.hexsha in hash_to_tag: tag_list = hash_to_tag[com.hexsha] - commits = commits + [ { "hexsha" : com.hexsha, diff --git a/api/swagger.yaml b/api/swagger.yaml index 975bb29..ce258ea 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -1982,9 +1982,6 @@ paths: Especificando **ssh_key** se agrega la cclave especificada directamente. - Especificando **oglive** se descarga si es necesario el .iso, se monta, y se extrae la clave. - Esta acción se hace en el fondo, y se devuelve un job_id. - tags: - "Git" parameters: @@ -2006,10 +2003,6 @@ paths: type: string example: "OgLive r20250518" required: False - oglive: - type: string - example: "https://ognproject.evlt.uma.es/oglive/ogLive-noble-6.8.0-31-generic-amd64-r20250518.cf13a6d_20250519.iso" - required: False responses: "200": description: "Exito" @@ -2270,7 +2263,12 @@ paths: get: summary: "Obtener lista de commits en una rama" description: | - Devuelve una lista de commits de Git + Devuelve una lista de commits de Git. + + **Filtrado de commits:** + Por defecto algunos commits que no son utiles para restaurar una imagen se ocultan. + Pasar filter_commits=0 para desactivar esta funcionalidad y ver todos los commits + del repositorio. tags: - "Git" parameters: @@ -2294,6 +2292,11 @@ paths: required: false type: int description: "Commits a saltar (para paginación)" + - name: filter_commits + in: query + required: false + type: int + description: "Si aplicar filtrado de commits. Por defecto 1." responses: "200": description: "Lista de commits"