[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

issue 3459 - svn patch does not tolerate empty lines

From: Daniel Näslund <daniel_at_longitudo.com>
Date: Wed, 5 Aug 2009 22:46:44 +0200

Hi!
[Sorry for not putting the shell script as an attachment. Could not
create a new thread with mutt.]

I'm getting a conflict when using svn patch with the shell script
below. According to the issue all lines after the empty line should be
ignored. Did I do something wrong?

My explanation to the behavior is that svn patch in
subversion/libsvn_client/patch.c (match_hunk) only compares hunk lines
that begin with '-' or ' '. I must add a ' ' if the hunk line does not
begin with one.

#!/bin/sh
# Tries to apply a diff where leading space on one line is dropped.

BASE_DIR=~/Code/Subversion/trunk

SVN=${BASE_DIR}/subversion/svn/svn
SVNADMIN=${BASE_DIR}/subversion/svnadmin/svnadmin

URL=file:///`pwd`/repos

rm -rf repos wc* import-me

${SVNADMIN} create repos
mkdir import-me;
cd import-me;
cat >> foo << EOF

bar
baz
EOF

${SVN} import -q -m "" ${URL}/trunk
cd ..;

${SVN} co ${URL}/trunk wc -q
cd wc
cat > foo << EOF
foo

EOF

${SVN} di > p
${SVN} revert foo;

# Remove the space from the empty line in the diff
cat p | sed -e "s/^[ ]$//" > p2

${SVN} patch p2
cat foo

My first ideas briefly (not implemented):
* subversion/libsvn_diff/parse_diff.c
 (svn_diff__parse_next_hunk): Allow empty lines to be part of hunk.
  Should use some library function.

* subversion/libsvn_client/patch.c
  (apply_one_hunk): Allow for applying diffs with fuzz. Issue 3460.

* subversion/libsvn_client/patch.c
  (match_hunk): Right now it demands that hunk lines begin with ' ' or
    '-' and that the hunk line is one character longer than the target line.
    That must be fixed.

Am I on the right track?

My idea for allowing empty lines:

Index: subversion/libsvn_diff/parse-diff.c
===================================================================
--- subversion/libsvn_diff/parse-diff.c (revision 38568)
+++ subversion/libsvn_diff/parse-diff.c (arbetskopia)
@@ -358,7 +358,10 @@
             }

           c = line->data[0];
- if (c == ' ' || c == '-' || c == '+')
+ if (c == ' ' || c == '-' || c == '+'
+ || (line->len == 1 && c == '\n')
+ || (line->len == 1 && c == '\r')
+ || (line->len == 2 && c == '\r' && line->data[1] == '\n'))
             hunk_seen = TRUE;
           else

Mvh
Daniel

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2380627
Received on 2009-08-05 22:47:25 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.