How do I determine if a directory is part of a Subversion working copy?

2024-09-24 Thread Vincent Lefevre
How do I determine if a directory is part of a Subversion working copy?

This is the same question as on

  
https://stackoverflow.com/questions/7172334/how-do-i-determine-if-a-directory-is-part-of-a-subversion-working-copy

but all the answers there except mine are incorrect.

The issue is that one needs to distinguish 3 cases, not 2!

1. Positive answer.
2. Negative answer.
3. Arbitrary error.

So, solutions based on "svn info 2> /dev/null" are incorrect as they
cannot distinguish case 2 and case 3. The error message is important.

I was using such a solution, and it took me some time to find the
cause of an unexpected negative answer: I had a concurrent "svn up"
running in another shell (which I forgot as it was lengthy).

I could check that this was indeed a plausible cause:

joooj:~/wd> while svn info > /dev/null ; do true; done
svn: E200033: Another process is blocking the working copy database, or the 
underlying filesystem does not support file locking; if the working copy is on 
a network filesystem, make sure file locking has been enabled on the file server
svn: E200033: sqlite[S5]: database is locked, executing statement 'PRAGMA 
case_sensitive_like=1;PRAGMA synchronous=OFF;PRAGMA 
recursive_triggers=ON;PRAGMA foreign_keys=OFF;PRAGMA locking_mode = 
NORMAL;PRAGMA journal_mode = TRUNCATE;'

when doing "svn up" in another shell.

So I proposed the following script:


#!/bin/sh

err=$(LC_ALL=C svn info "$1" 2>&1 >/dev/null)

if [ $? = 0 ]; then
  echo yes
  exit 0
fi

case $err in
  *"is not a working copy")
echo no
exit 0 ;;
esac

printf "%s\n" "$err" >&2
exit 1


But is there a better solution?

Checking the error message might not be future-proof.

-- 
Vincent Lefèvre  - Web: 
100% accessible validated (X)HTML - Blog: 
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


Re: How do I determine if a directory is part of a Subversion working copy?

2024-09-24 Thread Yasuhito FUTATSUKI
Hello,

On 2024/09/25 9:17, Vincent Lefevre wrote:

 > Checking the error message might not be future-proof.

Then, check the error code instead.

e.g. with Python bindings:
[[[
import sys
from svn import core, client

def is_path_within_wc(path):
ret = True
try:
client.get_wc_root(core.svn_path_canonicalize(path),
   client.create_context())
except core.SubversionException as e:
if e.apr_err == core.SVN_ERR_WC_NOT_WORKING_COPY:
ret = False
else:
raise(e)
return ret

if __name__ == '__main__':
if len(sys.argv) != 2:
print('Usage: %s ' % sys.argv[0])
exit(2)
try:
print('yes' if is_path_within_wc(sys.argv[1]) else 'no')
except Exception as e:
print('error:', e)
exit(1)
]]]

Cheers,
-- 
Yasuhito FUTATSUKI 


Re: How to delete fiiles on the server that were accidentally part of an import?

2024-09-24 Thread Bo Berglund
On Tue, 24 Sep 2024 06:42:15 +, "Lorenz via users"
 wrote:

>Bo Berglund wrote:
>
>>I used the following command to import a folder with files into Subversion
>>without having to create a checked out copy of the new server side folder.
>>All of this on a single line in Windows cmd:
>>
>>
>>svn import LocalFolderName
>>https://oursvnservername/svn/pc/Name_of_project/tags/Name_of_project_6-3-3 -m
>>"Importing Name_of_project 6.3.3 for use when building the installers"
>>
>>After it completed I discovered that a few files that were *not* part of the
>>project to import were accidentally present in the local source folder...
>>
>>So now I wonder how I can delete these files *on the server* without first
>>checking out the project and svn remove them?
>>
>>Is there a corresponding server side delete that does not require a local copy
>>first?
>>
>>In the SvnBook I found this example, which I do not really understand:
>>
>>Deleting a URL, however, is immediate, so you have to supply a log message:
>>
>>$ svn delete -m "Deleting file 'yourfile'" \
>> file:///var/svn/repos/test/yourfile
>>
>>Committed revision 15.
>>
>>
>>I don't understand how the syntax should be especially the use of the 
>>backslash.
>>Why is that there?
>>
>>And my server target is *not* a file: rather it is an https URL as shown above
>>in my import command.
>>
>>Please explain.
>
>- regarding repo access URLs:
>https://svnbook.red-bean.com/nightly/en/svn.basic.in-action.html#svn.basic.in-action.wc.tbl-1
>
>- are you aware that svn delete removes its target from HEAD revision?
>The file/folder will still be in the repo and accessable going back in
>history.

I know that but I wanted to remove these files because they are not really part
of the fileset I need to be there. So in order to get a clean checkout/export I
needed to delete them.
Does not matter if they still remain in the repo in an earlier revision because
HEAD is what will always be used. They are support files for a build process.

I looked in my bookmarked version of the svnbook:
https://svnbook.red-bean.com/en/1.8/svn.ref.svn.c.delete.html

Here the URL delete command is described as follows:

$ svn delete -m "Deleting file 'yourfile'" \
 file:///var/svn/repos/test/yourfile

And that did not make sense to me because file: is NOT in my view an URL and
also because they had entered a \ in the middle of the command, which also does
not make sense to me...

But I tested with this instead (as I wrote in my next post):

svn delete -m "Deleting file xxx"
https://svnserver/svn/repo/tags/nameofproject/filetodelete

And this dis the job.


-- 
Bo Berglund
Developer in Sweden



Re: How to delete fiiles on the server that were accidentally part of an import?

2024-09-24 Thread Daniel Sahlberg
Den tis 24 sep. 2024 kl 09:30 skrev Bo Berglund :

> Here the URL delete command is described as follows:
>
> $ svn delete -m "Deleting file 'yourfile'" \
>  file:///var/svn/repos/test/yourfile
>
> And that did not make sense to me because file: is NOT in my view an URL
> and
> also because they had entered a \ in the middle of the command, which also
> does
> not make sense to me...
>

file:// is a URL with the protocol "file:", just as http:// is a URL with
the protocol "http:". It is meant to be adjusted to whatever the URL is for
your repository. Remember that SVN can use at least five different
protocols so any one chosen would be "wrong" for a majority of the readers,
but other examples use both http://, svn:// and svn+ssh://.

The backslash character is a continuation character used in many Unix
shells to break up the command to several separate lines. It is used to
indicate "don't expect that you can press enter after the log message and
enter the URL on the next line". As someone pointed out ^ can be used in
Windows for the same function.

I'd be happy if we can improve the book to be more clear in this regard -
feel free to make a suggestion.

Kind regards,
Daniel