MCPcopy Create free account
hub / github.com/BillHuang2001/evogit / get_initial_branches

Function get_initial_branches

python-impl/evogit/api.py:57–91  ·  view source on GitHub ↗

Get the initial branches with a simple strategy. 1. Try to load the existing branches from the local repository. Existing branches are the branches that are already created from previous runs. This implies that we will try to restore from the previous state. 2. If not enough,

(config: EvoGitConfig, pop_size: int)

Source from the content-addressed store, hash-verified

55
56
57def get_initial_branches(config: EvoGitConfig, pop_size: int) -> list[str]:
58 """Get the initial branches with a simple strategy.
59 1. Try to load the existing branches from the local repository.
60 Existing branches are the branches that are already created from previous runs.
61 This implies that we will try to restore from the previous state.
62 2. If not enough, try to load the branches from the remote repository.
63 Normally this happens when a new node joins the evolution.
64 So it tries to kickstart the evolution by loading the branches from the remote.
65 3. If still not enough, create new branches from the current head.
66 """
67 if config.clean_start:
68 # If clean start, start from main branch
69 print("Clean start, start from main branch")
70 main_commit_id = git.get_commit_by_branch(config, "main")
71 pop = [main_commit_id for _ in range(pop_size)]
72 return pop
73
74 # Try to load the branches from the local repository
75 branches = git.list_branches(config)
76 pop = branches[:pop_size]
77 pop = [git.get_commit_by_branch(config, branch) for branch in pop]
78
79 # If not enough, try to load the branches from the remote repository
80 if len(pop) < pop_size:
81 remote_branches = git.list_branches(config, list_remote=True)
82 remote_pop = remote_branches[: pop_size - len(pop)]
83 remote_pop = [git.get_commit_by_branch(config, branch) for branch in remote_pop]
84 pop.extend(remote_pop)
85
86 # If still not enough, create new branches from the current head
87 while len(pop) < pop_size:
88 head = git.read_head_commit(config)
89 pop.append(head)
90
91 return pop
92
93
94def push_local_branches(

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected