Get all revisions from a (deleted) file

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

Get all revisions from a (deleted) file

by Sandro F :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello all,

I want to get a revision list of a collection of files in my repository. I try something like this where "filename" stands for the file in the collection:

            long count = 1;
            long fromRevision = 0;
            long toRevision = repos.getLatestRevision();
            String url = filename;
            final List logEntries = new ArrayList();
            if (count > 0) {
                repos.log(new String[]{url}, fromRevision, toRevision, false, false, count,
                        new ISVNLogEntryHandler() {

                            public void handleLogEntry(SVNLogEntry logEntry) {
                                logEntries.add(logEntry);
                            }
                        });
            }

I also try this code:

            Collection revisions =  repos.getFileRevisions(url, (Collection) null, 0, repos.getLatestRevision());

            for (Iterator revs = revisions.iterator(); revs.hasNext();) {
               SVNFileRevision fileRevision = (SVNFileRevision) revs.next();
                /* Some private classes...
                DataRevision revision = new DataRevision();
                revision.setRevision(fileRevision.getRevision());
                ret.add(revision);*/
            }

Both code snippets work fine for files which were not deleted in a newer revision of the repository. I get the following error for deleted files:

svn: '/test/commit/dir2/test.doc2' is not a file in revision 265 svn: REPORT of '/svn/pis/!svn/bc/265': 500 Internal Server Error

I simply want to get all revisions from a file whether or not the file exists in the HEAD-revision of the repository.


Thanks and best regards,
Sandro Frenzel

Re: Get all revisions from a (deleted) file

by Alexander Kitaev-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello Sandro,

Log method requires target file to exist in at least one of the
revisions specified. In case file doesn't exist, log operation will fail.

The reason for that behavior is that in repository history there could
be multiple files with the same path, each with its own history
independent on history of others. For example, you may have the
following history:

r1: A /dir/file.txt
r2: M /dir/file.txt
r3: D /dir/file.txt
...
r7: A /dir/file.txt (from /dir/source.txt)
r8: M /dir/file.txt
r9: D /dir/file.txt
...

In the above example there are two different files with path
'/dir/file.txt' - first is just added and then deleted and second copied
from another file and then deleted. If you call "log -rHEAD:0
/dir/file.txt" SVNKit (and Subversion) will not know what file do you
mean (as path does not exist nor in 0, neither in HEAD and there is no
sort of 'hook' to follow file history from).

So, in such situation (when file doesn't exist in start and end
revisions of the log range) you should specify so called 'peg' revision.
In the above example the following two commands will give different results:

svn log -r0:HEAD /dir/file.txt@2
svn log -r0:HEAD /dir/file.txt@8

SVNRepository.log doesn't support peg revision - it is supported in the
higher level API, that first locates exact revisions range in which file
exist using pegRevision and SVNRepository.getLocations(...) method and
then calls SVNRepository.log method.

For you probably using SVNLogClient.doLog method will be more convenient:

        SVNClientManager manager = SVNClientManager.newInstance();
        SVNLogClient logClient = manager.getLogClient();
        SVNURL url =
SVNURL.parseURIEncoded("http://svn.svnkit.com/repos/svnkit/trunk");
        logClient.doLog(url, new String[] {"REMARKS.txt"},
                SVNRevision.create(4000), /* peg revision */
                SVNRevision.UNDEFINED,    /* start, defaults to peg */
                SVNRevision.UNDEFINED,    /* end, defaults to 0 */
                false, /* stop on copy */
                false, /* include paths */
                true,  /* include mergeinfo */
                -1,  /* no limit */
                null, /* all revprops*/
                new ISVNLogEntryHandler() {
                    public void handleLogEntry(SVNLogEntry logEntry)
throws SVNException {
                        System.out.println(logEntry.getRevision());
                    }
                });

And still file must exist in start or end revision, this is Subversion
limitation. To get revision in which file was deleted (if it was) you
may run log on its parent directory (or grandparent if parent also
deleted) - this will give you an information on revision in which target
file was deleted and so you'll get proper revision range to call log on.

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

Sandro F wrote:

> Hello all,
>
> I want to get a revision list of a collection of files in my repository. I
> try something like this where "filename" stands for the file in the
> collection:
>
>             long count = 1;
>    long fromRevision = 0;
>    long toRevision = repos.getLatestRevision();
>    String url = filename;
>    final List logEntries = new ArrayList();
>    if (count > 0) {
> repos.log(new String[]{url}, fromRevision, toRevision, false, false,
> count,
> new ISVNLogEntryHandler() {
>
>    public void handleLogEntry(SVNLogEntry logEntry) {
> logEntries.add(logEntry);
>    }
> });
>    }
>
> I also try this code:
>
>    Collection revisions =  repos.getFileRevisions(url, (Collection) null,
> 0, repos.getLatestRevision());
>
>    for (Iterator revs = revisions.iterator(); revs.hasNext();) {
>       SVNFileRevision fileRevision = (SVNFileRevision) revs.next();
> /* Some private classes...
>                 DataRevision revision = new DataRevision();
> revision.setRevision(fileRevision.getRevision());
> ret.add(revision);*/
>    }
>
> Both code snippets work fine for files which were not deleted in a newer
> revision of the repository. I get the following error for deleted files:
>
> svn: '/test/commit/dir2/test.doc2' is not a file in revision 265 svn: REPORT
> of '/svn/pis/!svn/bc/265': 500 Internal Server Error
>
> I simply want to get all revisions from a file whether or not the file
> exists in the HEAD-revision of the repository.
>
>
> Thanks and best regards,
> Sandro Frenzel
>

---------------------------------------------------------------------
To unsubscribe, e-mail: svnkit-users-unsubscribe@...
For additional commands, e-mail: svnkit-users-help@...