Electron 的补丁
Every patch in Electron is a maintenance burden. When upstream code changes, patches can break—sometimes without even a patch conflict or a compilation error. It’s an ongoing effort to keep our patch set up-to-date and effective. So we strive to keep our patch count at a minimum. To that end, every patch must describe its reason for existence in its commit message. That reason must be one of the following:
- The patch is temporary, and is intended to be (or has been) committed upstream or otherwise eventually removed. Include a link to an upstream PR or code review if available, or a procedure for verifying whether the patch is still needed at a later date.
- The patch makes Electron-specific changes in functionality which are fundamentally incompatible with upstream.
In general, all the upstream projects we work with are friendly folks and are often happy to accept refactorings that allow the code in question to be compatible with both Electron and the upstream project. (See e.g. change in Chromium, which allowed us to remove a patch that did the same thing, or this change in Node, which was a no-op for Node but fixed a bug in Electron.) We should aim to upstream changes whenever we can, and avoid indefinite-lifetime patches.
补丁系统
If you find yourself in the unfortunate position of having to make a change which can only be made through patching an upstream project, you’ll need to know how to manage patches in Electron.
To help manage these patch sets, we provide two tools: git-import-patches
and git-export-patches
. git-import-patches
imports a set of patch files into a git repository by applying each patch in the correct order and creating a commit for each one. does the reverse; it exports a series of git commits in a repository into a set of files in a directory and an accompanying .patches
file.
添加新补丁
NOTE:
git-export-patches
ignores any uncommitted files, so you must create a commit if you want your changes to be exported. The subject line of the commit message will be used to derive the patch file name, and the body of the commit message should include the reason for the patch’s existence.
编辑现有补丁
移除补丁
Note that git-import-patches
will mark the commit that was HEAD
when it was run as . This lets you keep track of which commits are from Electron patches (those that come after refs/patches/upstream-head
) and which commits are in upstream (those before refs/patches/upstream-head
).
解决冲突
When updating an upstream dependency, patches may fail to apply cleanly. Often, the conflict can be resolved automatically by git with a 3-way merge. You can instruct git-import-patches
to use the 3-way merge algorithm by passing the -3
argument:
If git-import-patches -3
encounters a merge conflict that it can’t resolve automatically, it will pause and allow you to resolve the conflict manually. Once you have resolved the conflict, git add
the resolved files and continue to apply the rest of the patches by running .