(localRefPrefix="refs/remotes/p4/", silent=True)
| 1214 | |
| 1215 | |
| 1216 | def createOrUpdateBranchesFromOrigin(localRefPrefix="refs/remotes/p4/", silent=True): |
| 1217 | if not silent: |
| 1218 | print("Creating/updating branch(es) in %s based on origin branch(es)" |
| 1219 | % localRefPrefix) |
| 1220 | |
| 1221 | originPrefix = "origin/p4/" |
| 1222 | |
| 1223 | for line in read_pipe_lines(["git", "rev-parse", "--symbolic", "--remotes"]): |
| 1224 | line = line.strip() |
| 1225 | if (not line.startswith(originPrefix)) or line.endswith("HEAD"): |
| 1226 | continue |
| 1227 | |
| 1228 | headName = line[len(originPrefix):] |
| 1229 | remoteHead = localRefPrefix + headName |
| 1230 | originHead = line |
| 1231 | |
| 1232 | original = extractSettingsGitLog(extractLogMessageFromGitCommit(originHead)) |
| 1233 | if 'depot-paths' not in original or 'change' not in original: |
| 1234 | continue |
| 1235 | |
| 1236 | update = False |
| 1237 | if not gitBranchExists(remoteHead): |
| 1238 | if verbose: |
| 1239 | print("creating %s" % remoteHead) |
| 1240 | update = True |
| 1241 | else: |
| 1242 | settings = extractSettingsGitLog(extractLogMessageFromGitCommit(remoteHead)) |
| 1243 | if 'change' in settings: |
| 1244 | if settings['depot-paths'] == original['depot-paths']: |
| 1245 | originP4Change = int(original['change']) |
| 1246 | p4Change = int(settings['change']) |
| 1247 | if originP4Change > p4Change: |
| 1248 | print("%s (%s) is newer than %s (%s). " |
| 1249 | "Updating p4 branch from origin." |
| 1250 | % (originHead, originP4Change, |
| 1251 | remoteHead, p4Change)) |
| 1252 | update = True |
| 1253 | else: |
| 1254 | print("Ignoring: %s was imported from %s while " |
| 1255 | "%s was imported from %s" |
| 1256 | % (originHead, ','.join(original['depot-paths']), |
| 1257 | remoteHead, ','.join(settings['depot-paths']))) |
| 1258 | |
| 1259 | if update: |
| 1260 | system(["git", "update-ref", remoteHead, originHead]) |
| 1261 | |
| 1262 | |
| 1263 | def originP4BranchesExist(): |
no test coverage detected