Changeset 45654 in webkit


Ignore:
Timestamp:
Jul 8, 2009 6:25:00 PM (15 years ago)
Author:
ddkilzer@apple.com
Message:

Bug 27062: bugzilla-tool: post-commits should read bug id from commit log and actually work

<https://bugs.webkit.org/show_bug.cgi?id=27062>

Reviewed by Eric Seidel.

Removed the required BUGID argument from the "post-commits"

command and replaced it with a -bbug-id switch or parsing the

commit log message for the bug URL. Fixed a bug in the
"post-commits" that would ignore the COMMITISH used and post a
patch of local changes against HEAD. Added --no-commit switch
to disable using the bulk of the ChangeLog entry as the comment
for the new patch.

  • Scripts/bugzilla-tool: (bug_id_from_commit_message): Added. Returns a bug id from the commit log message, thus enforcing the need for a bug URL in the message. (PostCommitsAsPatchesToBug.init): Updated help description to match new behavior of pulling bug ids from commit log
messages instead of from the command line. Added -bbug-id

switch and --no-comment switch.
(PostCommitsAsPatchesToBug.execute): Updated to use
bug_id_from_commit_message() to pull bug ids from commit log
messages. Also switched from SCM.create_patch() to use
SCM.create_patch_from_local_commit() to fix a bug where local
repository changes were posted as a patch instead of the

specific COMMITISH. Fall back to -bbug-id if no URL is found

in the commit log message. Don't specify a comment for the
patch if --no-comment is used. Set cherry_pick argument to True
for Git.commit_ids_from_range_arguments() since we don't want
implicit commit range behavior for this command.

  • Scripts/modules/bugzilla.py: Import datetime module. (timestamp): Added. Returns a timestamp in the form of "YYYYMMDDhhmmss". (Bugzilla.bug_server_regex): Added static attribute. (Bugzilla.add_patch_to_bug): Construct a more meaningful patch file name using the bug_id and timestamp().
  • Scripts/modules/scm.py: (SCM.create_patch_from_local_commit): Added. (Git.create_patch_from_local_commit): Added. Runs "git diff" to return a patch for the given commit_id.
Location:
trunk/WebKitTools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKitTools/ChangeLog

    r45647 r45654  
     12009-07-08  David Kilzer  <ddkilzer@apple.com>
     2
     3        Bug 27062: bugzilla-tool: post-commits should read bug id from commit log and actually work
     4
     5        <https://bugs.webkit.org/show_bug.cgi?id=27062>
     6
     7        Reviewed by Eric Seidel.
     8
     9        Removed the required BUGID argument from the "post-commits"
     10        command and replaced it with a -b|--bug-id switch or parsing the
     11        commit log message for the bug URL.  Fixed a bug in the
     12        "post-commits" that would ignore the COMMITISH used and post a
     13        patch of local changes against HEAD.  Added --no-commit switch
     14        to disable using the bulk of the ChangeLog entry as the comment
     15        for the new patch.
     16
     17        * Scripts/bugzilla-tool:
     18        (bug_id_from_commit_message): Added.  Returns a bug id from the
     19        commit log message, thus enforcing the need for a bug URL in the
     20        message.
     21        (PostCommitsAsPatchesToBug.__init__): Updated help description
     22        to match new behavior of pulling bug ids from commit log
     23        messages instead of from the command line.  Added -b|--bug-id
     24        switch and --no-comment switch.
     25        (PostCommitsAsPatchesToBug.execute): Updated to use
     26        bug_id_from_commit_message() to pull bug ids from commit log
     27        messages.  Also switched from SCM.create_patch() to use
     28        SCM.create_patch_from_local_commit() to fix a bug where local
     29        repository changes were posted as a patch instead of the
     30        specific COMMITISH.  Fall back to -b|--bug-id if no URL is found
     31        in the commit log message.  Don't specify a comment for the
     32        patch if --no-comment is used.  Set cherry_pick argument to True
     33        for Git.commit_ids_from_range_arguments() since we don't want
     34        implicit commit range behavior for this command.
     35
     36        * Scripts/modules/bugzilla.py: Import datetime module.
     37        (timestamp): Added.  Returns a timestamp in the form of
     38        "YYYYMMDDhhmmss".
     39        (Bugzilla.bug_server_regex): Added static attribute.
     40        (Bugzilla.add_patch_to_bug): Construct a more meaningful patch
     41        file name using the bug_id and timestamp().
     42
     43        * Scripts/modules/scm.py:
     44        (SCM.create_patch_from_local_commit): Added.
     45        (Git.create_patch_from_local_commit): Added.  Runs "git diff" to
     46        return a patch for the given commit_id.
     47
    1482009-07-08  Maciej Stachowiak  <mjs@apple.com>
    249
  • trunk/WebKitTools/Scripts/bugzilla-tool

    r45469 r45654  
    11#!/usr/bin/python
    22# Copyright (c) 2009, Google Inc. All rights reserved.
     3# Copyright (c) 2009 Apple Inc. All rights reserved.
    34#
    45# Redistribution and use in source and binary forms, with or without
     
    102103    return changelog_paths
    103104
     105def bug_id_from_commit_message(commit_message):
     106    match = re.search(Bugzilla.bug_server_regex + "show_bug\.cgi\?id=(?P<bug_id>\d+)", commit_message, re.MULTILINE)
     107    return match.group('bug_id')
     108
    104109def commit_message_for_this_commit(scm):
    105110    changelog_paths = modified_changelogs(scm)
     
    408413    def __init__(self):
    409414        options = [
     415            make_option("-b", "--bug-id", action="store", type="string", dest="bug_id", help="Specify bug id if no URL is provided in the commit log."),
     416            make_option("--no-comment", action="store_false", dest="comment", default=True, help="Do not use commit log message as a comment for the patch."),
    410417            make_option("--no-obsolete", action="store_false", dest="obsolete_patches", default=True, help="Do not obsolete old patches before posting new ones."),
    411418            make_option("--no-review", action="store_false", dest="review", default=True, help="Do not mark the patch for review."),
    412419        ]
    413         Command.__init__(self, 'Attaches a range of local commits to a bug as patch files.', 'BUGID COMMITISH', options=options)
    414 
    415     def execute(self, options, args, tool):
    416         bug_id = args[0]
    417        
     420        Command.__init__(self, 'Attaches a range of local commits to bugs as patch files.', 'COMMITISH', options=options)
     421
     422    def execute(self, options, args, tool):
    418423        if not tool.scm().supports_local_commits():
    419424            error(tool.scm().display_name() + " does not support local commits.")
    420        
    421         commit_ids = tool.scm().commit_ids_from_range_arguments(args[1:])
    422        
     425
     426        commit_ids = tool.scm().commit_ids_from_range_arguments(args, cherry_pick=True)
     427
    423428        if len(commit_ids) > 10:
    424             error("Are you sure you want to attach %s to bug %s?" % (pluralize('patch', len(commit_ids)), bug_id))
     429            error("Are you sure you want to attach %s patches?" % (pluralize('patch', len(commit_ids))))
    425430            # Could add a --patches-limit option.
    426431
    427         if options.obsolete_patches:
    428             PostDiffAsPatchToBug.obsolete_patches_on_bug(bug_id, tool.bugs)
    429        
    430         log("Attaching %s as patches to bug %s" % (pluralize('commit', len(commit_ids)), bug_id))
     432        have_obsoleted_patches = set()
    431433        for commit_id in commit_ids:
    432434            commit_message = tool.scm().commit_message_for_commit(commit_id)
    433435            commit_lines = commit_message.splitlines()
    434            
     436
     437            bug_id = options.bug_id or bug_id_from_commit_message(commit_message)
     438            if not bug_id:
     439                log("Skipping %s: No bug id found in commit log or specified with --bug-id." % commit_id)
     440                continue
     441
     442            if options.obsolete_patches and bug_id not in have_obsoleted_patches:
     443                PostDiffAsPatchToBug.obsolete_patches_on_bug(bug_id, tool.bugs)
     444                have_obsoleted_patches.update(bug_id)
     445
    435446            description = commit_lines[0]
    436             comment_text = "\n".join(commit_lines[1:])
    437             comment_text += "---\n"
    438             comment_text += tool.scm().files_changed_summary_for_commit(commit_id)
    439        
    440             diff = tool.scm().create_patch()
     447            comment_text = None
     448            if (options.comment):
     449                comment_text = "\n".join(commit_lines[1:])
     450                comment_text += "\n---\n"
     451                comment_text += tool.scm().files_changed_summary_for_commit(commit_id)
     452
     453            diff = tool.scm().create_patch_from_local_commit(commit_id)
    441454            diff_file = StringIO.StringIO(diff) # add_patch_to_bug expects a file-like object
    442455            tool.bugs.add_patch_to_bug(bug_id, diff_file, description, comment_text, mark_for_review=options.review)
  • trunk/WebKitTools/Scripts/modules/bugzilla.py

    r45638 r45654  
    11# Copyright (c) 2009, Google Inc. All rights reserved.
     2# Copyright (c) 2009 Apple Inc. All rights reserved.
    23#
    34# Redistribution and use in source and binary forms, with or without
     
    3536import urllib2
    3637
     38from datetime import datetime # used in timestamp()
     39
    3740# WebKit includes a built copy of BeautifulSoup in Scripts/modules
    3841# so this import should always succeed.
     
    7073        return None
    7174    return value.rstrip('\n')
     75
     76def timestamp():
     77    return datetime.now().strftime("%Y%m%d%H%M%S")
    7278
    7379class Bugzilla:
     
    8288        # Ignore bugs.webkit.org/robots.txt until we fix it to allow this script
    8389        self.browser.set_handle_robots(False)
     90
     91    bug_server_regex = "https?\://bugs\.webkit\.org/"
    8492
    8593    # This could eventually be a text file
     
    247255            self.browser['comment'] = comment_text
    248256        self.browser['flag_type-1'] = ('?',) if mark_for_review else ('X',)
    249         self.browser.add_file(patch_file_object, "text/plain", "bugzilla_requires_a_filename.patch")
     257        self.browser.add_file(patch_file_object, "text/plain", "bug-%s-%s.patch" % (bug_id, timestamp()))
    250258        self.browser.submit()
    251259
  • trunk/WebKitTools/Scripts/modules/scm.py

    r45580 r45654  
    11# Copyright (c) 2009, Google Inc. All rights reserved.
     2# Copyright (c) 2009 Apple Inc. All rights reserved.
    23#
    34# Redistribution and use in source and binary forms, with or without
     
    155156        raise NotImplementedError, "subclasses must implement"
    156157
     158    def create_patch_from_local_commit(self, commit_id):
     159        pass
     160
    157161    def commit_locally_with_message(self, message):
    158162        pass
     
    291295
    292296    # Git-specific methods:
    293    
     297
     298    def create_patch_from_local_commit(self, commit_id):
     299        return self.run_command(['git', 'diff', commit_id + "^.." + commit_id])
     300
    294301    def commit_locally_with_message(self, message):
    295302        self.run_command(['git', 'commit', '--all', '-F', '-'], input=message)
Note: See TracChangeset for help on using the changeset viewer.