Changeset 276856 in webkit


Ignore:
Timestamp:
Apr 30, 2021, 3:24:13 PM (4 years ago)
Author:
Jonathan Bedard
Message:

[webkitcmpy] Better document inner-workings of identifier generation
https://bugs.webkit.org/show_bug.cgi?id=225241

Reviewed by Dewei Zhu.

  • Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py:

(Git.commit):
(Git.find):

  • Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py:

(Svn.commit):

  • Scripts/libraries/webkitscmpy/webkitscmpy/remote/bitbucket.py:

(BitBucket.commit):

  • Scripts/libraries/webkitscmpy/webkitscmpy/remote/git_hub.py:

(GitHub.commit):

Location:
trunk/Tools
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r276853 r276856  
     12021-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
    1182021-04-30  Wenson Hsieh  <wenson_hsieh@apple.com>
    219
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/git.py

    r275353 r276856  
    152152
    153153    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
    154155        if revision and not self.is_svn:
    155156            raise self.Exception('This git checkout does not support SVN revisions')
     157
     158        # Determine the hash for a provided Subversion revision
    156159        elif revision:
    157160            if hash:
     
    174177        log_format = ['-1'] if include_log else ['-1', '--format=short']
    175178
     179        # Determine the `git log` output and branch for a given identifier
    176180        if identifier is not None:
    177181            if revision:
     
    219223                identifier = None
    220224
     225        # Determine the `git log` output for a given branch or tag
    221226        elif branch or tag:
    222227            if hash:
     
    229234                raise self.Exception("Failed to retrieve commit information for '{}'".format(branch or tag))
    230235
     236        # Determine the `git log` output for a given hash
    231237        else:
    232238            hash = Commit._parse_hash(hash, do_assert=True)
     
    235241                raise self.Exception("Failed to retrieve commit information for '{}'".format(hash or 'HEAD'))
    236242
     243        # Fully define the hash from the `git log` output
    237244        match = self.GIT_COMMIT.match(log.stdout.splitlines()[0])
    238245        if not match:
     
    240247        hash = match.group('hash')
    241248
     249        # A commit is often on multiple branches, the canonical branch is the one with the highest priority
    242250        branch = self.prioritize_branches(self._branches_for(hash))
    243251
     252        # Compute the identifier if the function did not receive one and we were asked to
    244253        if not identifier and include_identifier:
    245254            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
    246257        branch_point = None if not include_identifier or branch == default_branch else self._commit_count(hash) - identifier
    247258        if branch_point and parsed_branch_point and branch_point != parsed_branch_point:
    248259            raise ValueError("Provided 'branch_point' does not match branch point of specified branch")
    249260
     261        # Check the commit log for a git-svn revision
    250262        logcontent = '\n'.join(line[4:] for line in log.stdout.splitlines()[4:])
    251263        matches = self.GIT_SVN_REVISION.findall(logcontent)
    252264        revision = int(matches[-1].split('@')[0]) if matches else None
    253265
     266        # We only care about when a commit was commited
    254267        commit_time = run(
    255268            [self.executable(), 'show', '-s', '--format=%ct', hash],
     
    260273        timestamp = int(commit_time.stdout.lstrip())
    261274
     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.
    262278        order = 0
    263279        while not identifier or order + 1 < identifier + (branch_point or 0):
     
    289305            raise ValueError("Expected 'argument' to be a string, not '{}'".format(type(argument)))
    290306
     307        # Map any candidate default branch to the one used by this repository
    291308        if argument in self.DEFAULT_BRANCHES:
    292309            argument = self.default_branch
    293310
     311        # See if the argument the user specified is a recognized commit format
    294312        parsed_commit = Commit.parse(argument, do_assert=False)
    295313        if parsed_commit:
     
    306324            )
    307325
     326        # The argument isn't a recognized commit format, hopefully it is a valid git ref of some form
    308327        output = run(
    309328            [self.executable(), 'rev-parse', argument],
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/local/svn.py

    r275635 r276856  
    270270            raise ValueError('SVN does not support Git hashes')
    271271
     272        # Determine commit info, revision and branch for a given identifier
    272273        parsed_branch_point = None
    273274        if identifier is not None:
     
    291292                raise self.Exception('Cannot provide a branch point for a commit on the default branch')
    292293
     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
    293296            if not self._metadata_cache.get(branch, []) or identifier >= len(self._metadata_cache.get(branch, [])):
    294297                if branch != self.default_branch:
     
    313316                self._cache_revisions(branch=branch)
    314317
     318        # Determine the commit info and branch for a given revision
    315319        elif revision:
    316320            if branch:
     
    322326            info = self.info(cached=True, revision=revision)
    323327
     328        # Determine the commit info, revision and branch for a tag or branch.
    324329        else:
    325330            if branch and tag:
     
    337342                branch = self._branch_for(revision)
    338343
     344        # Extract the commit time from the commit info
    339345        date = info['Last Changed Date'].split(' (')[0] if info.get('Last Changed Date') else None
    340346        if date:
     
    346352            ) * (1 if tz_diff[0] == '-' else -1)
    347353
     354        # Compute the identifier if the function did not receive one and we were asked to
    348355        if include_identifier and not identifier:
    349356            if branch != self.default_branch and revision > self._metadata_cache.get(self.default_branch, [0])[-1]:
     
    357364            raise ValueError("Provided 'branch_point' does not match branch point of specified branch")
    358365
     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.
    359368        if branch == self.default_branch or '/' in branch:
    360369            branch_arg = '^/{}'.format(branch)
    361370        else:
    362371            branch_arg = '^/branches/{}'.format(branch)
    363 
    364372        log = run(
    365373            [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  
    146146            raise self.Exception('Cannot map revisions to commits on BitBucket')
    147147
     148        # Determine the commit data and branch for a given identifier
    148149        if identifier is not None:
    149150            if revision:
     
    195196                identifier = None
    196197
     198        # Determine the commit data for a given branch or tag
    197199        elif branch or tag:
    198200            if hash:
     
    204206                raise self.Exception("Failed to retrieve commit information for '{}'".format(branch or tag))
    205207
     208        # Determine the commit data for a given hash
    206209        else:
    207210            hash = Commit._parse_hash(hash, do_assert=True)
     
    210213                raise self.Exception("Failed to retrieve commit information for '{}'".format(hash or 'HEAD'))
    211214
     215        # A commit is often on multiple branches, the canonical branch is the one with the highest priority
    212216        branches = self._branches_for(commit_data['id'])
    213217        if branches:
    214218            branch = self.prioritize_branches(branches)
    215 
    216219        else:
    217220            # A commit not on any branches cannot have an identifier
     
    219222            branch = None
    220223
     224        # Define identifiers on default branch
    221225        branch_point = None
    222226        if include_identifier and branch and branch == self.default_branch:
     
    224228                identifier = self._distance(commit_data['id'])
    225229
     230        # Define identifiers on branches diverged from the default branch
    226231        elif include_identifier and branch:
    227232            if not identifier:
     
    229234            branch_point = self._distance(commit_data['id']) - identifier
    230235
     236        # Check the commit log for a git-svn revision
    231237        matches = self.GIT_SVN_REVISION.findall(commit_data['message'])
    232238        revision = int(matches[-1].split('@')[0]) if matches else None
    233239
     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.
    234243        timestamp = int(commit_data['committerTimestamp'] / 1000)
    235244        order = 0
  • trunk/Tools/Scripts/libraries/webkitscmpy/webkitscmpy/remote/git_hub.py

    r274080 r276856  
    188188            raise self.Exception('Cannot map revisions to commits on GitHub')
    189189
     190        # Determine the commit data and branch for a given identifier
    190191        if identifier is not None:
    191192            if revision:
     
    233234                identifier = None
    234235
     236        # Determine the commit data for a given branch or tag
    235237        elif branch or tag:
    236238            if hash:
     
    242244                raise self.Exception("Failed to retrieve commit information for '{}'".format(branch or tag))
    243245
     246        # Determine the commit data for a given hash
    244247        else:
    245248            hash = Commit._parse_hash(hash, do_assert=True)
     
    248251                raise self.Exception("Failed to retrieve commit information for '{}'".format(hash or 'HEAD'))
    249252
     253        # A commit is often on multiple branches, the canonical branch is the one with the highest priority
    250254        branches = self._branches_for(commit_data['sha'])
    251255        if branches:
    252256            branch = self.prioritize_branches(branches)
    253 
    254257        else:
    255258            # A commit not on any branches cannot have an identifier
     
    257260            branch = None
    258261
     262        # Define identifiers on default branch
    259263        branch_point = None
    260264        if include_identifier and branch and branch == self.default_branch:
     
    265269                identifier, _ = result
    266270
     271        # Define identifiers on branches diverged from the default branch
    267272        elif include_identifier and branch:
    268273            if not identifier:
     
    270275            branch_point = self._count_for_ref(ref=commit_data['sha'])[0] - identifier
    271276
     277        # Check the commit log for a git-svn revision
    272278        matches = self.GIT_SVN_REVISION.findall(commit_data['commit']['message'])
    273279        revision = int(matches[-1].split('@')[0]) if matches else None
     
    278284        ).timetuple()))
    279285
     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.
    280289        order = 0
    281290        while not identifier or order + 1 < identifier + (branch_point or 0):
Note: See TracChangeset for help on using the changeset viewer.