Skip to content

Commit a5cb0b8

Browse files
committed
Fixing commit math, and git svn bug
1 parent 73519d5 commit a5cb0b8

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed

src/source_repo/svn.py

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ def convert(ctx: Context) -> None:
3636

3737
repo_key = ctx.job.get("config",{}).get("repo_key")
3838

39+
# ctx.job["result"]["process"]["pid"] = os.getpid()
40+
# ctx.job["result"]["process"]["ppid"] = os.getppid()
41+
# ctx.job["result"]["process"]["pgrp"] = os.getpgrp()
42+
3943
# Extract repo conversion job config values from the repos list in ctx,
4044
# and set default values for required but undefined configs
4145
_extract_repo_config_and_set_default_values(ctx)
@@ -190,7 +194,7 @@ def _build_cli_commands(ctx: Context) -> dict:
190194
# git commands
191195
cmd_git_default_branch = arg_git + ["symbolic-ref", "HEAD", f"refs/heads/{git_default_branch}"]
192196
cmd_git_garbage_collection = arg_git + ["gc"]
193-
cmd_git_svn_fetch = arg_git_svn + ["fetch", "--quiet", "--quiet"]
197+
cmd_git_svn_fetch = arg_git_svn + ["fetch", "--quiet"]
194198
cmd_git_svn_init = arg_git_svn + ["init"] + arg_svn_remote_repo_code_root_url
195199

196200
# Add authentication, if provided
@@ -800,7 +804,7 @@ def _git_svn_fetch(ctx: Context, commands: dict) -> bool:
800804
retry_delay_seconds = (random.randrange(1, 5) * retries_attempted)
801805

802806
# Log the failure
803-
log(ctx, f"{repo_key}; git svn fetch failed, retrying {retries_attempted} of max {max_retries} times, with a semi-random delay of {retry_delay_seconds} seconds", "debug")
807+
log(ctx, f"{repo_key}; retrying {retries_attempted} of max {max_retries} times, with a semi-random delay of {retry_delay_seconds} seconds", "debug")
804808

805809
# Sleep the delay
806810
time.sleep(retry_delay_seconds)
@@ -836,7 +840,7 @@ def _check_git_svn_fetch_success(ctx: Context, git_svn_fetch_result: dict) -> bo
836840

837841

838842
## Gather needed inputs
839-
job_stats_local_git_repo_stats = _get_local_git_repo_stats(ctx)
843+
current_job_stats_local_git_repo_stats = _get_local_git_repo_stats(ctx)
840844

841845
job_config = ctx.job.get("config",{})
842846
max_retries = job_config.get("max_retries")
@@ -977,19 +981,22 @@ def _check_git_svn_fetch_success(ctx: Context, git_svn_fetch_result: dict) -> bo
977981
# warnings.append(f"git_latest_commit_rev_end: {latest_converted_svn_rev} != rev_batch_end: {rev_batch_end}")
978982

979983
## Commit count checks
984+
job_stats_local = ctx.job.get("stats",{}).get("local",{})
980985

981986
# Get the number of commits which were already in the local git repo before the job started
982-
git_commit_count_begin = job_stats_local_git_repo_stats.get("git_commit_count_begin", 0)
987+
git_commit_count_begin = job_stats_local.get("git_commit_count_begin")
983988

984989
# Get the current number of commits in the local git repo after this fetch attempt (includes all retries)
985-
current_git_commit_count = job_stats_local_git_repo_stats.get("git_commit_count", 0)
990+
current_git_commit_count = current_job_stats_local_git_repo_stats.get("git_commit_count")
991+
986992

987993

988994
## This try commit counts
989995
# Order is important, must be before ## Whole job commit counts,
990996
# because this tries to use the git_commit_count_added_whole_job from the previous retry
991997
# Get the count of commits from the end of the previous try
992-
git_commit_count_after_previous_try = job_stats_local_git_repo_stats.get("git_commit_count_added_whole_job")
998+
git_commit_count_after_previous_try = job_stats_local.get("git_commit_count_added_whole_job")
999+
9931000
# If this is the first try, then use the commit count from the beginning of the job
9941001
if not git_commit_count_after_previous_try:
9951002
git_commit_count_after_previous_try = git_commit_count_begin
@@ -1014,38 +1021,54 @@ def _check_git_svn_fetch_success(ctx: Context, git_svn_fetch_result: dict) -> bo
10141021

10151022

10161023
## Add git_dir_size_
1017-
git_dir_size = job_stats_local_git_repo_stats.get("git_dir_size")
1024+
git_dir_size = current_job_stats_local_git_repo_stats.get("git_dir_size")
10181025
if git_dir_size:
10191026
ctx.job["stats"]["local"].update({f"git_dir_size_try_{retries_attempted}": git_dir_size})
10201027

10211028

10221029
# Check if git svn has blown past svn info's "Last Changed Rev"
1023-
# Only a problem when the repo has 0 commits
1024-
branches_max_rev = job_stats_local_git_repo_stats.get("svn_metadata_branches_max_rev", 0)
1025-
last_changed_revision = ctx.job.get("stats",{}).get("remote",{}).get("last_changed_revision")
1030+
branches_max_rev = current_job_stats_local_git_repo_stats.get("svn_metadata_branches_max_rev", 0)
1031+
last_changed_revision = ctx.job.get("stats",{}).get("remote",{}).get("last_changed_revision")
1032+
git_latest_commit_rev = current_job_stats_local_git_repo_stats.get("git_latest_commit_rev", 0)
10261033

10271034
if (
1028-
current_git_commit_count == 0 and
1029-
branches_max_rev > last_changed_revision
1035+
branches_max_rev > last_changed_revision and
1036+
current_git_commit_count == 0
10301037
):
10311038

10321039
# If git svn has blown past svn info's "Last Changed Rev"
1033-
log(ctx, f"{repo_key}; Repo is empty, and branches_max_rev {branches_max_rev} > last_changed_revision {last_changed_revision}, unsetting svn-remote.svn.branches-maxRev and svn-remote.svn.tags-maxRev to remediate", "warning")
1040+
errors.append(f"{repo_key}; Repo is empty, and branches_max_rev {branches_max_rev} > last_changed_revision {last_changed_revision}, unsetting svn-remote.svn.branches-maxRev and svn-remote.svn.tags-maxRev to remediate")
10341041

10351042
# Remediate the situation
10361043
# NOTE: This causes this run of the git svn fetch command to start back from svn repo revision 1,
10371044
# which may take a long time
10381045
git.set_config(ctx, "svn-remote.svn.branches-maxRev", "0", config_file_path=".git/svn/.metadata")
10391046
git.set_config(ctx, "svn-remote.svn.tags-maxRev", "0", config_file_path=".git/svn/.metadata")
10401047

1048+
# If the repo is out of date,
1049+
# and branches_max_rev is higher than the last changed rev that we're trying to sync
1050+
# this repo will always be out of date, unless we can back up branches_max_rev to let us sync
1051+
# the last changed rev
1052+
if (
1053+
branches_max_rev > last_changed_revision and
1054+
last_changed_revision > git_latest_commit_rev
1055+
):
1056+
# branches_max_rev_setback = last_changed_revision - 1
1057+
# errors.append(f"{repo_key}; branches_max_rev {branches_max_rev} > last_changed_revision {last_changed_revision} > git_latest_commit_rev {git_latest_commit_rev}, meaning this repo would never catch up; trying to remediate by resetting branches_max_rev to git_latest_commit_rev {git_latest_commit_rev}")
1058+
# git.set_config(ctx, "svn-remote.svn.branches-maxRev", f"{branches_max_rev_setback}", config_file_path=".git/svn/.metadata")
1059+
# git.set_config(ctx, "svn-remote.svn.tags-maxRev", f"{branches_max_rev_setback}", config_file_path=".git/svn/.metadata")
1060+
errors.append(f"{repo_key}; branches_max_rev {branches_max_rev} > last_changed_revision {last_changed_revision} > git_latest_commit_rev {git_latest_commit_rev}, meaning this repo would never catch up; unsetting svn-remote.svn.branches-maxRev and svn-remote.svn.tags-maxRev to remediate")
1061+
git.set_config(ctx, "svn-remote.svn.branches-maxRev", "0", config_file_path=".git/svn/.metadata")
1062+
git.set_config(ctx, "svn-remote.svn.tags-maxRev", "0", config_file_path=".git/svn/.metadata")
1063+
10411064

10421065
# Assign the lists to the job result data for log output
10431066
if errors:
10441067
ctx.job["result"]["errors"] = errors
10451068
if warnings:
10461069
ctx.job["result"]["warnings"] = warnings
10471070
action = "git svn fetch"
1048-
reason = f"{repo_key}; "
1071+
reason = ""
10491072
structured_log_dict = {"process": git_svn_fetch_result}
10501073

10511074
## Make final success / fail call

src/utils/git.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,12 @@ def get_count_of_commits_in_repo(ctx: Context) -> int:
212212
cmd_git_count_commits_result = cmd.run_subprocess(ctx, cmd_git_count_commits, quiet=True, name="cmd_git_count_commits", ignore_stderr=True)
213213

214214
if cmd_git_count_commits_result["return_code"] == 0:
215-
216215
count_commits = ''.join(cmd_git_count_commits_result["output"]) if isinstance(cmd_git_count_commits_result["output"], list) else cmd_git_count_commits_result["output"]
217-
return int(count_commits)
218216

219-
else:
220-
return None
217+
if count_commits:
218+
return int(count_commits)
219+
220+
return None
221221

222222

223223
def deduplicate_git_config_file(ctx: Context) -> None:

0 commit comments

Comments
 (0)