⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 277220 in webkit


Ignore:
Timestamp:
May 7, 2021, 6:08:08 PM (5 years ago)
Author:
zhifei_fang@apple.com
Message:

Add support for syncing repo with commit revision label.
​https://bugs.webkit.org/show_bug.cgi?id=221982

Reviewed by Ryosuke Niwa.

Add new syncing option reportRevisionIdentifier, which will let the script try to sync the commit revision identifier from the commit message.
Add new syncing option reportSVNRevision, which will let the script try to report SVN revision from a git-svn repo.

  • tools/sync-commits.py:

(main):
(load_repository):
(GitRepository.init):
(GitRepository.fetch_next_commit):
(GitRepository._git_hash_to_svn_revision):
(GitRepository._svn_revision_to_git_hash):
(GitRepository._revision_from_tokens):
(GitRepository._fetch_all_hashes):

Location:
trunk/Websites/perf.webkit.org
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Websites/perf.webkit.org/ChangeLog

    r275993 r277220  
     12021-05-07  Zhifei Fang  <zhifei_fang@apple.com>
     2       
     3        Add support for syncing repo with commit revision label.
     4        https://bugs.webkit.org/show_bug.cgi?id=221982
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Add new syncing option reportRevisionIdentifier, which will let the script try to sync the commit revision identifier from the commit message.
     9        Add new syncing option reportSVNRevision, which will let the script try to report SVN revision from a git-svn repo.
     10
     11        * tools/sync-commits.py:
     12        (main):
     13        (load_repository):
     14        (GitRepository.__init__):
     15        (GitRepository.fetch_next_commit):
     16        (GitRepository._git_hash_to_svn_revision):
     17        (GitRepository._svn_revision_to_git_hash):
     18        (GitRepository._revision_from_tokens):
     19        (GitRepository._fetch_all_hashes):
     20
    1212021-04-14  Zhifei Fang  <zhifei_fang@apple.com>
    222
  • trunk/Websites/perf.webkit.org/tools/sync-commits.py

    r274800 r277220  
    1717from util import text_content
    1818
     19# There are some buggy commit messages:
     20# Canonical link: https://commits.webkit.org/https://commits.webkit.org/232477@main
     21REVISION_IDENTIFIER_RE = re.compile(r'Canonical link: (https\://commits\.webkit\.org/)+(?P<revision_identifier>\d+@[\w\.\-]+)\n')
    1922
    2023def main(argv):
    … …  
    4447def load_repository(repository):
    4548    if 'gitCheckout' in repository:
    46         return GitRepository(name=repository['name'], git_url=repository['url'], git_checkout=repository['gitCheckout'], git_branch=repository.get('branch'))
     49        return GitRepository(
     50            name=repository['name'], git_url=repository['url'], git_checkout=repository['gitCheckout'],
     51            git_branch=repository.get('branch'), report_revision_identifier_in_commit_msg=repository.get('reportRevisionIdentifier'),
     52            report_svn_revison=repository.get('reportSVNRevision'))
    4753    return SVNRepository(name=repository['name'], svn_url=repository['url'], should_trust_certificate=repository.get('trustCertificate', False),
    4854        use_server_auth=repository.get('useServerAuth', False), account_name_script_path=repository.get('accountNameFinderScript'))
    … …  
    193199class GitRepository(Repository):
    194200
    195     def __init__(self, name, git_checkout, git_url, git_branch=None):
     201    def __init__(self, name, git_checkout, git_url, git_branch=None, report_revision_identifier_in_commit_msg=False, report_svn_revison=False):
    196202        assert(os.path.isdir(git_checkout))
    197203        super(GitRepository, self).__init__(name)
    … …  
    200206        self._git_branch = git_branch
    201207        self._tokenized_hashes = []
     208        self._report_revision_identifier_in_commit_msg = report_revision_identifier_in_commit_msg
     209        self._report_svn_revision = report_svn_revison
    202210
    203211    def fetch_next_commit(self, server_config, last_fetched):
    … …  
    206214            tokens = self._tokenized_hashes[0]
    207215        else:
     216            if self._report_svn_revision:
     217                last_fetched_git_hash = self._git_hash_from_svn_revision(last_fetched)
     218                if not last_fetched_git_hash:
     219                    self._fetch_remote()
     220                    last_fetched_git_hash = self._git_hash_from_svn_revision(last_fetched)
     221                    if not last_fetched_git_hash:
     222                        raise ValueError('Cannot find the git hash for the last fetched svn revision')
     223                last_fetched = last_fetched_git_hash
    208224            tokens = self._find_next_hash(last_fetched)
    209225            if not tokens:
    … …  
    221237        return None
    222238
     239    def _svn_revision_from_git_hash(self, git_hash):
     240        return self._run_git_command(['svn', 'find-rev', git_hash]).strip()
     241
     242    def _git_hash_from_svn_revision(self, revision):
     243        return self._run_git_command(['svn', 'find-rev', 'r{}'.format(revision)]).strip()
     244
    223245    def _revision_from_tokens(self, tokens):
    224246        current_hash = tokens[0]
    … …  
    230252        message = self._run_git_command(['log', current_hash, '-1', '--pretty=%B'])
    231253
     254        revision_identifier = None
     255        if self._report_revision_identifier_in_commit_msg:
     256            revision_identifier_match = REVISION_IDENTIFIER_RE.search(message)
     257            if not revision_identifier_match:
     258                raise ValueError('Expected commit message to include revision identifier, but cannot find it, will need a history rewrite to fix it')
     259            revision_identifier = revision_identifier_match.group('revision_identifier')
     260
     261        current_revision = current_hash
     262        previous_revision = previous_hash
     263        if self._report_svn_revision:
     264            current_revision = self._svn_revision_from_git_hash(current_hash)
     265            if not current_revision:
     266                raise ValueError('Cannot find SVN revison for {}'.format(current_hash))
     267            if previous_hash:
     268                previous_revision = self._svn_revision_from_git_hash(previous_hash)
     269                if not previous_revision:
     270                    raise ValueError('Cannot find SVN revison for {}'.format(previous_hash))
     271
    232272        return {
    233273            'repository': self._name,
    234             'revision': current_hash,
    235             'previousCommit': previous_hash,
     274            'revision': current_revision,
     275            'revisionIdentifier': revision_identifier,
     276            'previousCommit': previous_revision,
    236277            'time': datetime.fromtimestamp(commit_time).strftime(r'%Y-%m-%dT%H:%M:%S.%f'),
    237278            'author': {'account': author_email, 'name': author_name},
    … …  
    245286        return None
    246287
     288    def _fetch_remote(self):
     289        self._run_git_command(['pull', self._git_url])
     290        if self._report_svn_revision:
     291            self._run_git_command(['svn', 'fetch'])
     292
    247293    def _fetch_all_hashes(self):
    248         self._run_git_command(['pull', self._git_url])
     294        self._fetch_remote()
    249295        scope = self._git_branch or '--all'
    250296        lines = self._run_git_command(['log', scope, '--date-order', '--reverse', '--pretty=%H %ct %ce %P']).split('\n')
Note: See TracChangeset for help on using the changeset viewer.