Skip to content

Commit 4c86f08

Browse files
committed
record applied patchfiles in the statefile
Adds a "patch: <patchfile>" line to the statefile and verify this record before applying each subsequent patch. This is a very useful mechanism during port maintenance when some patches have to be rebased; it allows repeated application of `port patch` (or "higher") where only the failing patch has to be reverted and already applied patches are skipped automatically. Also adds default fd argument to check_statefile and write_statefile in portutil.tcl , so that they can be called externally without having to reopen the statefile. In that case they will check/write to the current statefile descriptor `$target_state_fd`. This will allow to call them safely from the patch_main override procedure in the muniversal-1.1 PG.
1 parent b2e06d5 commit 4c86f08

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

src/port1.0/portpatch.tcl

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ proc portpatch::build_getpatchtype {args} {
6868
}
6969

7070
proc portpatch::patch_main {args} {
71-
global UI_PREFIX
71+
global UI_PREFIX target_state_fd
7272

7373
# First make sure that patchfiles exists and isn't stubbed out.
7474
if {![exists patchfiles] || [option patchfiles] eq ""} {
@@ -96,18 +96,24 @@ proc portpatch::patch_main {args} {
9696
catch {set xzcat "[findBinary xz $portutil::autoconf::xz_path] -dc"}
9797

9898
foreach patch $patchlist {
99-
ui_info "$UI_PREFIX [format [msgcat::mc "Applying %s"] [file tail $patch]]"
100-
switch -- [file extension $patch] {
101-
.Z -
102-
.gz {command_exec patch "$gzcat \"$patch\" | (" ")"}
103-
.bz2 {command_exec patch "$bzcat \"$patch\" | (" ")"}
104-
.xz {
105-
if {[info exists xzcat]} {
106-
command_exec patch "$xzcat \"$patch\" | (" ")"
107-
} else {
108-
return -code error [msgcat::mc "xz binary not found; port needs to add 'depends_patch bin:xz:xz'"]
109-
}}
110-
default {command_exec patch "" "< '$patch'"}
99+
set pfile [file tail $patch]
100+
if {![check_statefile patch $pfile $target_state_fd]} {
101+
ui_info "$UI_PREFIX [format [msgcat::mc "Applying %s"] [file tail $patch]]"
102+
switch -- [file extension $patch] {
103+
.Z -
104+
.gz {command_exec patch "$gzcat \"$patch\" | (" ")"}
105+
.bz2 {command_exec patch "$bzcat \"$patch\" | (" ")"}
106+
.xz {
107+
if {[info exists xzcat]} {
108+
command_exec patch "$xzcat \"$patch\" | (" ")"
109+
} else {
110+
return -code error [msgcat::mc "xz binary not found; port needs to add 'depends_patch bin:xz:xz'"]
111+
}}
112+
default {command_exec patch "" "< '$patch'"}
113+
}
114+
write_statefile patch $pfile $target_state_fd
115+
} else {
116+
ui_info "$UI_PREFIX [format [msgcat::mc "Skipping already applied %s"] $pfile]"
111117
}
112118
}
113119
return 0

src/port1.0/portutil.tcl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,11 @@ proc get_statefile_value {class fd result} {
18781878

18791879
# check_statefile
18801880
# Check completed/selected state of target/variant $name
1881-
proc check_statefile {class name fd} {
1881+
proc check_statefile {class name {fd {}}} {
1882+
global target_state_fd
1883+
if {$fd eq {} && [info exists target_state_fd]} {
1884+
set fd $target_state_fd
1885+
}
18821886
seek $fd 0
18831887
while {[gets $fd line] >= 0} {
18841888
if {$line eq "$class: $name"} {
@@ -1890,7 +1894,11 @@ proc check_statefile {class name fd} {
18901894

18911895
# write_statefile
18921896
# Set target $name completed in the state file
1893-
proc write_statefile {class name fd} {
1897+
proc write_statefile {class name {fd {}}} {
1898+
global target_state_fd
1899+
if {$fd eq {} && [info exists target_state_fd]} {
1900+
set fd $target_state_fd
1901+
}
18941902
if {[check_statefile $class $name $fd]} {
18951903
return 0
18961904
}

0 commit comments

Comments
 (0)