You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Dmitry Pavlenko <pa...@tmatesoft.com> on 2018/07/19 17:57:05 UTC

[PATCH] Re: Directory becomes file when applying patch

Hello, Julian!
I've checked that the latest trunk version skips the directory in this case 
(much better than making it a file). So I'm not sure if it is possible to turn 
it into directory addition at all.

Anyway I've created a test for the case. I'm not 100% sure in the expected 
output/disk/status of the test but from the first glance it looks ok.

The test fails because it expects a directory with a property to be created 
but it is skipped.
-- 
Dmitry Pavlenko,
TMate Software,
http://subgit.com/ - git-svn bridge

> Hello!
> When I apply Git format patch that adds a directory with properties, a file
> is added instead.
> 
> Here I provide a reproducing script and also add a file for comparison.
> 
> I think the origin of the problem in the fact that SVN patch doesn't keep
> "node kind". But a patch in "svn diff --git" format does. Here's the example
> of the patch. Notice
> 
>  a) "Property changes on: dir" and "Property changes on: file" lines;
>  b) "new file mode 10644" for file and no such line for directory;
> 
> allowing to distinguish between files and directories.
> 
> I don't know whether it's a known issue or not but I think it would be nice
> to infer "node kind" from that information and also (if this is not already
> done) by the following logic: if patch changes "dir" and "dir/someFile",
> then "dir" is probably a directory.
> 
> 
> Index: /tmp/wc/dir
> ===================================================================
> diff --git a/dir b/dir
> --- a/dir       (nonexistent)
> +++ b/dir       (working copy)
> 
> Property changes on: dir
> ___________________________________________________________________
> Added: propName
> ## -0,0 +1 ##
> +propValue
> \ No newline at end of property
> Index: /tmp/wc/file
> ===================================================================
> diff --git a/file b/file
> new file mode 10644
> 
> Property changes on: file
> ___________________________________________________________________
> Added: propName
> ## -0,0 +1 ##
> +propValue
> \ No newline at end of property
> 
> 
> 
> The reproducing script:
> 
> 
> #!/bin/sh
> 
> SVN=svn
> 
> #1. Create an empty SVN repository.
> 
> REPOSITORY_PATH="$PWD/svn.repo"
> 
> svnadmin create "$REPOSITORY_PATH"
> 
> # 2. Add a file with properties and a directory with properties to the
> repository.
> 
> WC_PATH="/tmp/wc"
> REPOSITORY_URL="file://$REPOSITORY_PATH"
> 
> $SVN co $REPOSITORY_URL $WC_PATH
> 
> touch $WC_PATH/file
> 
> $SVN add $WC_PATH/file
> $SVN mkdir $WC_PATH/dir
> 
> $SVN propset propName propValue $WC_PATH/file
> $SVN propset propName propValue $WC_PATH/dir
> 
> # 3. Create diff between repository HEAD and working copy:
> 
> PATCH_FILE=/tmp/patch
> 
> $SVN diff --git $REPOSITORY_URL $WC_PATH > $PATCH_FILE
> 
> # 4. Cleanup the working copy
> 
> $SVN revert $WC_PATH/file
> $SVN revert $WC_PATH/dir
> 
> rm $WC_PATH/file
> rmdir $WC_PATH/dir
> 
> # 5. Apply the patch back:
> 
> $SVN patch $PATCH_FILE $WC_PATH
> 
> # 6. Make sure that the file is file and that dir is directory
> 
> FILE_TYPE=`stat -c "%F" $WC_PATH/file`
> DIRECTORY_TYPE=`stat -c "%F" $WC_PATH/dir`
> 
> if [ "$FILE_TYPE" != "regular empty file" ] ; then
>   echo "================"
>   echo "File is not file but $FILE_TYPE"
>   echo "================"
> fi
> 
> if [ "$DIRECTORY_TYPE" != "directory" ] ; then
>   echo "================"
>   echo "Dir is not directory but $DIRECTORY_TYPE"
>   echo "================"
> fi


Re: [PATCH] Re: Directory becomes file when applying patch

Posted by Julian Foad <ju...@apache.org>.
Dmitry Pavlenko wrote:
> I've checked that the latest trunk version skips the directory in this case 
> (much better than making it a file). So I'm not sure if it is possible to turn 
> it into directory addition at all.
> 
> Anyway I've created a test for the case. I'm not 100% sure in the expected 
> output/disk/status of the test but from the first glance it looks ok.

You know what? I think 'patch' should not infer that the item being patched is a directory just because it has no 'file mode' line. I take back what I wrote about the 'file mode' line being 'the right information to use'. Only when it is present, then it is the right information to use.

We don't currently have a way to tell 'patch' whether to expect a git-format or Subversion-format or old-fashioned patch. It is supposed to guess based on the input. In this case, the input does not have enough information to say it is meant to be creating a directory.

The patch format needs to be augmented to explicitly indicate operations on directories.

When a patch does not include a 'mode' line, then as you said a patch command could use heuristics to determine it is a directory in some cases, if child paths appear in the patch. However, I don't want us to spend effort on heuristics, I want us to spend the effort on making an exact (explicit) format.

I think the testable bug at this stage is that 'svn diff --git' for a directory modification writes a patch that looks the same as for a file modification. You could write a test for that, but we already know that support for directories in patches (both git-format and svn format) is an enhancement that has not been designed yet.

So I suggest we close this issue.

Does that make sense?

-- 
- Julian