MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / checkout_cppcheck_version

Function checkout_cppcheck_version

tools/donate_cpu_lib.py:122–155  ·  view source on GitHub ↗
(repo_path, version, cppcheck_path)

Source from the content-addressed store, hash-verified

120
121
122def checkout_cppcheck_version(repo_path, version, cppcheck_path):
123 if not os.path.isabs(cppcheck_path):
124 raise ValueError("cppcheck_path is not an absolute path")
125 if os.path.exists(cppcheck_path):
126 print('Checking out {}'.format(version))
127 subprocess.check_call(['git', 'checkout', '-f', version], cwd=cppcheck_path)
128
129 # It is possible to pull branches, not tags
130 if version != 'main':
131 return False
132
133 hash_old = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], cwd=cppcheck_path).strip()
134
135 print('Pulling {}'.format(version))
136 # --rebase is a workaround for a dropped commit - see https://github.com/cppcheck-opensource/cppcheck/pull/6904
137 # TODO: drop the commit in question
138 # TOD: remove --rebase
139 subprocess.check_call(['git', 'pull', '--rebase'], cwd=cppcheck_path)
140
141 hash_new = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'], cwd=cppcheck_path).strip()
142
143 has_changes = hash_old != hash_new
144 if not has_changes:
145 print('No changes detected')
146 return has_changes
147
148 if version != 'main':
149 print('Fetching {}'.format(version))
150 # Since this is a shallow clone, explicitly fetch the remote version tag
151 refspec = 'refs/tags/' + version + ':ref/tags/' + version
152 subprocess.check_call(['git', 'fetch', '--depth=1', 'origin', refspec], cwd=repo_path)
153 print('Adding worktree \'{}\' for {}'.format(cppcheck_path, version))
154 subprocess.check_call(['git', 'worktree', 'add', cppcheck_path, version], cwd=repo_path)
155 return True
156
157
158def get_cppcheck_info(cppcheck_path):

Callers

nothing calls this directly

Calls 2

formatMethod · 0.80
existsMethod · 0.45

Tested by

no test coverage detected