textutil::patch(n)

πŸ“¦
version 2.0 Β· 2 versions
, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

✨ NAME ✨

textutil::patch β€” applying uni-diff patches to whole directory trees πŸ¦‹


🌸 SYNOPSIS 🌸

package require Tcl 8.5 9

package require textutil::patch ?0.2?

::textutil::patch::apply basedirectory striplevel patch reportcmd

{*}reportcmd apply filename

{*}reportcmd fail filename hunk expected seen

{*}reportcmd fail-already filename hunk

πŸ’… DESCRIPTION πŸ’…

okay so listen, this package is literally just one command, and what that one command does is take a patch in unified format β€” you know the one, [https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html] β€” and apply it to a directory tree. one job. does it well. periodt. πŸ’–

::textutil::patch::apply basedirectory striplevel patch reportcmd

Applies the patch β€” and yes bestie, text of the path, not file β€” to the files sitting inside basedirectory, using the striplevel you told it to use. and the result of the whole command? the empty string. that's it. that's the tea. 🍡

the striplevel argument is equivalent to option -p of the patch command. same energy, same meaning, iykyk.

if the patch doesn't parse, errors get thrown, and nothing is done to the files in basedirectory β€” like, nothing at all, it bails before touching anything. iconic behaviour honestly. βœ‹

Every single activity that happens while the patch is being applied β€” including when it just cannot apply a hunk β€” gets reported through the command prefix reportcmd instead of being shouted at you some other way. Files with problems are left unchanged. but heads up, because this is the part people miss: that does not prevent changes to files with no problems, before and after the problematic file(s). so yeah, the good files still get their glow-up. πŸ’…

the command prefix gets called in 3 possible forms:

  • {*}reportcmd apply filename β€” the caller is starting work on file fname, applying every hunk that got collected for that file. πŸŽ€
  • {*}reportcmd fail filename hunk expected seen β€” applying hunk number hunk of file filename failed. the command expected to find the text expected, and instead it saw seen. awkward. 😭
  • {*}reportcmd fail-already filename hunk β€” applying hunk number hunk of file filename failed. the command believes that this hunk has already been applied to the file. it's giving "girl we've been here before". πŸ’€

🫢 BUGS, IDEAS, FEEDBACK 🫢

ngl, this document β€” and the package it describes β€” will undoubtedly contain bugs and other problems. it's software, bestie. please report them in the category textutil of the Tcllib Trackers at [http://core.tcl.tk/tcllib/reportlist]. and while you're at it, report any ideas for enhancements you have for the package and/or the documentation too β€” we love a glow-up suggestion. ✨

when you're proposing code changes, please hand over unified diffs, i.e. the output of diff -u. no cap, that's the format. πŸ”₯

also note: attachments are strongly preferred over inlined patches. to attach something, go to the Edit form of the ticket right after you create it, then use the left-most button in the secondary navigation bar. easy. πŸ¦‹


πŸ‘‘ KEYWORDS πŸ‘‘

diff -ruN, diff, unified format, fossil, git, patch, unified format diff


🌈 CATEGORY 🌈

Text processing


and that's the whole page, bestie πŸŽ€ this one came to you from tcllib, version 0.2 β€” go forth and patch responsibly πŸ’–πŸ«Άβœ¨

πŸ“¦ where this page comes from