SHARE
TWEET

Untitled

a guest Oct 21st, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mplementation
  2.  
  3. 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.
  4.  
  5. Modify your cmd_psuh implementation to dump the args you’re passed, keeping existing printf() calls in place:
  6.  
  7.     int i;
  8.  
  9.     ...
  10.  
  11.     printf(Q_("Your args (there is %d):\n",
  12.           "Your args (there are %d):\n",
  13.           argc),
  14.            argc);
  15.     for (i = 0; i < argc; i++)
  16.         printf("%d: %s\n", i, argv[i]);
  17.  
  18.     printf(_("Your current working directory:\n<top-level>%s%s\n"),
  19.            prefix ? "/" : "", prefix ? prefix : "");
  20.  
  21. 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?
  22.  
  23. Add a line to #include "config.h". Then, add the following bits to the function body:
  24.  
  25.     const char *cfg_name;
  26.  
  27. ...
  28.  
  29.     git_config(git_default_config, NULL);
  30.     if (git_config_get_string_const("user.name", &cfg_name) > 0)
  31.         printf(_("No name is found in config\n"));
  32.     else
  33.         printf(_("Your name: %s\n"), cfg_name);
  34.  
  35. 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
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top