3

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

誰かがそれをする方法を知っていますか?

4

4 に答える 4

6

私はTMateSoftwareの人々と話をしましたが、これは確かに可能であるようです。彼らが説明したように、はい、ローカルファイルを使用して新しいコンテンツでチェックサムを生成し、それをSubversionに送信できますが、(もしあれば)これはSubversionがローカルコピーに正しく最新のものがあることを確認するのに役立つだけです。結局のところ、Subversionはとにかく独自のdiffとdeltaを実行します。

したがって、ローカルコピーがない場合は、ファイルが新しいものであるかのようにチェックサムを作成できます。これが私の大きなプロジェクトから抽出した大まかなコードです。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();

コミットエディタを取得した後、何か問題が発生した場合に編集を中止できるように、すべてcloseEdit()を1つのブロックにまとめることを忘れないでください。try...catch

私はこれを試しましたが、SVNKIt 1.3.7(Mavenなど)を使用したすべてのテストに合格しています。

<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>
于 2011-12-28T21:44:09.743 に答える
0

本当に方法はありません。基本的に、SVNはcheckout-edit-commitモデルで動作します。それをあなたから隠すアプリがあるかもしれませんが、それらはまだ舞台裏で一時的なディレクトリなどへのチェックアウトを実行しています。

于 2011-01-17T09:24:55.353 に答える
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());

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

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サンプルコードから:

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();
}
于 2011-04-06T19:06:32.497 に答える
-2

理論的にはこれは実行可能であるはずですが、実際にはSVNKitを使用することは不可能のようです。

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

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

于 2011-01-17T12:20:14.897 に答える