Skip to content

Commit

Permalink
Merge remote-tracking branch 'ptesarik/overlap'
Browse files Browse the repository at this point in the history
This is related to #31, but not a complete solution yet, because I can still
reproduce the original failure with some patch series.

The last commit adds one of the reported cases to test data, and it passes
cargo test, so there is some improvement.
  • Loading branch information
ptesarik committed Jan 8, 2025
2 parents 73e4cd7 + d523464 commit 72aa027
Show file tree
Hide file tree
Showing 15 changed files with 15,291 additions and 204 deletions.
423 changes: 219 additions & 204 deletions src/libpatch/patch/mod.rs

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions testdata/patching/hunks_overlapping_modified.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
aaa
bbb
ccc
ddd modified
eee modified
fff
ggg modified
hhh
iii
jjj
kkk
lll
mmm
nnn
ooo
ppp
qqq
rrr
sss
ttt
uuu
vvv
www
xxx
xxx
xxx
xxx
xxx
xxx
xxx
xxx
xxx
xxx
xxx
xxx
xxx
xxx
xxx
xxx
xxx
xxx
xxx
xxx
xxx
xxx
33 changes: 33 additions & 0 deletions testdata/patching/hunks_overlapping_modified.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Leading context overlaps previously modified content.

This is accepted by GNU patch, and the context in all hunks must match the
original file content.
--- file.in 2019-01-16 15:02:37.016021405 +0100
+++ hunks_overlapping_modified.out 2019-01-16 15:03:08.724512747 +0100
@@ -1,7 +1,7 @@
aaa
bbb
ccc
-ddd
+ddd modified
eee
fff
ggg
@@ -2,7 +2,7 @@
bbb
ccc
ddd
-eee
+eee modified
fff
ggg
hhh
@@ -4,7 +4,7 @@
ddd
eee
fff
-ggg
+ggg modified
hhh
iii
jjj
64 changes: 64 additions & 0 deletions testdata/patching/offset_to_end.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
aaa
bbb
ccc
0000
1111
2222
3333
4444
5555
6666
ddd
eee
fff
ggg
hhh
iii
jjj
kkk
lll
mmm
nnn
ooo
ppp
qqq
rrr
sss
ttt
uuu
vvv
www
xxx
aaa
bbb
ccc
ddd
eee
fff
ggg
hhh
iii
jjj
kkk
lll
mmm
nnn
ooo
ppp
qqq
rrr
sss
ttt
uuu
vvv
www
xxx
0000
1111
2222
3333
4444
www
6666
yyy
zzz
15 changes: 15 additions & 0 deletions testdata/patching/offset_to_end.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Move a hunk to the end of the file with a positive offset.

Make sure that the offset bounds are set correctly and allow moving the hunk
down to the very end of the file.
--- file4.in 2019-01-29 14:25:32.384682572 +0100
+++ offset_to_end.out 2025-01-07 17:05:09.973739126 +0100
@@ -40,7 +40,7 @@
2222
3333
4444
-5555
+www
6666
yyy
zzz
64 changes: 64 additions & 0 deletions testdata/patching/offset_to_start.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
aaa
bbb
ccc
ddd
1111
2222
3333
4444
5555
6666
ddd
eee
fff
ggg
hhh
iii
jjj
kkk
lll
mmm
nnn
ooo
ppp
qqq
rrr
sss
ttt
uuu
vvv
www
xxx
aaa
bbb
ccc
ddd
eee
fff
ggg
hhh
iii
jjj
kkk
lll
mmm
nnn
ooo
ppp
qqq
rrr
sss
ttt
uuu
vvv
www
xxx
0000
1111
2222
3333
4444
5555
6666
yyy
zzz
15 changes: 15 additions & 0 deletions testdata/patching/offset_to_start.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Move a hunk to the start of the file with a negative offset.

Make sure that the offset bounds are set correctly and allow moving the hunk
up to the very beginning of the file.
--- file4.in 2019-01-29 14:25:32.384682572 +0100
+++ offset_to_start.out 2025-01-07 17:05:09.973739126 +0100
@@ -40,7 +40,7 @@
aaa
bbb
ccc
-0000
+ddd
1111
2222
3333
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
Reproducer for issue #31

There are two overlapping patches and one that does not apply, so the patch as
a whole must be rolled back, but the second overlapping hunk modifies the
trailing context of the first hunk.

diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index 35d4b398c197..8bd9fd51208c 100644
--- a/qeth_core_main.c
+++ b/qeth_core_main.c
@@ -4744,92 +4788,6 @@ static int qeth_query_oat_command(struct qeth_card *card, char __user *udata)
return rc;
}

-static int qeth_query_card_info_cb(struct qeth_card *card,
- struct qeth_reply *reply, unsigned long data)
-{
- struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *)data;
- struct qeth_link_info *link_info = reply->param;
- struct qeth_query_card_info *card_info;
-
- QETH_CARD_TEXT(card, 2, "qcrdincb");
- if (qeth_setadpparms_inspect_rc(cmd))
- return -EIO;
-
- card_info = &cmd->data.setadapterparms.data.card_info;
- netdev_dbg(card->dev,
- "card info: card_type=0x%02x, port_mode=0x%04x, port_speed=0x%08x\n",
- card_info->card_type, card_info->port_mode,
- card_info->port_speed);
-
- switch (card_info->port_mode) {
- case CARD_INFO_PORTM_FULLDUPLEX:
- link_info->duplex = DUPLEX_FULL;
- break;
- case CARD_INFO_PORTM_HALFDUPLEX:
- link_info->duplex = DUPLEX_HALF;
- break;
- default:
- link_info->duplex = DUPLEX_UNKNOWN;
- }
-
- switch (card_info->card_type) {
- case CARD_INFO_TYPE_1G_COPPER_A:
- case CARD_INFO_TYPE_1G_COPPER_B:
- link_info->speed = SPEED_1000;
- link_info->port = PORT_TP;
- break;
- case CARD_INFO_TYPE_1G_FIBRE_A:
- case CARD_INFO_TYPE_1G_FIBRE_B:
- link_info->speed = SPEED_1000;
- link_info->port = PORT_FIBRE;
- break;
- case CARD_INFO_TYPE_10G_FIBRE_A:
- case CARD_INFO_TYPE_10G_FIBRE_B:
- link_info->speed = SPEED_10000;
- link_info->port = PORT_FIBRE;
- break;
- default:
- switch (card_info->port_speed) {
- case CARD_INFO_PORTS_10M:
- link_info->speed = SPEED_10;
- break;
- case CARD_INFO_PORTS_100M:
- link_info->speed = SPEED_100;
- break;
- case CARD_INFO_PORTS_1G:
- link_info->speed = SPEED_1000;
- break;
- case CARD_INFO_PORTS_10G:
- link_info->speed = SPEED_10000;
- break;
- case CARD_INFO_PORTS_25G:
- link_info->speed = SPEED_25000;
- break;
- default:
- link_info->speed = SPEED_UNKNOWN;
- }
-
- link_info->port = PORT_OTHER;
- }
-
- return 0;
-}
-
-int qeth_query_card_info(struct qeth_card *card,
- struct qeth_link_info *link_info)
-{
- struct qeth_cmd_buffer *iob;
-
- QETH_CARD_TEXT(card, 2, "qcrdinfo");
- if (!qeth_adp_supported(card, IPA_SETADP_QUERY_CARD_INFO))
- return -EOPNOTSUPP;
- iob = qeth_get_adapter_cmd(card, IPA_SETADP_QUERY_CARD_INFO, 0);
- if (!iob)
- return -ENOMEM;
-
- return qeth_send_ipa_cmd(card, iob, qeth_query_card_info_cb, link_info);
-}
-
static void qeth_init_link_info(struct qeth_card *card)
{
card->info.link_info.duplex = DUPLEX_FULL;
@@ -4839,6 +4797,7 @@ static int qeth_init_link_info_oat_cb(struct qeth_card *card,
struct qeth_query_oat_physical_if *phys_if;
struct qeth_query_oat_reply *reply;

+ QETH_CARD_TEXT(card, 2, "qoatincb");
if (qeth_setadpparms_inspect_rc(cmd))
return -EIO;

@@ -4918,38 +4877,7 @@ static int qeth_init_link_info_oat_cb(struct qeth_card *card,

static void qeth_init_link_info(struct qeth_card *card)
{
- card->info.link_info.duplex = DUPLEX_FULL;
-
- if (IS_IQD(card) || IS_VM_NIC(card)) {
- card->info.link_info.speed = SPEED_10000;
- card->info.link_info.port = PORT_FIBRE;
- } else {
- switch (card->info.link_type) {
- case QETH_LINK_TYPE_FAST_ETH:
- case QETH_LINK_TYPE_LANE_ETH100:
- card->info.link_info.speed = SPEED_100;
- card->info.link_info.port = PORT_TP;
- break;
- case QETH_LINK_TYPE_GBIT_ETH:
- case QETH_LINK_TYPE_LANE_ETH1000:
- card->info.link_info.speed = SPEED_1000;
- card->info.link_info.port = PORT_FIBRE;
- break;
- case QETH_LINK_TYPE_10GBIT_ETH:
- card->info.link_info.speed = SPEED_10000;
- card->info.link_info.port = PORT_FIBRE;
- break;
- case QETH_LINK_TYPE_25GBIT_ETH:
- card->info.link_info.speed = SPEED_25000;
- card->info.link_info.port = PORT_FIBRE;
- break;
- default:
- dev_info(&card->gdev->dev, "Unknown link type %x\n",
- card->info.link_type);
- card->info.link_info.speed = SPEED_UNKNOWN;
- card->info.link_info.port = PORT_OTHER;
- }
- }
+ qeth_default_link_info(card);
}

/**
Loading

0 comments on commit 72aa027

Please sign in to comment.