SVNKit

Posted by Bruce Tsai
06/22/2016

在開發時期原始碼控制已是不可少的一部份,大部份的人應該都會使用 IDE 或 GUI 工具來進行諸如 commitupdate 等的操作,也有一部份人慣用指令列來操作功能。但若要使用程式來進行原始碼的提交或更新,一個方法是透過 command 來組合出需要執行的操作,另一種方式則是透過 SVNKit 這樣的工具來處理程式碼的處理。對於需要以程式來進行操作的需求,可以少去不少組合指令的麻煩。

範例

//initiate the reporitory from the url
SVNRepository repository = SVNRepositoryFactory.create(SVNURL.parseURIDecoded(url));
//create authentication data
ISVNAuthenticationManager authManager =
        SVNWCUtil.createDefaultAuthenticationManager("cliff.darling", "svnuser");
repository.setAuthenticationManager(authManager);
//output some data to verify connection
System.out.println("Repository Root: " + repository.getRepositoryRoot(true));
System.out.println("Repository UUID: " + repository.getRepositoryUUID(true));
//need to identify latest revision
long latestRevision = repository.getLatestRevision();
System.out.println("Repository Latest Revision: " + latestRevision);

//create client manager and set authentication
SVNClientManager ourClientManager = SVNClientManager.newInstance();
ourClientManager.setAuthenticationManager(authManager);
//use SVNUpdateClient to do the export
SVNUpdateClient updateClient = ourClientManager.getUpdateClient();
updateClient.setIgnoreExternals(false);
updateClient.doExport(repository.getLocation(), new File(destPath),
        SVNRevision.create(latestRevision), SVNRevision.create(latestRevision),
        null, true, SVNDepth.INFINITY);

results matching ""

    No results matching ""