2011-03-28 6 views
2

SVN 저장소를 사용하여 일부 메트릭을 수집하기 위해 SVN 키트를 사용하고 있습니다. 나는이 간단한 문제에 붙어있어 그것을 통과 할 수 없다.svnkit을 사용하여 파일의 이전 수정본 수정

나는 저에게 저장소에있는 모든 파일과 그들의 다른 개정판의 경로를 알려주는 SVNRepository 객체를 가지고 있습니다. 각 개정마다 이전 개정 값을 설정하고 싶습니다. 파일을 체크 아웃하지 않고 어떻게 할 수 있습니까? 아니면 내 코드에서 최상의 성능을 발휘할 수있는 최선의 방법은 무엇입니까?

또한 이전 버전을 할당 할 때 복사/붙여 넣기 및 이동 작업을 고려해야합니다.

답변

3

다음 기술이 저에게 효과적이었습니다.

//This is where I query SVN server 
if (entryPath.getType() != SVNLogEntryPath.TYPE_ADDED) { 
    LogEntryPreviousRevFinder handler = new LogEntryPreviousRevFinder(workingFileName.substring(interestingPath.length()), thisRevision); 

    //Start checking for previous modified revision for this file in the previous 3 revision. 
    //If not found try for previous 5 and then 7. If not found till then, put in a warning and continue. 
    //This is necessary because in SVN a branch operation is performed at the folder level and not file 
    //hence we need to go further back and find out the revision than was last modified. 
    for (int i = 3; i <= 7; i+=2) { 
     repository.log(new String[] {workingFileName}, thisRevision, 0l, true, false, i, handler); 
     if (handler.isSuccess()) { 
      prevPath = handler.getPreviousPath(); 
      prevRevision = handler.getPreviousRevision(); 
      break; 
     } else { 
      continue; 
     } 
    } 

    if (!handler.isSuccess()) { 
     log.warn("Failed to find previous revision for file: " + workingFileName 
       + " Will contine considering this one as added in this revision"); 
    } 
} else { 
    //Files with SVNLogEntryPath.TYPE_ADDED are either added in this revision 
    //or are copied or renamed from an existing file. If later, we need to identify the Copy from path 
    //as that will be the file which will be used for calculating relative metrics and later Flux values 
    if (entryPath.getCopyPath() != null && entryPath.getCopyPath().trim().length() > 0) { 
     prevPath = entryPath.getCopyPath(); 
     prevRevision = entryPath.getCopyRevision(); 
    } else { 
     log.debug("File: " + workingFileName + " added in this revision"); 
    } 
} 

ISVNLogEntryHandler 구현 :이 작업을 수행 할 수있는 더 나은 및 더 효율적인 방법이 있는지

//ISVNLogEntryHandler implementation for identifying previous revision 
private class LogEntryPreviousRevFinder implements ISVNLogEntryHandler { 
    private String interestingFile; 
    private String previousPath; 
    private long thisRevision; 
    private long previousRevision; 
    private boolean isSuccess; 

    public LogEntryPreviousRevFinder(String interestingFile, long revision) { 
     this.interestingFile = interestingFile; 
     this.thisRevision = revision; 
     isSuccess = false; 
    } 

    @Override 
    public void handleLogEntry(SVNLogEntry logEntry) throws SVNException { 
     if (isSuccess) 
      return; 

     if (thisRevision == logEntry.getRevision()) 
      return; 

     Set changedPathsSet = logEntry.getChangedPaths().keySet(); 
     for (Iterator changedPaths = changedPathsSet.iterator(); changedPaths.hasNext();) { 
      SVNLogEntryPath entryPath = (SVNLogEntryPath) logEntry.getChangedPaths().get(changedPaths.next()); 
      String workingFileName = entryPath.getPath(); 

      if (workingFileName.endsWith(interestingFile)) { 
       previousRevision = logEntry.getRevision(); 
       previousPath = workingFileName; 
       isSuccess = true; 
      } 
     } 
    } 

    public long getPreviousRevision() { 
     return previousRevision; 
    } 
    public String getPreviousPath() { 
     return previousPath; 
    } 
    public boolean isSuccess() { 
     return isSuccess; 
    } 
} 

이 궁금하다.

관련 문제