Skip to content

Commit 4f9b659

Browse files
committed
Update for get_next_x_commit function
Signed-off-by: ziad hany <[email protected]>
1 parent fd990d2 commit 4f9b659

File tree

2 files changed

+11
-31
lines changed

2 files changed

+11
-31
lines changed

minecode_pipelines/miners/cargo.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ def process_cargo_packages(cargo_repo, fed_repo, fed_conf_repo, logger):
2929

3030
while True:
3131
setting_last_commit = get_last_commit(fed_conf_repo, "cargo")
32-
33-
if setting_last_commit is None:
34-
setting_last_commit = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
35-
36-
next_commit = get_next_x_commit(cargo_repo, setting_last_commit, x=1000, branch="master")
32+
next_commit = get_next_x_commit(cargo_repo, setting_last_commit, x=10, branch="master")
3733

3834
if next_commit == setting_last_commit:
3935
logger("No new commits to mine")

minecode_pipelines/utils.py

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,13 @@ def get_temp_file(file_name="data", extension=".file", dir_name=""):
4949
location = os.path.join(temp_dir, file_name)
5050
return location
5151

52-
53-
EMPTY_TREE_HASH = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
54-
55-
56-
def get_next_x_commit(repo: Repo, current_commit: str, x: int = 1, branch: str = "master") -> str:
57-
if x == 0:
58-
return current_commit
59-
60-
history = list(repo.iter_commits(branch))
61-
if not history:
62-
return current_commit # no commits, return current_commit
63-
64-
if not current_commit or current_commit == EMPTY_TREE_HASH:
65-
if x == 1:
66-
return history[-1].hexsha
67-
else:
68-
return history[0].hexsha
69-
70-
for i, commit in enumerate(history):
71-
if commit.hexsha == current_commit:
72-
if i + x < len(history):
73-
return history[i + x].hexsha
74-
else:
75-
return history[0].hexsha
76-
77-
return history[0].hexsha
52+
def get_next_x_commit(repo: Repo, current_commit: str, x: int = 10, branch: str = "master") -> str:
53+
"""
54+
Get the x-th next commit after the current commit in the specified branch.
55+
"""
56+
if not current_commit:
57+
current_commit = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
58+
revs = repo.git.rev_list(f"^{current_commit}", branch).splitlines()
59+
if len(revs) < x:
60+
raise ValueError(f"Not enough commits ahead; only {len(revs)} available.")
61+
return revs[-x]

0 commit comments

Comments
 (0)