Using Javacvs to interact with CVS from Java programming. Problem in remove file.

Posted on 2005-04-21
Last Modified: 2012-05-05

Hi All,

I am using JavaCvs (cvs client library - NetBeans ) in my java application to communicate with CVS repository. My Add, update, checkout, checkin operations seems to be working fine. But when I remove a file using RemoveCommand, the file seems to be removed. But If i upload another file with the same name into the same directory path , for some reason instead of uploading the new file its  getting back (recovering) the previous file. I don't know why its doing that. Below is the example to illustrate the problem better.

1) Added a file A.txt using AddCommand to CVS.  (Say file A.txt's content A#).

2) Viewed the file A.txt. It showed the content A#

3) Removed the file using RemoveCommand followed by CommitCommnad from CVS.

4) Modified the file A.txt (Say file A.txt's content B#) in my local dir.

5) Added the file A.txt to CVS using AddCommand.

6) Viewed the file A.txt. It showed the content A# instead of B#. Its not adding the new file instead its considering (recovering) the old file it seems.

I did the above operations from Java program using netbean's javacvs api. I don't gave any local working folder, as i am using cvs to store some documents.

I don't know why its behaving that way. Please help me resolve this issue.

Thanks in advance.

Here is my code for removeing the file from cvs.

                  c = new PServerConnection();


                  RPCvsClient client = new RPCvsClient(c, new RPAdminHandler());
                  client.getEventManager().addCVSListener(new BasicListener());
                  Entry ent = new Entry();
                  ByteArrayOutputStream streamForCVS = null;
                  client.setEntry(null, ent);

                  StatusCommand command = new StatusCommand();
                  GlobalOptions globalOptions = new GlobalOptions();
                  client.executeCommand(command, globalOptions);
                  StatusBuilder sb = (StatusBuilder) command.getBuilder();
                  StatusInformation si = sb.getStatusInformation();
                  if ( si != null )
                  String repositoryVersionOfFileToBeDeleted = si.getRepositoryRevision();

                  ent = new Entry();
                  ByteArrayOutputStream stream = null;
                  client.setEntry(null, ent);      
                  RemoveCommand removeCommand = new RemoveCommand();
                  globalOptions = new GlobalOptions();
                  client.executeCommand(removeCommand, globalOptions);

                  //      Now commit the delete
                  client = new RPCvsClient(c, new RPAdminHandler());
                  client.getEventManager().addCVSListener(new BasicListener());
                  ent = new Entry();
                  stream = new ByteArrayOutputStream();      //      faking out the file
                  client.setEntry(null, ent);      //      no need to set the file. hence set to null.
                  CommitCommand commitCommand = new CommitCommand();
                  globalOptions = new GlobalOptions();
                  client.executeCommand(commitCommand, globalOptions);

Question by:shilpa_rajith
    LVL 92

    Assisted Solution

    Where do you remove the local copy?
    Also could be related to the remove, remove the file for the repository, but not removing the history.
    LVL 15

    Assisted Solution

    Never used this API but based on command line CVS don't you need to call
    client.executeCommand() with CommitCommand
    after you called client.executeCommand(removeCommand, globalOptions) ?

    Author Comment


    Thanks for the response.

    Hi Objects,

    In my application the users will upload their documents. Behind the scene I am storing the documents in CVS. So when the users upload their documents,  the application will add them to CVS. When the user wants to view them, then the app will get it from CVS and show them. Basically its kind of document management. So i don't have a local copy as such here. OR i don't know if i am missing something here.

    How do i remove the file from History ??

    Hi aozarov,

    I am calling client.executeCommand() with CommitCommand after RemoveCommand. You can find that at the botton of my code.

    Thanks in advance.

    LVL 15

    Accepted Solution

    >> I am calling client.executeCommand() with CommitCommand after RemoveCommand. You can find that at the botton of my code.
    As I said, I never dealt with this api but should you do that before you close the client ( your call c.close(); right after the remove)?

    >> How do i remove the file from History ??
    You can do that, when using cvs client, via the admin command:
    C:\java-temp>c:\cygwin\bin\cvs -H admin
    Usage: cvs admin [options] files...
     -o range   Delete (outdate) specified range of revisions...
    But I don't think this is your problem.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now