Changeset 276856 in webkit
- Timestamp:
- Apr 30, 2021, 3:24:13 PM (4 years ago)
- Location:
- trunk/Tools
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r276853 r276856 1 2021-04-30 Jonathan Bedard <jbedard@apple.com> 2 3 [webkitcmpy] Better document inner-workings of identifier generation 4 https://bugs.webkit.org/show_bug.cgi?id=225241 5 6 Reviewed by Dewei Zhu. 7 8 * Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py: 9 (Git.commit): 10 (Git.find): 11 * Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py: 12 (Svn.commit): 13 * Scripts/libraries/webkitscmpy/webkitscmpy/remote/bitbucket.py: 14 (BitBucket.commit): 15 * Scripts/libraries/webkitscmpy/webkitscmpy/remote/git_hub.py: 16 (GitHub.commit): 17 1 18 2021-04-30 Wenson Hsieh <wenson_hsieh@apple.com> 2 19 -
trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py
r275353 r276856 152 152 153 153 def commit(self, hash=None, revision=None, identifier=None, branch=None, tag=None, include_log=True, include_identifier=True): 154 # Only git-svn checkouts can convert revisions to fully qualified commits 154 155 if revision and not self.is_svn: 155 156 raise self.Exception('This git checkout does not support SVN revisions') 157 158 # Determine the hash for a provided Subversion revision 156 159 elif revision: 157 160 if hash: … … 174 177 log_format = ['-1'] if include_log else ['-1', '--format=short'] 175 178 179 # Determine the `git log` output and branch for a given identifier 176 180 if identifier is not None: 177 181 if revision: … … 219 223 identifier = None 220 224 225 # Determine the `git log` output for a given branch or tag 221 226 elif branch or tag: 222 227 if hash: … … 229 234 raise self.Exception("Failed to retrieve commit information for '{}'".format(branch or tag)) 230 235 236 # Determine the `git log` output for a given hash 231 237 else: 232 238 hash = Commit._parse_hash(hash, do_assert=True) … … 235 241 raise self.Exception("Failed to retrieve commit information for '{}'".format(hash or 'HEAD')) 236 242 243 # Fully define the hash from the `git log` output 237 244 match = self.GIT_COMMIT.match(log.stdout.splitlines()[0]) 238 245 if not match: … … 240 247 hash = match.group('hash') 241 248 249 # A commit is often on multiple branches, the canonical branch is the one with the highest priority 242 250 branch = self.prioritize_branches(self._branches_for(hash)) 243 251 252 # Compute the identifier if the function did not receive one and we were asked to 244 253 if not identifier and include_identifier: 245 254 identifier = self._commit_count(hash if branch == default_branch else '{}..{}'.format(default_branch, hash)) 255 256 # Only compute the branch point we're on something other than the default branch 246 257 branch_point = None if not include_identifier or branch == default_branch else self._commit_count(hash) - identifier 247 258 if branch_point and parsed_branch_point and branch_point != parsed_branch_point: 248 259 raise ValueError("Provided 'branch_point' does not match branch point of specified branch") 249 260 261 # Check the commit log for a git-svn revision 250 262 logcontent = '\n'.join(line[4:] for line in log.stdout.splitlines()[4:]) 251 263 matches = self.GIT_SVN_REVISION.findall(logcontent) 252 264 revision = int(matches[-1].split('@')[0]) if matches else None 253 265 266 # We only care about when a commit was commited 254 267 commit_time = run( 255 268 [self.executable(), 'show', '-s', '--format=%ct', hash], … … 260 273 timestamp = int(commit_time.stdout.lstrip()) 261 274 275 # Comparing commits in different repositories involves comparing timestamps. This is problematic because it git, 276 # it's possible for a series of commits to share a commit time. To handle this case, we assign each commit a 277 # zero-indexed "order" within it's timestamp. 262 278 order = 0 263 279 while not identifier or order + 1 < identifier + (branch_point or 0): … … 289 305 raise ValueError("Expected 'argument' to be a string, not '{}'".format(type(argument))) 290 306 307 # Map any candidate default branch to the one used by this repository 291 308 if argument in self.DEFAULT_BRANCHES: 292 309 argument = self.default_branch 293 310 311 # See if the argument the user specified is a recognized commit format 294 312 parsed_commit = Commit.parse(argument, do_assert=False) 295 313 if parsed_commit: … … 306 324 ) 307 325 326 # The argument isn't a recognized commit format, hopefully it is a valid git ref of some form 308 327 output = run( 309 328 [self.executable(), 'rev-parse', argument], -
trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py
r275635 r276856 270 270 raise ValueError('SVN does not support Git hashes') 271 271 272 # Determine commit info, revision and branch for a given identifier 272 273 parsed_branch_point = None 273 274 if identifier is not None: … … 291 292 raise self.Exception('Cannot provide a branch point for a commit on the default branch') 292 293 294 # Populate mapping of revisions on their respective branches if we don't have enough revisions on the 295 # branch specified by the provided identifier 293 296 if not self._metadata_cache.get(branch, []) or identifier >= len(self._metadata_cache.get(branch, [])): 294 297 if branch != self.default_branch: … … 313 316 self._cache_revisions(branch=branch) 314 317 318 # Determine the commit info and branch for a given revision 315 319 elif revision: 316 320 if branch: … … 322 326 info = self.info(cached=True, revision=revision) 323 327 328 # Determine the commit info, revision and branch for a tag or branch. 324 329 else: 325 330 if branch and tag: … … 337 342 branch = self._branch_for(revision) 338 343 344 # Extract the commit time from the commit info 339 345 date = info['Last Changed Date'].split(' (')[0] if info.get('Last Changed Date') else None 340 346 if date: … … 346 352 ) * (1 if tz_diff[0] == '-' else -1) 347 353 354 # Compute the identifier if the function did not receive one and we were asked to 348 355 if include_identifier and not identifier: 349 356 if branch != self.default_branch and revision > self._metadata_cache.get(self.default_branch, [0])[-1]: … … 357 364 raise ValueError("Provided 'branch_point' does not match branch point of specified branch") 358 365 366 # Determine the commit message for a commit. Note that in Subversion, this will always result in a network call 367 # and is one of the major reasons the WebKit project uses ChangeLogs. 359 368 if branch == self.default_branch or '/' in branch: 360 369 branch_arg = '^/{}'.format(branch) 361 370 else: 362 371 branch_arg = '^/branches/{}'.format(branch) 363 364 372 log = run( 365 373 [self.executable(), 'log', '-l', '1', '-r', str(revision), branch_arg], cwd=self.root_path, -
trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/bitbucket.py
r274080 r276856 146 146 raise self.Exception('Cannot map revisions to commits on BitBucket') 147 147 148 # Determine the commit data and branch for a given identifier 148 149 if identifier is not None: 149 150 if revision: … … 195 196 identifier = None 196 197 198 # Determine the commit data for a given branch or tag 197 199 elif branch or tag: 198 200 if hash: … … 204 206 raise self.Exception("Failed to retrieve commit information for '{}'".format(branch or tag)) 205 207 208 # Determine the commit data for a given hash 206 209 else: 207 210 hash = Commit._parse_hash(hash, do_assert=True) … … 210 213 raise self.Exception("Failed to retrieve commit information for '{}'".format(hash or 'HEAD')) 211 214 215 # A commit is often on multiple branches, the canonical branch is the one with the highest priority 212 216 branches = self._branches_for(commit_data['id']) 213 217 if branches: 214 218 branch = self.prioritize_branches(branches) 215 216 219 else: 217 220 # A commit not on any branches cannot have an identifier … … 219 222 branch = None 220 223 224 # Define identifiers on default branch 221 225 branch_point = None 222 226 if include_identifier and branch and branch == self.default_branch: … … 224 228 identifier = self._distance(commit_data['id']) 225 229 230 # Define identifiers on branches diverged from the default branch 226 231 elif include_identifier and branch: 227 232 if not identifier: … … 229 234 branch_point = self._distance(commit_data['id']) - identifier 230 235 236 # Check the commit log for a git-svn revision 231 237 matches = self.GIT_SVN_REVISION.findall(commit_data['message']) 232 238 revision = int(matches[-1].split('@')[0]) if matches else None 233 239 240 # Comparing commits in different repositories involves comparing timestamps. This is problematic because it git, 241 # it's possible for a series of commits to share a commit time. To handle this case, we assign each commit a 242 # zero-indexed "order" within it's timestamp. 234 243 timestamp = int(commit_data['committerTimestamp'] / 1000) 235 244 order = 0 -
trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/git_hub.py
r274080 r276856 188 188 raise self.Exception('Cannot map revisions to commits on GitHub') 189 189 190 # Determine the commit data and branch for a given identifier 190 191 if identifier is not None: 191 192 if revision: … … 233 234 identifier = None 234 235 236 # Determine the commit data for a given branch or tag 235 237 elif branch or tag: 236 238 if hash: … … 242 244 raise self.Exception("Failed to retrieve commit information for '{}'".format(branch or tag)) 243 245 246 # Determine the commit data for a given hash 244 247 else: 245 248 hash = Commit._parse_hash(hash, do_assert=True) … … 248 251 raise self.Exception("Failed to retrieve commit information for '{}'".format(hash or 'HEAD')) 249 252 253 # A commit is often on multiple branches, the canonical branch is the one with the highest priority 250 254 branches = self._branches_for(commit_data['sha']) 251 255 if branches: 252 256 branch = self.prioritize_branches(branches) 253 254 257 else: 255 258 # A commit not on any branches cannot have an identifier … … 257 260 branch = None 258 261 262 # Define identifiers on default branch 259 263 branch_point = None 260 264 if include_identifier and branch and branch == self.default_branch: … … 265 269 identifier, _ = result 266 270 271 # Define identifiers on branches diverged from the default branch 267 272 elif include_identifier and branch: 268 273 if not identifier: … … 270 275 branch_point = self._count_for_ref(ref=commit_data['sha'])[0] - identifier 271 276 277 # Check the commit log for a git-svn revision 272 278 matches = self.GIT_SVN_REVISION.findall(commit_data['commit']['message']) 273 279 revision = int(matches[-1].split('@')[0]) if matches else None … … 278 284 ).timetuple())) 279 285 286 # Comparing commits in different repositories involves comparing timestamps. This is problematic because it git, 287 # it's possible for a series of commits to share a commit time. To handle this case, we assign each commit a 288 # zero-indexed "order" within it's timestamp. 280 289 order = 0 281 290 while not identifier or order + 1 < identifier + (branch_point or 0):
Note:
See TracChangeset
for help on using the changeset viewer.