Skip to content

Commit 22ae800

Browse files
committed
Update for get_next_x_commit function
Signed-off-by: ziad hany <[email protected]>
1 parent 2fb96aa commit 22ae800

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
@@ -61,29 +61,13 @@ def get_temp_file(file_name="data", extension=".file", dir_name=""):
6161
location = os.path.join(temp_dir, file_name)
6262
return location
6363

64-
65-
EMPTY_TREE_HASH = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
66-
67-
68-
def get_next_x_commit(repo: Repo, current_commit: str, x: int = 1, branch: str = "master") -> str:
69-
if x == 0:
70-
return current_commit
71-
72-
history = list(repo.iter_commits(branch))
73-
if not history:
74-
return current_commit # no commits, return current_commit
75-
76-
if not current_commit or current_commit == EMPTY_TREE_HASH:
77-
if x == 1:
78-
return history[-1].hexsha
79-
else:
80-
return history[0].hexsha
81-
82-
for i, commit in enumerate(history):
83-
if commit.hexsha == current_commit:
84-
if i + x < len(history):
85-
return history[i + x].hexsha
86-
else:
87-
return history[0].hexsha
88-
89-
return history[0].hexsha
64+
def get_next_x_commit(repo: Repo, current_commit: str, x: int = 10, branch: str = "master") -> str:
65+
"""
66+
Get the x-th next commit after the current commit in the specified branch.
67+
"""
68+
if not current_commit:
69+
current_commit = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
70+
revs = repo.git.rev_list(f"^{current_commit}", branch).splitlines()
71+
if len(revs) < x:
72+
raise ValueError(f"Not enough commits ahead; only {len(revs)} available.")
73+
return revs[-x]

0 commit comments

Comments
 (0)