need solution for an unusual use case

View: New views
6 Messages — Rating Filter:   Alert me  

need solution for an unusual use case

by Gowri :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,

I suppose this is not at all a common problem and I am not sure how to
solve this but here's what I do:

I use the java library from tmatesoft to do a commit of some files
from a tool that I'm writing. basically, the user uses this tool to
trigger a simulation which writes some files to a directory. Now, the
user expects the tool to add all of these files to SVN. If the files
are modified (by hand or by changing some parameters on teh GUI whose
values go into some files) then the user would like to commit them
again by using this tool.

My problem is:
Adding files for the first time is easy enough but how do I update
files later (because the users do not check out these output files and
hence we do not have a concept of working copies)

I'd really appreciate all the help I can get.

Regards,
Gowri

Re: need solution for an unusual use case

by Alexander Kitaev-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

 > My problem is:
 > Adding files for the first time is easy enough but how do I update
 > files later (because the users do not check out these output files and
 > hence we do not have a concept of working copies)
So, am I understand correctly that your question is how to distinguish
locally modified files from those not modified?

If that is correct then there are two basic ways of doing that. First,
you may compare file checksum (MD5 digest) with one stored on the server
side (in repository) for that file. In case checksum differs, then file
is modified.

Another approach is to provide some sort of "working copy", e.g. store
checked out files revisions, timestamps and checksums locally (it not
necessary have to be some folder, it could be a separate file or
database). Then you may use this information to check whether file was
locally modified or not.

To commit modified file, you may use the following code (I'll skip most,
only leave code that is relevant to file modification):

editor.openFile(path, -1);
editor.applyTextDelta(path, null);
SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator( );
String checksum = deltaGenerator.
     sendDelta(path , newFileContents /* InputStream */, editor , true);
editor.textDeltaEnd(path);
editor.closeFile(path, textChecksum)


Alexander Kitaev,
TMate Software,
http://svnkit.com/ - Java [Sub]Versioning Library!

Gowri wrote:

> Hi all,
>
> I suppose this is not at all a common problem and I am not sure how to
> solve this but here's what I do:
>
> I use the java library from tmatesoft to do a commit of some files
> from a tool that I'm writing. basically, the user uses this tool to
> trigger a simulation which writes some files to a directory. Now, the
> user expects the tool to add all of these files to SVN. If the files
> are modified (by hand or by changing some parameters on teh GUI whose
> values go into some files) then the user would like to commit them
> again by using this tool.
>
> My problem is:
> Adding files for the first time is easy enough but how do I update
> files later (because the users do not check out these output files and
> hence we do not have a concept of working copies)
>
> I'd really appreciate all the help I can get.
>
> Regards,
> Gowri

Re: need solution for an unusual use case

by Gowri :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Alexander,

I modified my code to do what you suggested but was faced a 'recv failed' exception. I read all the posts I could find related to the subject and they all seemed to point to errors while specifying the path to the file being modified. Here's my code:

                                String path = "file.log";
                                SVNNodeKind nodeKind3 = repository.checkPath(path, -1);
                                ISVNEditor editor = repository.getCommitEditor(
                                                "updating files", null);
                                editor.openRoot(-1);

                                try {
                                        editor.openFile(path, -1);
                                        editor.applyTextDelta(path, null);
                                        SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();
                                        String checksum = deltaGenerator
                                                        .sendDelta(path, new FileInputStream(new File(
                                                                        "C:\\test\\file.log")), editor, true);
                                        editor.textDeltaEnd(path);
                                        editor.closeFile(path, checksum);
                                } catch (Exception e) {
                                        e.printStackTrace();
                                }

nodeKind3 correctly prints "file". I don't know what I'm doing wrong here (file.log is directly under the root.) Could you please help?

Regards,
Gowri


Alexander Kitaev-3 wrote:
Hello,

 > My problem is:
 > Adding files for the first time is easy enough but how do I update
 > files later (because the users do not check out these output files and
 > hence we do not have a concept of working copies)
So, am I understand correctly that your question is how to distinguish
locally modified files from those not modified?

If that is correct then there are two basic ways of doing that. First,
you may compare file checksum (MD5 digest) with one stored on the server
side (in repository) for that file. In case checksum differs, then file
is modified.

Another approach is to provide some sort of "working copy", e.g. store
checked out files revisions, timestamps and checksums locally (it not
necessary have to be some folder, it could be a separate file or
database). Then you may use this information to check whether file was
locally modified or not.

To commit modified file, you may use the following code (I'll skip most,
only leave code that is relevant to file modification):

editor.openFile(path, -1);
editor.applyTextDelta(path, null);
SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator( );
String checksum = deltaGenerator.
     sendDelta(path , newFileContents /* InputStream */, editor , true);
editor.textDeltaEnd(path);
editor.closeFile(path, textChecksum)


Alexander Kitaev,
TMate Software,
http://svnkit.com/ - Java [Sub]Versioning Library!

Gowri wrote:
> Hi all,
>
> I suppose this is not at all a common problem and I am not sure how to
> solve this but here's what I do:
>
> I use the java library from tmatesoft to do a commit of some files
> from a tool that I'm writing. basically, the user uses this tool to
> trigger a simulation which writes some files to a directory. Now, the
> user expects the tool to add all of these files to SVN. If the files
> are modified (by hand or by changing some parameters on teh GUI whose
> values go into some files) then the user would like to commit them
> again by using this tool.
>
> My problem is:
> Adding files for the first time is easy enough but how do I update
> files later (because the users do not check out these output files and
> hence we do not have a concept of working copies)
>
> I'd really appreciate all the help I can get.
>
> Regards,
> Gowri

Re: need solution for an unusual use case

by Alexander Kitaev-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

It seems that I made a small mistake in the sample code: you shouldn't
call editor.textDeltaEnd(...) - it is called inside SVNDeltaGenerator();

Also, you should add the following lines to your code:

editor.closeDir(); // for openRoot
editor.closeEdit();

to commit transaction. Please, let me know if it resolves the problem -
I couldn't test the code right now, so may be it still miss something -
I'll test it tomorrow myself as well.

Alexander Kitaev,
TMate Software,
http://svnkit.com/ - Java [Sub]Versioning Library!

Gowri wrote:

> Hi Alexander,
>
> I modified my code to do what you suggested but was faced a 'recv failed'
> exception. I read all the posts I could find related to the subject and they
> all seemed to point to errors while specifying the path to the file being
> modified. Here's my code:
>
>                                 String path = "file.log";
> SVNNodeKind nodeKind3 = repository.checkPath(path, -1);
> ISVNEditor editor = repository.getCommitEditor(
> "updating files", null);
> editor.openRoot(-1);
>
> try {
> editor.openFile(path, -1);
> editor.applyTextDelta(path, null);
> SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();
> String checksum = deltaGenerator
> .sendDelta(path, new FileInputStream(new File(
> "C:\\test\\file.log")), editor, true);
> editor.textDeltaEnd(path);
> editor.closeFile(path, checksum);
> } catch (Exception e) {
> e.printStackTrace();
> }
>
> nodeKind3 correctly prints "file". I don't know what I'm doing wrong here
> (file.log is directly under the root.) Could you please help?
>
> Regards,
> Gowri
>
>
>
> Alexander Kitaev-3 wrote:
>> Hello,
>>
>>  > My problem is:
>>  > Adding files for the first time is easy enough but how do I update
>>  > files later (because the users do not check out these output files and
>>  > hence we do not have a concept of working copies)
>> So, am I understand correctly that your question is how to distinguish
>> locally modified files from those not modified?
>>
>> If that is correct then there are two basic ways of doing that. First,
>> you may compare file checksum (MD5 digest) with one stored on the server
>> side (in repository) for that file. In case checksum differs, then file
>> is modified.
>>
>> Another approach is to provide some sort of "working copy", e.g. store
>> checked out files revisions, timestamps and checksums locally (it not
>> necessary have to be some folder, it could be a separate file or
>> database). Then you may use this information to check whether file was
>> locally modified or not.
>>
>> To commit modified file, you may use the following code (I'll skip most,
>> only leave code that is relevant to file modification):
>>
>> editor.openFile(path, -1);
>> editor.applyTextDelta(path, null);
>> SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator( );
>> String checksum = deltaGenerator.
>>      sendDelta(path , newFileContents /* InputStream */, editor , true);
>> editor.textDeltaEnd(path);
>> editor.closeFile(path, textChecksum)
>>
>>
>> Alexander Kitaev,
>> TMate Software,
>> http://svnkit.com/ - Java [Sub]Versioning Library!
>>
>> Gowri wrote:
>>> Hi all,
>>>
>>> I suppose this is not at all a common problem and I am not sure how to
>>> solve this but here's what I do:
>>>
>>> I use the java library from tmatesoft to do a commit of some files
>>> from a tool that I'm writing. basically, the user uses this tool to
>>> trigger a simulation which writes some files to a directory. Now, the
>>> user expects the tool to add all of these files to SVN. If the files
>>> are modified (by hand or by changing some parameters on teh GUI whose
>>> values go into some files) then the user would like to commit them
>>> again by using this tool.
>>>
>>> My problem is:
>>> Adding files for the first time is easy enough but how do I update
>>> files later (because the users do not check out these output files and
>>> hence we do not have a concept of working copies)
>>>
>>> I'd really appreciate all the help I can get.
>>>
>>> Regards,
>>> Gowri
>>
>

Re: need solution for an unusual use case

by Gowri :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Alexander,

removing editor.textDeltaEnd(...) worked :) What exactly does this do anyway? It was weird. I used to get recv failed if I stepped through the code and connection reset or malformed network data if I ran my old code. Thank you so much for your help. Really appreciate it.

Regards,
Gowri

Alexander Kitaev-3 wrote:
Hello,

It seems that I made a small mistake in the sample code: you shouldn't
call editor.textDeltaEnd(...) - it is called inside SVNDeltaGenerator();

Also, you should add the following lines to your code:

editor.closeDir(); // for openRoot
editor.closeEdit();

to commit transaction. Please, let me know if it resolves the problem -
I couldn't test the code right now, so may be it still miss something -
I'll test it tomorrow myself as well.

Alexander Kitaev,
TMate Software,
http://svnkit.com/ - Java [Sub]Versioning Library!

Gowri wrote:
> Hi Alexander,
>
> I modified my code to do what you suggested but was faced a 'recv failed'
> exception. I read all the posts I could find related to the subject and they
> all seemed to point to errors while specifying the path to the file being
> modified. Here's my code:
>
>                                 String path = "file.log";
> SVNNodeKind nodeKind3 = repository.checkPath(path, -1);
> ISVNEditor editor = repository.getCommitEditor(
> "updating files", null);
> editor.openRoot(-1);
>
> try {
> editor.openFile(path, -1);
> editor.applyTextDelta(path, null);
> SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();
> String checksum = deltaGenerator
> .sendDelta(path, new FileInputStream(new File(
> "C:\\test\\file.log")), editor, true);
> editor.textDeltaEnd(path);
> editor.closeFile(path, checksum);
> } catch (Exception e) {
> e.printStackTrace();
> }
>
> nodeKind3 correctly prints "file". I don't know what I'm doing wrong here
> (file.log is directly under the root.) Could you please help?
>
> Regards,
> Gowri
>
>
>
> Alexander Kitaev-3 wrote:
>> Hello,
>>
>>  > My problem is:
>>  > Adding files for the first time is easy enough but how do I update
>>  > files later (because the users do not check out these output files and
>>  > hence we do not have a concept of working copies)
>> So, am I understand correctly that your question is how to distinguish
>> locally modified files from those not modified?
>>
>> If that is correct then there are two basic ways of doing that. First,
>> you may compare file checksum (MD5 digest) with one stored on the server
>> side (in repository) for that file. In case checksum differs, then file
>> is modified.
>>
>> Another approach is to provide some sort of "working copy", e.g. store
>> checked out files revisions, timestamps and checksums locally (it not
>> necessary have to be some folder, it could be a separate file or
>> database). Then you may use this information to check whether file was
>> locally modified or not.
>>
>> To commit modified file, you may use the following code (I'll skip most,
>> only leave code that is relevant to file modification):
>>
>> editor.openFile(path, -1);
>> editor.applyTextDelta(path, null);
>> SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator( );
>> String checksum = deltaGenerator.
>>      sendDelta(path , newFileContents /* InputStream */, editor , true);
>> editor.textDeltaEnd(path);
>> editor.closeFile(path, textChecksum)
>>
>>
>> Alexander Kitaev,
>> TMate Software,
>> http://svnkit.com/ - Java [Sub]Versioning Library!
>>
>> Gowri wrote:
>>> Hi all,
>>>
>>> I suppose this is not at all a common problem and I am not sure how to
>>> solve this but here's what I do:
>>>
>>> I use the java library from tmatesoft to do a commit of some files
>>> from a tool that I'm writing. basically, the user uses this tool to
>>> trigger a simulation which writes some files to a directory. Now, the
>>> user expects the tool to add all of these files to SVN. If the files
>>> are modified (by hand or by changing some parameters on teh GUI whose
>>> values go into some files) then the user would like to commit them
>>> again by using this tool.
>>>
>>> My problem is:
>>> Adding files for the first time is easy enough but how do I update
>>> files later (because the users do not check out these output files and
>>> hence we do not have a concept of working copies)
>>>
>>> I'd really appreciate all the help I can get.
>>>
>>> Regards,
>>> Gowri
>>
>

Re: need solution for an unusual use case

by Alexander Kitaev-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

editor.textDeltaEnd have to be called - the problem in my sample code
was that it was called _twice_ - first time from the code and second
time from SVNDeltaGenerator.sendDelta method - this makes svnserve
daemon fail as it was not what it expected to receive.

Alexander Kitaev,
TMate Software,
http://svnkit.com/ - Java [Sub]Versioning Library!

Gowri wrote:

> Hi Alexander,
>
> removing editor.textDeltaEnd(...) worked :) What exactly does this do
> anyway? It was weird. I used to get recv failed if I stepped through the
> code and connection reset or malformed network data if I ran my old code.
> Thank you so much for your help. Really appreciate it.
>
> Regards,
> Gowri
>
>
> Alexander Kitaev-3 wrote:
>> Hello,
>>
>> It seems that I made a small mistake in the sample code: you shouldn't
>> call editor.textDeltaEnd(...) - it is called inside SVNDeltaGenerator();
>>
>> Also, you should add the following lines to your code:
>>
>> editor.closeDir(); // for openRoot
>> editor.closeEdit();
>>
>> to commit transaction. Please, let me know if it resolves the problem -
>> I couldn't test the code right now, so may be it still miss something -
>> I'll test it tomorrow myself as well.
>>
>> Alexander Kitaev,
>> TMate Software,
>> http://svnkit.com/ - Java [Sub]Versioning Library!
>>
>> Gowri wrote:
>>> Hi Alexander,
>>>
>>> I modified my code to do what you suggested but was faced a 'recv failed'
>>> exception. I read all the posts I could find related to the subject and
>>> they
>>> all seemed to point to errors while specifying the path to the file being
>>> modified. Here's my code:
>>>
>>>                                 String path = "file.log";
>>> SVNNodeKind nodeKind3 = repository.checkPath(path, -1);
>>> ISVNEditor editor = repository.getCommitEditor(
>>> "updating files", null);
>>> editor.openRoot(-1);
>>>
>>> try {
>>> editor.openFile(path, -1);
>>> editor.applyTextDelta(path, null);
>>> SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator();
>>> String checksum = deltaGenerator
>>> .sendDelta(path, new FileInputStream(new File(
>>> "C:\\test\\file.log")), editor, true);
>>> editor.textDeltaEnd(path);
>>> editor.closeFile(path, checksum);
>>> } catch (Exception e) {
>>> e.printStackTrace();
>>> }
>>>
>>> nodeKind3 correctly prints "file". I don't know what I'm doing wrong here
>>> (file.log is directly under the root.) Could you please help?
>>>
>>> Regards,
>>> Gowri
>>>
>>>
>>>
>>> Alexander Kitaev-3 wrote:
>>>> Hello,
>>>>
>>>>  > My problem is:
>>>>  > Adding files for the first time is easy enough but how do I update
>>>>  > files later (because the users do not check out these output files
>>>> and
>>>>  > hence we do not have a concept of working copies)
>>>> So, am I understand correctly that your question is how to distinguish
>>>> locally modified files from those not modified?
>>>>
>>>> If that is correct then there are two basic ways of doing that. First,
>>>> you may compare file checksum (MD5 digest) with one stored on the server
>>>> side (in repository) for that file. In case checksum differs, then file
>>>> is modified.
>>>>
>>>> Another approach is to provide some sort of "working copy", e.g. store
>>>> checked out files revisions, timestamps and checksums locally (it not
>>>> necessary have to be some folder, it could be a separate file or
>>>> database). Then you may use this information to check whether file was
>>>> locally modified or not.
>>>>
>>>> To commit modified file, you may use the following code (I'll skip most,
>>>> only leave code that is relevant to file modification):
>>>>
>>>> editor.openFile(path, -1);
>>>> editor.applyTextDelta(path, null);
>>>> SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator( );
>>>> String checksum = deltaGenerator.
>>>>      sendDelta(path , newFileContents /* InputStream */, editor , true);
>>>> editor.textDeltaEnd(path);
>>>> editor.closeFile(path, textChecksum)
>>>>
>>>>
>>>> Alexander Kitaev,
>>>> TMate Software,
>>>> http://svnkit.com/ - Java [Sub]Versioning Library!
>>>>
>>>> Gowri wrote:
>>>>> Hi all,
>>>>>
>>>>> I suppose this is not at all a common problem and I am not sure how to
>>>>> solve this but here's what I do:
>>>>>
>>>>> I use the java library from tmatesoft to do a commit of some files
>>>>> from a tool that I'm writing. basically, the user uses this tool to
>>>>> trigger a simulation which writes some files to a directory. Now, the
>>>>> user expects the tool to add all of these files to SVN. If the files
>>>>> are modified (by hand or by changing some parameters on teh GUI whose
>>>>> values go into some files) then the user would like to commit them
>>>>> again by using this tool.
>>>>>
>>>>> My problem is:
>>>>> Adding files for the first time is easy enough but how do I update
>>>>> files later (because the users do not check out these output files and
>>>>> hence we do not have a concept of working copies)
>>>>>
>>>>> I'd really appreciate all the help I can get.
>>>>>
>>>>> Regards,
>>>>> Gowri
>>
>