Bug 219982

Summary: [webkitscmpy] Add command to canonicalize unpushed commits
Product: WebKit Reporter: Jonathan Bedard <jbedard>
Component: Tools / TestsAssignee: Jonathan Bedard <jbedard>
Status: RESOLVED FIXED    
Severity: Normal CC: aakash_jain, ap, dewei_zhu, slewis, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=219988
https://bugs.webkit.org/show_bug.cgi?id=219989
https://bugs.webkit.org/show_bug.cgi?id=219992
https://bugs.webkit.org/show_bug.cgi?id=220369
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch for landing none

Description Jonathan Bedard 2020-12-17 08:36:27 PST
We need to add a command to modify authorship and insert identifiers into commit before they are pushed to the remote.
Comment 1 Radar WebKit Bug Importer 2020-12-17 08:36:42 PST
<rdar://problem/72427536>
Comment 2 Jonathan Bedard 2020-12-17 09:56:49 PST
Created attachment 416434 [details]
Patch
Comment 3 Jonathan Bedard 2020-12-17 10:16:08 PST
Comment on attachment 416434 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=416434&action=review

> Tools/Scripts/libraries/webkitscmpy/webkitscmpy/canonicalize/message.py:60
> +        lines[identifier_index - 1] = 'Identifier: {}'.format(commit)

I know Alexey has an opinion on this bit in that he thinks it should be a URL, which would look like:
<https://scm.webkit.org/1234@main>
Comment 4 Jonathan Bedard 2020-12-17 10:16:49 PST
(In reply to Jonathan Bedard from comment #3)
> Comment on attachment 416434 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=416434&action=review
> 
> > Tools/Scripts/libraries/webkitscmpy/webkitscmpy/canonicalize/message.py:60
> > +        lines[identifier_index - 1] = 'Identifier: {}'.format(commit)
> 
> I know Alexey has an opinion on this bit in that he thinks it should be a
> URL, which would look like:
> <https://scm.webkit.org/1234@main>

Note: This service does not yet exist, so this URL is dead.
Comment 5 Jonathan Bedard 2020-12-17 15:51:15 PST
Created attachment 416477 [details]
Patch
Comment 6 Jonathan Bedard 2020-12-18 07:02:28 PST
Created attachment 416516 [details]
Patch
Comment 7 Jonathan Bedard 2020-12-18 13:43:14 PST
Created attachment 416542 [details]
Patch
Comment 8 Alexey Proskuryakov 2020-12-18 13:47:54 PST
Comment on attachment 416542 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=416542&action=review

> Tools/Scripts/libraries/webkitscmpy/webkitscmpy/canonicalize/message.py:62
> +        lines.insert(identifier_index, 'Identifier: {}'.format(identifier_template.format(commit)))

I continue to think that we want a descriptive name here that gives at least a hint for how it's expected to be used by people, e.g. "Canonical link".
Comment 9 Alexey Proskuryakov 2020-12-18 13:48:33 PST
Comment on attachment 416542 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=416542&action=review

>> Tools/Scripts/libraries/webkitscmpy/webkitscmpy/canonicalize/message.py:62
>> +        lines.insert(identifier_index, 'Identifier: {}'.format(identifier_template.format(commit)))
> 
> I continue to think that we want a descriptive name here that gives at least a hint for how it's expected to be used by people, e.g. "Canonical link".

Also, on a purely nitpicking level, the URL is not the identifier, only the last part of it is.
Comment 10 Jonathan Bedard 2020-12-18 14:00:30 PST
Created attachment 416543 [details]
Patch
Comment 11 Jonathan Bedard 2020-12-18 16:21:30 PST
Created attachment 416558 [details]
Patch
Comment 12 Jonathan Bedard 2021-01-05 13:11:51 PST
Created attachment 417028 [details]
Patch
Comment 13 dewei_zhu 2021-01-05 14:26:47 PST
Comment on attachment 417028 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=417028&action=review

> Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program.py:186
> +    from webkitscmpy.canonicalize import Canonicalize

There was a version of patch that splits the commands into different files, but we decided to keep them in a single file since there were too few commands/code to split them.
I see the deferred import is to avoid circular import. Do you think it's time to consider re-split commands?

> Tools/Scripts/libraries/webkitscmpy/webkitscmpy/canonicalize/committer.py:50
> +    REPOSITORY_PATH = os.environ.get('OLDPWD')

I do see GIT_* are set somewhere, but I don't see we set OLDPWD anywhere. How do we guarantee this since OLDPWD might be different based on PWD history.
Comment 14 Jonathan Bedard 2021-01-05 14:44:23 PST
Comment on attachment 417028 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=417028&action=review

>> Tools/Scripts/libraries/webkitscmpy/webkitscmpy/canonicalize/committer.py:50
>> +    REPOSITORY_PATH = os.environ.get('OLDPWD')
> 
> I do see GIT_* are set somewhere, but I don't see we set OLDPWD anywhere. How do we guarantee this since OLDPWD might be different based on PWD history.

The GIT_* variables are both read and written, OLDPWD is only read. The bash code you see is actually reading the values of the GIT_* variables printed out by this script and exporting that to git filter-branch.

Seems like git filter-branch always sets OLDPWD, although I'm not entirely certain why (seems likely to be something about git's underlying bash-y nature)
Comment 15 Jonathan Bedard 2021-01-05 15:06:37 PST
Comment on attachment 417028 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=417028&action=review

>> Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program.py:186
>> +    from webkitscmpy.canonicalize import Canonicalize
> 
> There was a version of patch that splits the commands into different files, but we decided to keep them in a single file since there were too few commands/code to split them.
> I see the deferred import is to avoid circular import. Do you think it's time to consider re-split commands?

I do, but I think that should be a stand-alone patch. No reason to make this one more complicated than it already is
Comment 16 dewei_zhu 2021-01-05 15:42:28 PST
Comment on attachment 417028 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=417028&action=review

>>> Tools/Scripts/libraries/webkitscmpy/webkitscmpy/program.py:186
>>> +    from webkitscmpy.canonicalize import Canonicalize
>> 
>> There was a version of patch that splits the commands into different files, but we decided to keep them in a single file since there were too few commands/code to split them.
>> I see the deferred import is to avoid circular import. Do you think it's time to consider re-split commands?
> 
> I do, but I think that should be a stand-alone patch. No reason to make this one more complicated than it already is

Sure.

>>> Tools/Scripts/libraries/webkitscmpy/webkitscmpy/canonicalize/committer.py:50
>>> +    REPOSITORY_PATH = os.environ.get('OLDPWD')
>> 
>> I do see GIT_* are set somewhere, but I don't see we set OLDPWD anywhere. How do we guarantee this since OLDPWD might be different based on PWD history.
> 
> The GIT_* variables are both read and written, OLDPWD is only read. The bash code you see is actually reading the values of the GIT_* variables printed out by this script and exporting that to git filter-branch.
> 
> Seems like git filter-branch always sets OLDPWD, although I'm not entirely certain why (seems likely to be something about git's underlying bash-y nature)

Got it.
Comment 17 dewei_zhu 2021-01-05 15:52:43 PST
r=me. Discussed with Jonathan in person, `git filter-branch` will set OLDPWD to the repo. Another approach Jonathan mentioned is to use 'GIT_DIR'. I'm OK with both approach.
Comment 18 EWS 2021-01-05 16:36:17 PST
Committed r271182: <https://trac.webkit.org/changeset/271182>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 417028 [details].
Comment 19 Jonathan Bedard 2021-01-05 22:06:05 PST
Reopening to attach new patch.
Comment 20 Jonathan Bedard 2021-01-05 22:06:06 PST
Created attachment 417065 [details]
Patch
Comment 21 Aakash Jain 2021-01-06 07:05:19 PST
> Tools/Scripts/libraries/webkitscmpy/webkitscmpy/canonicalize/__init__.py:62
>              if not repository.path:

Should repository.path be changed here as well?
Comment 22 Aakash Jain 2021-01-06 07:05:27 PST
Comment on attachment 417065 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=417065&action=review

> Tools/Scripts/libraries/webkitscmpy/webkitscmpy/canonicalize/__init__.py:76
>              '{remote}/{branch}..{branch}'.format(remote=args.remote, branch=branch),

test
Comment 23 Jonathan Bedard 2021-01-06 07:09:24 PST
(In reply to Aakash Jain from comment #21)
> > Tools/Scripts/libraries/webkitscmpy/webkitscmpy/canonicalize/__init__.py:62
> >              if not repository.path:
> 
> Should repository.path be changed here as well?

root_path is derived from path, what we're basically checking for here is "is the repository the user specified something actually existing on the filesystem, or is it referring to a remote repository accessed via a web API"
Comment 24 Jonathan Bedard 2021-01-06 08:00:16 PST
Created attachment 417084 [details]
Patch for landing
Comment 25 EWS 2021-01-06 10:15:05 PST
Committed r271203: <https://trac.webkit.org/changeset/271203>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 417084 [details].
Comment 26 Jonathan Bedard 2021-01-07 08:44:03 PST
A follow-up note on this change: We are now using this script in the post-commit SVN hook to push to https://github.com/WebKit/WebKit.