[svnbook] r4058 committed - Finish issue #117 ("1.7 change: New 'svn patch' subcommand")....

svnbook at googlecode.com svnbook at googlecode.com
Fri Sep 2 14:44:25 CDT 2011


Revision: 4058
Author:   cmpilato at gmail.com
Date:     Fri Sep  2 12:43:35 2011
Log:      Finish issue #117 ("1.7 change: New 'svn patch' subcommand").

* en/book/ch09-reference.xml
   (svn.ref.svn.c.patch): Flesh out this section.

http://code.google.com/p/svnbook/source/detail?r=4058

Modified:
  /trunk/en/book/ch09-reference.xml

=======================================
--- /trunk/en/book/ch09-reference.xml	Thu Sep  1 10:52:03 2011
+++ /trunk/en/book/ch09-reference.xml	Fri Sep  2 12:43:35 2011
@@ -3796,12 +3796,92 @@
          </refnamediv>
          <refsect1>
            <title>Synopsis</title>
-          <para><literal>svn patch PATCHFILE [PATH]</literal></para>
+          <para><literal>svn patch PATCHFILE [WCPATH]</literal></para>
          </refsect1>
          <refsect1>
            <title>Description</title>

-          <para>### TODO ###</para>
+          <para>This subcommand will apply changes described a
+            unidiff-formatted patch
+            file <replaceable>PATCHFILE</replaceable> to the working
+            copy <replaceable>WCPATH</replaceable>.  As with most
+            other working copy subcommands,
+            if <replaceable>WCPATH</replaceable> is omitted, the
+            changes are applied to the current working directory.  A
+            unidiff patch suitable for application to a working copy
+            can be produced with the <command>svn diff</command>
+            command or third-party differencing tools.  Any
+            non-unidiff content found in the patch file is
+            ignored.</para>
+
+          <para>Changes listed in the patch file will either be
+            applied or rejected.  If a change does not match at its
+            exact line offset, it may be applied earlier or later in
+            the file if a match is found elsewhere for the surrounding
+            lines of context provided by the patch.  A change may also
+            be applied with <firstterm>fuzz</firstterm>—meaning,
+            one or more lines of context are ignored when attempting
+            to match the change location.  If no matching context can
+            be found for a change, the change conflicts and will be
+            written to a reject file which bears the extension
+            <filename>.svnpatch.rej</filename>.</para>
+
+          <para><command>svn patch</command> reports a status line for
+            patched file or directory using letter codes, very similar
+            to the way that <command>svn update</command> provides
+            notification.  The letter codes have the following
+            meanings:</para>
+
+          <variablelist>
+
+            <varlistentry>
+              <term><literal>A</literal></term>
+              <listitem>
+                <para>Added</para>
+              </listitem>
+            </varlistentry>
+
+            <varlistentry>
+              <term><literal>D</literal></term>
+              <listitem>
+                <para>Deleted</para>
+              </listitem>
+            </varlistentry>
+
+            <varlistentry>
+              <term><literal>C</literal></term>
+              <listitem>
+                <para>Conflicted</para>
+              </listitem>
+            </varlistentry>
+
+            <varlistentry>
+              <term><literal>G</literal></term>
+              <listitem>
+                <para>Merged</para>
+              </listitem>
+            </varlistentry>
+
+            <varlistentry>
+              <term><literal>U</literal></term>
+              <listitem>
+                <para>Updated</para>
+              </listitem>
+            </varlistentry>
+
+          </variablelist>
+
+          <para>Changes applied with an offset or fuzz are reported on
+            lines starting with the '<literal>></literal>'
+            symbol. You should review such changes carefully.</para>
+
+          <para>If the patch removes all content from a file, that
+            file is automatically scheduled for deletion.  Likewise,
+            if the patch creates a new file, that file is
+            automatically scheduled for addition.  Use <command>svn
+            revert</command> to undo undesired deletions and
+            additions.</para>
+
          </refsect1>

          <refsect1>
@@ -3821,7 +3901,129 @@
          <refsect1>
            <title>Examples</title>

-          <para>### TODO ###</para>
+          <para>Apply a simple patch file generated by
+            the <command>svn diff</command> command.  Our patch file
+            will create a new file, delete another file, and modify a
+            third's contents and properties.  Here's the patch file
+            itself (which we'll assume is creatively named
+            <filename>PATCH</filename>):</para>
+
+          <informalexample>
+            <programlisting>
+Index: deleted-file
+===================================================================
+--- deleted-file	(revision 3)
++++ deleted-file	(working copy)
+@@ -1 +0,0 @@
+-This file will be deleted.
+Index: changed-file
+===================================================================
+--- changed-file	(revision 4)
++++ changed-file	(working copy)
+@@ -1,6 +1,6 @@
+ The letters in a line of text
+ Could make your day much better.
+ But expanded into paragraphs,
+-I'd tell of kangaroos and calves
++I'd tell of monkeys and giraffes
+ Until you were all smiles and laughs
+ From my letter made of letters.
+
+Property changes on: changed-file
+___________________________________________________________________
+Added: propname
+## -0,0 +1 ##
++propvalue
+Index: added-file
+===================================================================
+--- added-file	(revision 0)
++++ added-file	(working copy)
+@@ -0,0 +1 @@
++This is an added file.
+</programlisting>
+          </informalexample>
+
+          <para>We can apply the previous patch file to another
+            working copy from our repository using <command>svn
+            patch</command>, and verify that it did the right thing by
+            using <command>svn diff</command>:</para>
+
+          <informalexample>
+            <screen>
+$ cd /some/other/workingcopy
+$ svn patch /path/to/PATCH
+D         deleted-file
+UU        changed-file
+A         added-file
+$ svn diff
+Index: deleted-file
+===================================================================
+--- deleted-file	(revision 3)
++++ deleted-file	(working copy)
+@@ -1 +0,0 @@
+-This file will be deleted.
+Index: changed-file
+===================================================================
+--- changed-file	(revision 4)
++++ changed-file	(working copy)
+@@ -1,6 +1,6 @@
+ The letters in a line of text
+ Could make your day much better.
+ But expanded into paragraphs,
+-I'd tell of kangaroos and calves
++I'd tell of monkeys and giraffes
+ Until you were all smiles and laughs
+ From my letter made of letters.
+
+Property changes on: changed-file
+___________________________________________________________________
+Added: propname
+## -0,0 +1 ##
++propvalue
+Index: added-file
+===================================================================
+--- added-file	(revision 0)
++++ added-file	(working copy)
+@@ -0,0 +1 @@
++This is an added file.
+$
+</screen>
+          </informalexample>
+
+          <para>Sometimes you might need Subversion to interpret a
+            patch <quote>in reverse</quote>—where added things
+            get treated as removed things, and vice-versa.  Use
+            the <option>--reverse-diff</option> option for this
+            purpose.  In the following example, we'll squirrel away
+            a patch file which describes the changes in our working
+            copy, and then use a reverse patch operation to undo those
+            changes.</para>
+
+          <informalexample>
+            <screen>
+$ svn status
+M       foo.c
+$ svn diff > PATCH
+$ cat PATCH
+Index: foo.c
+===================================================================
+--- foo.c	(revision 128)
++++ foo.c	(working copy)
+@@ -1003,7 +1003,7 @@
+     return ERROR_ON_THE_G_STRING;
+
+   /* Do something in a loop. */
+-  for (i = 0; i < txns->nelts; i++)
++  for (i = 0; i < txns->nelts; i--)
+     {
+       status = do_something(i);
+       if (status)
+$ svn patch --reverse-diff PATCH
+U         foo.c
+$ svn status
+$
+</screen>
+          </informalexample>

          </refsect1>
        </refentry>




More information about the svnbook-dev mailing list