Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No output when calling callMain with args #91

Open
williamfzc opened this issue Jan 18, 2024 · 3 comments
Open

No output when calling callMain with args #91

williamfzc opened this issue Jan 18, 2024 · 3 comments

Comments

@williamfzc
Copy link

williamfzc commented Jan 18, 2024

This project is really cool. Thanks for all your work!

I have followed some related issues (#80) to capture the output, which working fine in some simple cases.

But it seems not work if I sending some args together.

// OK
lg.callMain(["log"])
// NO OUTPUT
lg.callMain(["log", "-p"])

Full snippet:

const lg = require('./node_modules/wasm-git/lg2.js');
let stdout;


lg["print"] = function (text) {
    console.log(text);
}

lg["printErr"] = function (text) {
    console.error(text);
}

lg.onRuntimeInitialized = () => {
    const FS = lg.FS;
    const NODEFS = FS.filesystems.NODEFS;

    FS.mkdir('/working');
    FS.mount(NODEFS, {root: '..'}, '/working');
    FS.chdir('/working');

    const gitConfigContent = '[user]\n' +
        'name = Test User\n' +
        'email = [email protected]\n' +
        '[safe]\ndirectory = *\n';

    FS.writeFile('/home/web_user/.gitconfig', gitConfigContent, (err) => {
        if (err) throw err;
        console.log('File has been saved!');
    });

    console.log(FS.readdir('.'));

    // OK
    lg.callMain(["log"])
    // NO OUTPUT
    lg.callMain(["log", "-p"])
};
@petersalomonsen
Copy link
Owner

Sorry for the late reply, but thanks for nice feedback!

The log command comes directly from here: https://github.com/libgit2/libgit2/blob/main/examples/log.c#L473

Can you try compiling the libgit2 examples directly ( as native, not as Wasm ) and see if the -p switch works there? Either it's missing in the example from libgit2, or it might not work when used in Wasm ( but I doubt that ). For everything that I've been missing from the libgit2 examples, I've added to the libgit2patchedfiles/examples folder, but as you can see I haven't patched the log command. It comes directly out of libgit2.

@williamfzc
Copy link
Author

Thanks for your reply!
Unfortunately I only have my laptop nearby which has no any compile env. :(

But I do some search in libgit2 and find this:

libgit2/libgit2#4209

which may can indicate the original example working fine.

@petersalomonsen
Copy link
Owner

That links also says it takes longer time with libgit2 than with normal git. Does it make any difference with a small vs a larger repository?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants