1

JGit ライブラリを使用して、Android フォンのドキュメントをサーバーに同期しようとしています。

それはほとんど機能します...しかし、コミットを機能させることができません。コミットを試みるたびに、「データ エラー」という例外が発生します。問題を org.eclipse.jgit.util.IO の次のステートメントまで追跡しました。

public static void readFully(final InputStream fd, final byte[] dst,
        int off, int len) throws IOException {
    while (len > 0) {
        final int r = fd.read(dst, off, len);
        if (r <= 0)
            throw new EOFException(JGitText.get().shortReadOfBlock);
        off += r;
        len -= r;
    }
}

行 fd.read(dst, off, len) は実行をスローします。fd パラメータは InflaterInputStream だと思うので、このコードは圧縮されたアーカイブから読み取ろうとします。

Android 2.2 を搭載した HTC Desire Z でこれを実行しようとしています。

私は org.eclipse.jgit-0.12.1.jar と com.jcraft.jsch_0.1.31.jar を使用して jgit 機能にアクセスしています。

問題を理解するためにいくつかのテスト例を作成しました

次のコードは、私の Windows XP マシンで問題なく実行されます。

public class Test {
/**
 * @param args
 */
public static void main(String[] args) {
    try {
        // Create a new directory
        File dirF = new File("C:\\Test\\TestDir");
        dirF.mkdir();
        log(">>> Created directory.\n");

        // Initialize git repository
        InitCommand init = Git.init();
        File initFile = new File("C:\\Test\\TestDir");
        init.setDirectory(initFile);
        init.call();
        log(">>> Git Init done.\n");

        // Create a file
        File newfile = new File("C:\\Test\\TestDir\\myfile.txt");
        newfile.createNewFile();
        PrintStream os = new PrintStream(newfile);
        os.println("Some text");
        os.close();
        log(">>> File created.\n");

        // Add to git
        FileRepositoryBuilder builder = new FileRepositoryBuilder();
        File f = new File("C:\\Test\\TestDir\\.git");
        Repository db = builder.setGitDir(f)
        .findGitDir() // scan up the file system tree
        .build();
        Git git = new Git(db);
        AddCommand add = git.add();
        add.addFilepattern(".").call();
        log(">>> Git Add done.\n");

        // Commit the change
        CommitCommand commit = git.commit();
        commit.setAll(true);
        commit.setMessage("A JGit message");
        commit.call();
        log(">>> Git Commit done.\n");

        // Check the log
        for (RevCommit c : git.log().call()) {
            log(c.getId() + "/" + c.getAuthorIdent().getName() + "/"
                    + c.getShortMessage());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}
private static void log(String s) {
    System.out.print(s);
}

}

次のコードは、Android フォンで例外をスローします。

public class JGitSimpleAndroidActivity extends Activity {
StringBuilder sb;
TextView tv;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    sb = new StringBuilder();
    tv = new TextView(this);
    try {
        // Create a new directory
        File sdCard;
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            sdCard = Environment.getExternalStorageDirectory();
        } else {
            log(">>> SD card is not available.");
            return;
        }
        File dirF = new File(sdCard,"TestDir");
        dirF.mkdir();
        log(">>> Created directory.\n");

        // Initialize git repository
        InitCommand init = Git.init();
        init.setDirectory(dirF);
        init.call();
        log(">>> Git Init done.\n");

        // Create a file
        File newfile = new File(dirF,"myfile.txt");
        newfile.createNewFile();
        PrintStream os = new PrintStream(newfile);
        os.println("Some text");
        os.close();
        log(">>> File created.\n");

        // Add to git
        FileRepositoryBuilder builder = new FileRepositoryBuilder();
        File f = new File(dirF,".git");
        Repository db = builder.setGitDir(f)
        .findGitDir() // scan up the file system tree
        .build();
        Git git = new Git(db);
        AddCommand add = git.add();
        add.addFilepattern(".").call();
        log(">>> Git Add done.\n");

        // Commit the change
        CommitCommand commit = git.commit();
        commit.setAll(true);
        commit.setMessage("A JGit message");
        commit.call(); // >>>>>>>> EXCEPTION THROWN HERE <<<<<<<
        log(">>> Git Commit done.\n");

        // Check the log
        for (RevCommit c : git.log().call()) {
            log(c.getId() + "/" + c.getAuthorIdent().getName() + "/"
                    + c.getShortMessage());
        }
    } catch (Exception e) {
        log(e.getMessage());
    }
}
private void log(String s) {
    sb.append(s);
    sb.append('\n');
    tv.setText(sb);
    setContentView(tv);
}
}

これを機能させるために何ができるかについてのアイデアはありますか?

よろしく、 アンダース

4

1 に答える 1

0

涼しい!

このパッチを試してください: (おそらく空白が破損しているため、そのまま適用しても機能しない場合があります)

   diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java index 4b9c572..4e38747 100644
    --- a/org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java
    +++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/IO.java @@ -214,7 +214,7 @@ public static void readFully(final InputStream fd, final byte[] dst,
                            int off, int len) throws IOException {
                    while (len > 0) {
                            final int r = fd.read(dst, off, len);
    -                       if (r <= 0)
    +                       if (r < 0)
                                    throw new EOFException(JGitText.get().shortReadOfBlock);
                            off += r;
                            len -= r; 
@@ -242,7 +242,7 @@ public static void skipFully(final InputStream fd, long toSkip)
                            throws IOException {
                    while (toSkip > 0) {
                            final long r = fd.skip(toSkip);
    -                       if (r <= 0)
    +                       if (r < 0)
                                    throw new EOFException(JGitText.get().shortSkipOfBlock);                          
                            toSkip -= r;
                }
于 2011-05-23T17:41:26.043 に答える