开发者

How can I get all revisions (not latest) for a special file using SVNkit?

开发者 https://www.devze.com 2023-04-02 03:10 出处:网络
I have used a sample java code to get a file\'s revision history, but only got one revision. There are many revisions in respository for this file. So how can I get all revisions for this file at o开发

I have used a sample java code to get a file's revision history, but only got one revision. There are many revisions in respository for this file. So how can I get all revisions for this file at o开发者_StackOverflownce?

…
long startRevision = -1;
long endRevision = 0; //HEAD (i.e. the latest) revision

SVNRepositoryFactoryImpl.setup();
repository = SVNRepositoryFactory.create( SVNURL.parseURIEncoded(url) );
ISVNAuthenticationManager authManager = 
         SVNWCUtil.createDefaultAuthenticationManager( name, password );
repository.setAuthenticationManager( authManager );

Collection logEntries = null;
logEntries = repository.log( new String[] { "EJB.java" }, null, startRevision,
                             endRevision, true, true );
…


Use 0 for start revision and -1 for end revision


Get the logs and get revisions using those logEntries

SVNRepository repository = null;
            repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url));
            ISVNAuthenticationManager authManager =
                               SVNWCUtil.createDefaultAuthenticationManager("", "");
            repository.setAuthenticationManager(authManager);
            SvnOperationFactory operationFactory = new SvnOperationFactory();
            SvnLog logOperation = operationFactory.createLog();
            logOperation.setSingleTarget(
                    SvnTarget.fromURL(
                            SVNURL.parseURIEncoded(url)));
            logOperation.setRevisionRanges( Collections.singleton(
                    SvnRevisionRange.create(
                            SVNRevision.create( 1 ),
                            SVNRevision.HEAD
                    )
            ) );
            Collection<SVNLogEntry> logEntries = logOperation.run( null );

Now iterate throught the logEntries and use logEntry.getRevision() to get all the revisions till date.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号