How to merge Wireshark upstream changes into a local fork

When maintaining the fork of Wireshark, it is necessary to synchronize the custom changes with the upstream changes from the main Wireshark repository. We use the following approach to apply a clean patch to a new upstream release.

Creating a patch based on the last release

At the date of writing, the last custom version is 3.6.1.

Branch log

The latest upstream commit was a0a473c7c1ba17553495bb03b3e1c2059f20557b in the case. So, we create a patch based on the modifications after that commit.

git diff a0a473c7c1ba17553495bb03b3e1c2059f20557b > ../patch-3.6.1

Convert the patch to UTF8 on Windows.

Get-Content ..\patch-3.6.1 | Set-Content -Encoding utf8 ..\patch-3.6.1-utf8

Fetching the upstream branches

Then we fetch the upstream changes and branches.

 git fetch upstream
remote: Enumerating objects: 1086, done.
remote: Counting objects: 100% (1086/1086), done.
remote: Compressing objects: 100% (522/522), done.
remote: Total 1086 (delta 846), reused 798 (delta 564), pack-reused 0Receiving objects:  99% (1076/1086), 4.
Receiving objects: 100% (1086/1086), 4.68 MiB | 8.24 MiB/s, done.
Resolving deltas: 100% (846/846), completed with 240 local objects.
a02b964b5f..79da670bd1  master      -> upstream/master
815172850d..81382c49b3  release-3.4 -> upstream/release-3.4
f0a6012f97..9403727cf7  release-3.6 -> upstream/release-3.6
* [new tag]               v3.4.12          -> v3.4.12
* [new tag]               v3.4.13rc0       -> v3.4.13rc0
* [new tag]               v3.6.2           -> v3.6.2
* [new tag]               v3.6.3rc0        -> v3.6.3rc0
* [new tag]               wireshark-3.4.12 -> wireshark-3.4.12
* [new tag]               wireshark-3.6.2  -> wireshark-3.6.2

The new tag wireshark-3.6.2 is the current stable version of Wireshark as of today.

Create a new branch from the tag

The next step is to create a new branch from the upstream tag.

git checkout -b waveanalyzer-3.6.2 wireshark-3.6.2
Switched to a new branch 'waveanalyzer-3.6.2'

Apply patch

Now we apply the patch created in the first step to the newly created branch.

git apply --reject --whitespace=fix ..\patch-3.6.1-utf8
../patch-3.6.1-utf8:672: trailing whitespace.

../patch-3.6.1-utf8:874: trailing whitespace.

../patch-3.6.1-utf8:875: trailing whitespace.

../patch-3.6.1-utf8:1001: trailing whitespace.
../patch-3.6.1-utf8:1003: trailing whitespace.
                        sharkd_json_value_string(NULL, col_item->col_data);
Checking patch epan/color_filters.c...
Checking patch epan/color_filters.h...
Checking patch epan/column-info.h...
Checking patch epan/column-utils.c...
Checking patch epan/dissectors/packet-frame.c...
Checking patch epan/epan.c...
Checking patch epan/epan.h...
Checking patch epan/frame_data.c...
Checking patch epan/frame_data.h...
Checking patch epan/print.c...
Checking patch epan/print.h...
Checking patch epan/proto.c...
Hunk #1 succeeded at 6670 (offset 6 lines).
Hunk #2 succeeded at 6699 (offset 6 lines).
Checking patch epan/proto.h...
Checking patch sharkd.c...
Checking patch sharkd.h...
Checking patch sharkd_daemon.c...
Checking patch sharkd_session.c...
Checking patch tshark.c...
Checking patch ui/clopts_common.c...
Checking patch ui/clopts_common.h...
Checking patch ui/decode_as_utils.c...
Checking patch ui/decode_as_utils.h...
Checking patch wsutil/json_dumper.c...
Applied patch epan/color_filters.c cleanly.
Applied patch epan/color_filters.h cleanly.
Applied patch epan/column-info.h cleanly.
Applied patch epan/column-utils.c cleanly.
Applied patch epan/dissectors/packet-frame.c cleanly.
Applied patch epan/epan.c cleanly.
Applied patch epan/epan.h cleanly.
Applied patch epan/frame_data.c cleanly.
Applied patch epan/frame_data.h cleanly.
Applied patch epan/print.c cleanly.
Applied patch epan/print.h cleanly.
Applied patch epan/proto.c cleanly.
Applied patch epan/proto.h cleanly.
Applied patch sharkd.c cleanly.
Applied patch sharkd.h cleanly.
Applied patch sharkd_daemon.c cleanly.
Applied patch sharkd_session.c cleanly.
Applied patch tshark.c cleanly.
Applied patch ui/clopts_common.c cleanly.
Applied patch ui/clopts_common.h cleanly.
Applied patch ui/decode_as_utils.c cleanly.
Applied patch ui/decode_as_utils.h cleanly.
Applied patch wsutil/json_dumper.c cleanly.
warning: squelched 11 whitespace errors
warning: 15 lines applied after fixing whitespace errors.

In this case, we were lucky, and all changes were applied without rejection. We need to commit the changes and push the new branch.

git add .
git commit -m "Apply waveanalyzer patch to upstream version 3.6.2"
[waveanalyzer-3.6.2 fe8eb20867] Apply waveanalyzer patch to upstream version 3.6.2
git push --set-upstream origin waveanalyzer-3.6.2

This approach has the downside: the git log does not contain all the development history of the patch. On the positive side, it results in a clean patch that can be applied cleanly upstream.