Manual templates override generated code from nodegit while generating source code. They really should be avoid untill absolutely necessary.
Everytime the library switches between C land and the javascript thread, there is a penalty in performance. If in practice the usage of a method in libgit2 requires crossing the c/javascript boundary frequently, it might be better option to use manual templates. An example being
Revwalk::FastWalk.
The generated code sometimes does not handle structures that are interdependent. An example would be
git_patchandgit_diff. Agit_patch's memory is owned bygit_diff, and that includes all of the children ofgit_patch, as well. So agit_diff_hunk,git_diff_line, andgit_patchall are owned by agit_diff, and when thatgit_diffis deleted, all the memory for any patches, hunks, or lines that are in use as NodeGitWrappers are now corrupted. Further, agit_diffkeeps a file handle open for its entire lifespan, which can lead to NodeGit holding onto file locks in Windows. Due to both of these compounding issues, we wrote manual templates to shift ownership away from agit_difftogit_patch,git_diff_hunk, andgit_diff_lineand also shorten the lifespan of a diff.
If a new pattern exists in libgit that would be difficult to implement using generated code, manual templates can be used for one-off cases. Typically generated code takes care of most patterns seen in libgit, but if function signatures do not follow typical pattern, manual templates could be used. Example:
git_filterandgit_remote_ls.
----- ## Implementing manual templates
*.cc files -> /generate/templates/manual/src/
*.h files -> /generate/templates/manual/include/
location: /generate/templates/templates/binding.gyp
location: /generate/templates/templates/nodegit.cc
use rawApi.ManualWrapper reference to add _ManualWrapper
add any js wrapper (if any) via importExtension