a guest Oct 21st, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- It’s probably useful to do at least something besides printing out a string. Let’s start by having a look at everything we get.
- Modify your cmd_psuh implementation to dump the args you’re passed, keeping existing printf() calls in place:
- int i;
- printf(Q_("Your args (there is %d):\n",
- "Your args (there are %d):\n",
- for (i = 0; i < argc; i++)
- printf("%d: %s\n", i, argv[i]);
- printf(_("Your current working directory:\n<top-level>%s%s\n"),
- prefix ? "/" : "", prefix ? prefix : "");
- Build and try it. As you may expect, there’s pretty much just whatever we give on the command line, including the name of our command. (If prefix is empty for you, try cd Documentation/ && ../bin-wrappers/git psuh). That’s not so helpful. So what other context can we get?
- Add a line to #include "config.h". Then, add the following bits to the function body:
- const char *cfg_name;
- git_config(git_default_config, NULL);
- if (git_config_get_string_const("user.name", &cfg_name) > 0)
- printf(_("No name is found in config\n"));
- printf(_("Your name: %s\n"), cfg_name);
- git_config() will grab the configuration from config files known to Git and apply standard precedence rules. git_config_get_string_const() will look up a specific key ("user.name") and give you the value. There are a number of single-key lookup functions like this one; you can see them all (and more info about how to use git_config()) in Documentation/technical/api-config.txt.
RAW Paste Data