2011-01-17 2 views
3

私はSVNKitを使用して、私たちのリポジトリからファイルの内容を取得しています。コード内でその内容を変更して、最初にファイルをチェックアウトせずに変更を元に戻したいと思います。私はすでにWebを検索し、ローカルファイルシステムへのチェックアウトを必要とするソリューションしか見つけられませんでした。ローカルチェックアウトなしでSVNKit経由で変更されたファイルをコミットしていますか?

誰でもその方法を知っていますか?

答えて

-2

これは実現可能なはずですが、実際にはSVNKitを使用することは不可能です。

私はすべてのチェックイン操作が直接または間接的にorg.tmatesoft.svn.core.wc.SVNCommitItemにあり、このクラスではコンストラクタ内に作業コピーファイルパスが必要であることがわかります。

このクラスをオーバーライドして、作業コピーを必要としない独自のバージョンを実装しようとするかもしれませんが、詳細はチェックしていません。

+0

そのヒントありがとう! – RobertB

0

本当に方法はありません。基本的に、SVNはチェックアウト編集コミットモデルで動作します。あなたにそれを隠すアプリがあるかもしれませんが、引き続きチェックアウトを行っています。舞台裏の一時的なディレクトリ。

+0

私は、これは、本質的にSVNが動作する方法であることを知っています。しかし、SVNKitのような図書館はこれを完全に回避することができます。 – RobertB

+0

オリですが、これは真実ではありません。エンドユーザの観点からは実際にはチェックアウト/編集/コミットモデルがありますが、Subversionプロトコルは呼び出し元をそのモデルに限定しません。上記のOscarの例は、ファイルを最初にチェックアウトせずにコミットを実行する方法を示しています.'oldData 'をデルタジェネレータに渡しますが、これは必須ではありません。デルタは「以前の」バージョンを参照しない可能性があります。 –

0

私はちょうど試しました。変更するファイルのバイト数を取得できます。メモリ内の内容を変更します。最後に、コードをチェックインします。 ======================================

byte[] in = checkOutPom(project+"/"+ destinationPathQualifier + tag+ "/pom.xml"); 
BufferedReader bin = new BufferedReader(new InputStreamReader(
       new ByteArrayInputStream(in))); 
MyPomHandler h = new MyPomHandler(); //replaces strings in the file 
ByteArrayOutputStream os = new ByteArrayOutputStream(); 
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
       os)); 
h.replace(bin, writer, "1.0.0-SNAPSHOT", tag); 
ISVNEditor editor = getRepository().getCommitEditor(
       "Patching POM with tag:"+tag, null); 
modifyFile(editor, project + "/" + destinationPathQualifier + tag, project + "/" + destinationPathQualifier + tag+"/pom.xml",in, os.toByteArray()); 

:ここにsnipedです=============

public byte[] checkOutPom(String filename) 
      throws SVNException { 
    SVNProperties fileProperties = new SVNProperties(); 
    ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
    getRepository().getFile(filename, -1, fileProperties, baos); 
    return baos.toByteArray(); 
} 

============================== ====================

svnkitサンプルコードから

:私はTMate Softwareの人たちに話を聞いた

public SVNCommitInfo modifyFile(ISVNEditor editor, String dirPath, 
      String filePath, byte[] oldData, byte[] newData) 
      throws SVNException { 
    editor.openRoot(-1);  
    editor.openDir(dirPath, -1);  
    editor.openFile(filePath, -1); 
    editor.applyTextDelta(filePath, null); 
    SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator(); 
    String checksum = deltaGenerator.sendDelta(filePath, 
       new ByteArrayInputStream(oldData), 0, new ByteArrayInputStream(
         newData), editor, true);  
    editor.closeFile(filePath, checksum); 
    editor.closeDir(); 
    editor.closeDir(); 
    return editor.closeEdit(); 
} 
6

、そしてあるようです確かに可能です。彼らが説明したとおり、ローカルファイルを使用して新しいコンテンツでチェックサムを生成し、それをSubversionに送信することができます(もしあれば)。これはSubversionがあなたのローカルコピー。その日の終わりに、Subversionはとにかく独自のdiffsとdeltasを実行します。

ローカルコピーがない場合は、あたかもファイルが新しいものであるかのようにチェックサムを作成するだけです。私の大きなプロジェクトから抜粋した、大まかなコードです。ファイルがすでに存在するかどうかが分かっている場合は、事前にSVNDirEntryを確認する必要はありません。私は説明のためにここに提供しています。

SVNDirEntry dirEntry = svnRepository.info(filePath, -1); 
ISVNEditor editor = svnRepository.getCommitEditor("example modification", null, true, null); 
editor.openRoot(-1); 
if(dirEntry.getKind() == SVNNodeKind.NONE) 
{ 
    editor.addFile(filePath, null, -1); 
} 
else 
{ 
    editor.openFile(filePath, -1); 
} 
editor.applyTextDelta(filePath, null); 
final SVNDeltaGenerator deltaGenerator = new SVNDeltaGenerator(); 
final String checksum = deltaGenerator.sendDelta(filePath, inputStream, editor, true); 
editor.closeFile(filePath, checksum); 
editor.closeDir(); //close the root 
editor.closeEdit(); 

は、何かがうまくいかない場合は、編集を中止することができるようtry...catchブロックにcloseEdit()にすべてを包むために、コミットエディタを取得した後、忘れてはいけません。

私はこれを試してみたのだが、(例えば、Mavenのから)SVNKIt 1.3.7を使用して、すべての私のテストに合格:

<repositories> 
    <repository> 
     <id>svnkit-repository</id> 
     <name>SVNKit Repository</name> 
     <url>http://maven.tmatesoft.com/content/repositories/releases/</url> 
    </repository> 
</repositories> 
... 
<dependency> 
    <groupId>org.tmatesoft.svnkit</groupId> 
    <artifactId>svnkit</artifactId> 
    <version>1.3.7</version> 
</dependency> 
関連する問題