Syntax for Code Change Specifications

Black Hole

May contain traces of nut
#1
I'm sure it means everything to those "in the know", and I realise the likes of the following is probably a dump from some kind of automatic differences process, but in detail - how does one interpret these lines, and how would one implement the specified changes (manually with a text editor, presumably)? EG (from https://hummy.tv/forum/threads/yout...com-or-other-video-platforms.8462/post-122500):
Code:
--- /mod/etc/init.d/S00swapper~
+++ /mod/etc/init.d/S00swapper
@@ -1,8 +1,7 @@
#!/bin/sh

-[ "`cat /etc/model`" = "HDR" ] || exit 0
-
swapfile=/mnt/hd3/.swap0
+[ "`cat /etc/model`" = "HD" ] && swapfile=/media/drive1/.swap0

case "$1" in
     start)
OK, so the first two lines are probably the 'before' and 'after' files. We then have some gobbledygook prefixed "@@". Then there are lines to remove prefixed "-" and lines to add prefixed "+", but the exact detail is not obvious without some guidance.

Besides implementing the changes in an editor, maybe there's a tool which can apply them automatically?
 

prpr

Well-Known Member
#2
the following is probably a dump from some kind of automatic differences process
From "diff -u oldfile newfile"
how does one interpret these lines, and how would one implement the specified changes (manually with a text editor, presumably)?
Yes, a text editor. Basically, get rid of the lines which start with '-' and add those which start with '+'. The others are just for context.

Or you can copy the above to a temporary file e.g. /tmp/patch and then run e.g. patch -i /tmp/patch to do it automatically.
 
OP
OP
Black Hole

Black Hole

May contain traces of nut
#3
Thanks for that. The details are here (see section "Unified Mode"): https://www.computerhope.com/unix/udiff.htm

Output from command diff -u <file1> <file2> :

--- <file1>
+++ <file2>
[1..n]{change_description_block}

Where:

{change_description_block} =

{line_no_descriptor}​
<lines_displayed_for_context>​
-<line_present_in_file1_but_not_file2>​
+<line_present_in_file2_but_not_file1>​
<lines_displayed_for_context>​

{line_no_descriptor} =

@@ -<n1s>,<n1c> +<n2s>,<n2c> @@​

<n1s> = Starting line number in <file1> that the change description block applies to;
<n1c> = Number of lines in <file1> that the change description block applies to;
<n2s> = Starting line number in <file2> that the change description block applies to;
<n2c> = Number of lines in <file2> that the change description block applies to.

Note: Starting line numbers and line counts include the context lines.
 
Last edited:
Top