Correct way to obtain the git tree of a remote branch with libgit2 - libgit2

I am trying to diff my HEAD with a remote branch using tree to tree comparison. To obtain the remote tree, I first tried using git_tree_lookup by passing the remote object obtained through git_revparse_single. This fails, even if I connect and fetch the remote beforehand.
However, if after checking, I cast the object pointer to a git_commit * and use git_commit_tree instead, it succeeds and returns me the remote tree.
Why does one way work and the other not?

Because git_revparse_single on a reference will return you a git_commit, not a git_tree. And you cannot cast a git_commit to a git_tree.
You are correct to look up the tree from the git_commit that you were returned using git_commit_tree.

Related

Redis RESP3 protocol -- how to set it for luascript?

I am using Redis 7.0.4. I am trying to use RESP3 protocol so that the luascript responses are making more sense. When I use the hello command in luascript, it throws error
This Redis command is not allowed from script
If I set it from command line, it seems to be temporary and fallback to 2.
What is the right way to set it, so my script can take advantage of it?
HELLO is not allowed in Lua script. If you want to switch RESP version in Lua script, you should call redis.setresp(version) instead.
-- use RESP3
redis.setresp(3)
Also, RESP3 support some new types, so you need to be careful with the RESP3 data type conversion from/to Lua types. Check this for detail.

What happen if I try to use SetObject and I already had the same key?

I'm working on a project using Redis cache with cachingFramework.redis.
I already have working the get function with Redis (using FetchObject)
but I need to update the Save function to save in DB and override/update the key/value in Redis.
Should I use SetObject? or I need to call first Remove(key)
It really depends on the when parameter, but by default the SET operation on redis overrides the current value, regardless of its type. Here is the documentation.
So you don't need to call the Remove method.
You can check here how StackExchange.Redis library choose between different SET commands (SET, SETNX, SETEX) depending on the parameters.

Spawn mob from other mods

I'm looking for a way to spawn entities from other mods. I found that for blocks and items there are a way to fetch them with
GameRegistry.findBlock()
but didnt found anything similar for mobs. I also didnt found any similar at forge off documentation. Is there any references/guides about communications with other mods?
I'm using MC 1.7.10/Forge 10.13.4
After a bit of code diving it looks like you can use EntityList.createEntityByName(String, World) to create an instance of an entity (it will return null if there's no entity with that name or another error occurs.) If you need to get an entity class from the name you can use the EntityList.stringToClassMapping map. Because 1.7.10 doesn't include any generics you'll have to manually cast the returned value from that map. As far as I can tell the type of the map is Map<String, Class>, as you probably already guessed.

Why does git_treebuilder_insert fail for invalid objects?

The documention for git_treebuilder_insert seems to imply that it doesn't care whether the object being inserted is valid:
No attempt is being made to ensure that the provided oid points to an existing git object in the object database, nor that the attributes make sense regarding the type of the pointed at object.
However, when actually using the library to create tree objects, if I try to write an entry with an invalid oid, this function returns failure. As reference, here's the code:
if (filemode != GIT_FILEMODE_COMMIT &&
!git_object__is_valid(bld->repo, id, otype_from_mode(filemode)))
return tree_error("Failed to insert entry; invalid object specified", filename);
What is the intended behavior, the code or the documentation?
The documentation is outdated; the code behaves as expected. The change to validate object pointers was made in order to:
Allow library users to make assumptions about the safety of their projects. It is generally an error to create something that dangles and points to an object that does not exist.
Improve consistency between creating references and creating objects. Now they both validate that the thing(s) they're pointing to exist, by default.
If you do not want this behavior, you can disable it, by calling:
git_libgit2_opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, 0);

How to connect to postgresql in a multithreaded C application

I have a few threads in my application. Each has its own PGconn* connection that is individually opened with the same connection string. When a thread makes a query, it almost never returns PGRES_TUPLES_OK.
I can provide some code examples if necessary, but does anything stand out here? I have tried using global mutexes as well, to no avail. I am using postgresql 9.3
PQerrorMessage(db) returns: connection pointer is NULL
From the postgresql documentation:
If a null pointer is returned, it should be treated like a PGRES_FATAL_ERROR result. Use PQerrorMessage to get more information about the error.
Ok, I figured it out.
I was using a function to open each connection, and was passing a pointer to a PGconn struct to it.
I needed to pass a double pointer.