Make die() and error() prefix line with binary name if set
PATCH 1/1 Make die() and error() prefix line with binary name if set
Since lots of logic is implemented via shell scripts, it's in general useful to print out where an error occured. Previously only some commands manually added the binary name to die() and error() calls.
Now, git_set_appname() can be used to set the name of the binary as first call in a binary's main() routine which will be used as prefix in die() and error(). If it was not called, no prefix will be printed.
---
apply.c | 10 ++++++---- blame.c | 2 ++ cat-file.c | 10 ++++++---- check-ref-format.c | 2 ++ checkout-index.c | 8 +++++--- clone-pack.c | 2 ++ commit-tree.c | 2 ++ connect.c | 4 ++-- convert-objects.c | 2 ++ daemon.c | 4 +++- describe.c | 2 ++ diff-files.c | 5 ++++- diff-index.c | 5 ++++- diff-stages.c | 5 ++++- diff-tree.c | 2 ++ entry.c | 14 +++++++------- fetch-clone.c | 2 +- fetch-pack.c | 4 +++- fsck-objects.c | 2 ++ get-tar-commit-id.c | 2 ++ git-compat-util.h | 1 + git.c | 2 ++ hash-object.c | 2 ++ http-fetch.c | 2 ++ http-push.c | 2 ++ index-pack.c | 2 ++ init-db.c | 2 ++ local-fetch.c | 2 ++ ls-files.c | 8 +++++--- ls-tree.c | 2 ++ mailinfo.c | 2 ++ mailsplit.c | 2 ++ merge-base.c | 2 ++ merge-index.c | 8 +++++--- merge-tree.c | 2 ++ mktag.c | 2 ++ mktree.c | 2 ++ name-rev.c | 2 ++ pack-objects.c | 2 ++ pack-redundant.c | 2 ++ patch-id.c | 2 ++ peek-remote.c | 2 ++ prune-packed.c | 2 ++ read-tree.c | 2 ++ receive-pack.c | 2 ++ repo-config.c | 2 ++ rev-list.c | 2 ++ rev-parse.c | 5 ++++- send-pack.c | 2 ++ shell.c | 2 ++ show-branch.c | 2 ++ show-index.c | 2 ++ ssh-fetch.c | 2 ++ ssh-upload.c | 2 ++ stripspace.c | 2 ++ symbolic-ref.c | 2 ++ tar-tree.c | 6 ++++-- test-date.c | 2 ++ test-delta.c | 2 ++ tree-diff.c | 2 +- unpack-file.c | 2 ++ unpack-objects.c | 2 ++ update-index.c | 23 ++++++++++++++--------- update-ref.c | 2 ++ update-server-info.c | 3 +++ upload-pack.c | 20 +++++++++++--------- usage.c | 14 ++++++++++++++ var.c | 3 +++ verify-pack.c | 2 ++ write-tree.c | 10 ++++++---- 70 files changed, 210 insertions(+), 58 deletions(-)
92e903a0273996028d069b28fde6c5a990e1157b
apply.c +6 -4
@@ -142,7 +142,7 @@ static void *read_patch_file(int fd, unsif (!nr)break ;if (nr <0 ) -die ("git-apply: read returned %s" ,strerror (errno)); +die ("read returned %s" ,strerror (errno)); size += nr; } *sizep = size;
@@ -320,17 +320,17 @@ static char *gitdiff_verify_name(const c name = orig_name; len =strlen (name);if (isnull) -die ("git-apply: bad git-diff - expected /dev/null, got %s on line %d" , name, linenr); +die ("bad git-diff - expected /dev/null, got %s on line %d" , name, linenr); another =find_name (line,NULL ,1 ,0 );if (!another ||memcmp (another, name, len)) -die ("git-apply: bad git-diff - inconsistent %s filename on line %d" , oldnew, linenr); +die ("bad git-diff - inconsistent %s filename on line %d" , oldnew, linenr);free (another);return orig_name; }else {/* expect "/dev/null" */ if (memcmp ("/dev/null" , line,9 ) || line[9 ] !='\n' ) -die ("git-apply: bad git-diff - expected /dev/null on line %d" , linenr); +die ("bad git-diff - expected /dev/null on line %d" , linenr);return NULL ; } }
@@ -1960,6 +1960,8 @@ int main(int argc, char **argv)int read_stdin =1 ;const char *whitespace_option =NULL ; +git_set_appname ("git-apply" ); +for (i =1 ; i < argc; i++) {const char *arg = argv[i];char *end;
blame.c +2 -0
@@ -752,6 +752,8 @@ int main(int argc, const char **argv)int longest_file, longest_author;int found_rename; +git_set_appname ("git-blame" ); +const char * prefix =setup_git_directory ();git_config (git_default_config);
cat-file.c +6 -4
@@ -16,9 +16,9 @@ static void flush_buffer(const char *buf/* Ignore epipe */ if (errno ==EPIPE )break ; -die ("git-cat-file: %s" ,strerror (errno)); +die ("%s" ,strerror (errno)); }else if (!ret) { -die ("git-cat-file: disk full?" ); +die ("disk full?" ); } size -= ret; buf += ret;
@@ -101,6 +101,8 @@ int main(int argc, char **argv)unsigned long size;int opt; +git_set_appname ("git-cat-file" ); +setup_git_directory ();git_config (git_default_config);if (argc !=3 ||get_sha1 (argv[2 ], sha1))
@@ -154,11 +156,11 @@ int main(int argc, char **argv)break ;default : -die ("git-cat-file: unknown option: %s\n" , argv[1 ]); +die ("unknown option: %s\n" , argv[1 ]); }if (!buf) -die ("git-cat-file %s: bad file" , argv[2 ]); +die ("bad file" , argv[2 ]);flush_buffer (buf, size);return 0 ;
check-ref-format.c +2 -0
@@ -9,6 +9,8 @@ #include <stdio.h>int main (int ac,char **av) { +git_set_appname ("git-check-ref-format" ); +if (ac !=2 )usage ("git-check-ref-format refname" );if (check_ref_format (av[1 ]))
checkout-index.c +5 -3
@@ -176,6 +176,8 @@ int main(int argc, char **argv)int all =0 ;int read_from_stdin =0 ; +git_set_appname ("git-checkout-index" ); + prefix =setup_git_directory ();git_config (git_default_config); prefix_length = prefix ?strlen (prefix) :0 ;
@@ -271,16 +273,16 @@ int main(int argc, char **argv)const char *arg = argv[i];if (all) -die ("git-checkout-index: don't mix '--all' and explicit filenames" ); +die ("don't mix '--all' and explicit filenames" );if (read_from_stdin) -die ("git-checkout-index: don't mix '--stdin' and explicit filenames" ); +die ("don't mix '--stdin' and explicit filenames" );checkout_file (prefix_path (prefix, prefix_length, arg)); }if (read_from_stdin) {struct strbuf buf;if (all) -die ("git-checkout-index: don't mix '--all' and '--stdin'" ); +die ("don't mix '--all' and '--stdin'" );strbuf_init (&buf);while (1 ) {char *path_name;
clone-pack.c +2 -0
@@ -150,6 +150,8 @@ int main(int argc, char **argv)int fd[2 ];pid_t pid; +git_set_appname ("git-clone-pack" ); +setup_git_directory (); nr_heads =0 ;
commit-tree.c +2 -0
@@ -87,6 +87,8 @@ int main(int argc, char **argv)char *buffer;unsigned int size; +git_set_appname ("git-commit-tree" ); +setup_ident ();setup_git_directory ();
connect.c +2 -2
@@ -69,7 +69,7 @@ int get_ack(int fd, unsigned char *resulint len =packet_read_line (fd, line,sizeof (line));if (!len) -die ("git-fetch-pack: expected ACK/NAK, got EOF" ); +die ("expected ACK/NAK, got EOF" );if (line[len-1 ] =='\n' ) line[--len] =0 ;if (!strcmp (line,"NAK" ))
@@ -81,7 +81,7 @@ int get_ack(int fd, unsigned char *resulreturn 1 ; } } -die ("git-fetch_pack: expected ACK/NAK, got '%s'" , line); +die ("expected ACK/NAK, got '%s'" , line); }int path_match (const char *path,int nr,char **match)
convert-objects.c +2 -0
@@ -319,6 +319,8 @@ int main(int argc, char **argv)unsigned char sha1[20 ];struct entry *entry; +git_set_appname ("git-convert-object" ); +setup_git_directory ();if (argc !=2 ||get_sha1 (argv[1 ], sha1))
daemon.c +3 -1
@@ -666,6 +666,8 @@ int main(int argc, char **argv)int inetd_mode =0 ;int i; +git_set_appname ("git-daemon" ); +for (i =1 ; i < argc; i++) {char *arg = argv[i];
@@ -739,7 +741,7 @@ int main(int argc, char **argv)if (strict_paths && (!ok_paths || !*ok_paths)) {if (!inetd_mode) -die ("git-daemon: option --strict-paths requires a whitelist" ); +die ("option --strict-paths requires a whitelist" );logerror ("option --strict-paths requires a whitelist" );exit (1 );
describe.c +2 -0
@@ -143,6 +143,8 @@ int main(int argc, char **argv) {int i; +git_set_appname ("git-describe" ); +for (i =1 ; i < argc; i++) {const char *arg = argv[i];
diff-files.c +4 -1
@@ -39,9 +39,12 @@ static void show_modified(int oldmode, iint main (int argc,const char **argv) {const char **pathspec; -const char *prefix =setup_git_directory (); +const char *prefix;int entries, i; +git_set_appname ("git-diff-files" ); + + prefix =setup_git_directory ();git_config (git_diff_config);diff_setup (&rev.diffopt);while (1 < argc && argv[1 ][0 ] =='-' ) {
diff-index.c +4 -1
@@ -171,13 +171,16 @@ int main(int argc, const char **argv) {const char *tree_name =NULL ;unsigned char sha1[20 ]; -const char *prefix =setup_git_directory (); +const char *prefix;const char **pathspec =NULL ;struct tree *tree;int ret;int allow_options =1 ;int i; +git_set_appname ("git-diff-index" ); + + prefix =setup_git_directory ();git_config (git_diff_config);diff_setup (&diff_options);for (i =1 ; i < argc; i++) {
diff-stages.c +4 -1
@@ -57,9 +57,12 @@ static void diff_stages(int stage1, intint main (int ac,const char **av) {int stage1, stage2; -const char *prefix =setup_git_directory (); +const char *prefix;const char **pathspec =NULL ; +git_set_appname ("git-diff-stages" ); + + prefix =setup_git_directory ();git_config (git_diff_config);read_cache ();diff_setup (&diff_options);
diff-tree.c +2 -0
@@ -67,6 +67,8 @@ int main(int argc, const char **argv)struct object_list *list;int read_stdin =0 ; +git_set_appname ("git-diff-tree" ); +git_config (git_diff_config); nr_sha1 =0 ;init_revisions (opt);
entry.c +7 -7
@@ -76,7 +76,7 @@ static int write_entry(struct cache_entrif (!new ||strcmp (type, blob_type)) {if (new)free (new); -return error ("git-checkout-index: unable to read sha1 file of %s (%s)" , +return error ("unable to read sha1 file of %s (%s)" , path,sha1_to_hex (ce->sha1)); }switch (ntohl (ce->ce_mode) &S_IFMT ) {
@@ -88,14 +88,14 @@ static int write_entry(struct cache_entr fd =create_file (path,ntohl (ce->ce_mode));if (fd <0 ) {free (new); -return error ("git-checkout-index: unable to create file %s (%s)" , +return error ("unable to create file %s (%s)" , path,strerror (errno)); } wrote =write (fd, new, size);close (fd);free (new);if (wrote != size) -return error ("git-checkout-index: unable to write file %s" , path); +return error ("unable to write file %s" , path);break ;case S_IFLNK :if (to_tempfile) {
@@ -103,26 +103,26 @@ static int write_entry(struct cache_entr fd =mkstemp (path);if (fd <0 ) {free (new); -return error ("git-checkout-index: unable to create " +return error ("unable to create " "file %s (%s)" , path,strerror (errno)); } wrote =write (fd, new, size);close (fd);free (new);if (wrote != size) -return error ("git-checkout-index: unable to write file %s" , +return error ("unable to write file %s" , path); }else { wrote =symlink (new, path);free (new);if (wrote) -return error ("git-checkout-index: unable to create " +return error ("unable to create " "symlink %s (%s)" , path,strerror (errno)); }break ;default :free (new); -return error ("git-checkout-index: unknown file mode for %s" , path); +return error ("unknown file mode for %s" , path); }if (state->refresh_cache) {
fetch-clone.c +1 -1
@@ -23,7 +23,7 @@ static int finish_pack(const char *pack_ pid =fork ();if (pid <0 ) -die ("git-clone-pack: unable to fork off git-index-pack" ); +die ("unable to fork off git-index-pack" );if (!pid) {close (0 );dup2 (pipe_fd[1 ],1 );
fetch-pack.c +3 -1
@@ -390,7 +390,7 @@ static int fetch_pack(int fd[2], int nr_ status =receive_unpack_pack (fd,"git-fetch-pack" , quiet);if (status) -die ("git-fetch-pack: fetch failed." ); +die ("fetch failed." ); all_done:while (ref) {
@@ -408,6 +408,8 @@ int main(int argc, char **argv)int fd[2 ];pid_t pid; +git_set_appname ("git-fetch-pack" ); +setup_git_directory (); nr_heads =0 ;
fsck-objects.c +2 -0
@@ -442,6 +442,8 @@ int main(int argc, char **argv) {int i, heads; +git_set_appname ("git-fsck-objects" ); +setup_git_directory ();for (i =1 ; i < argc; i++) {
get-tar-commit-id.c +2 -0
@@ -12,6 +12,8 @@ int main(int argc, char **argv)char buffer[HEADERSIZE ];ssize_t n; +git_set_appname ("git-get-tar-commit-id" ); + n =read (0 , buffer,HEADERSIZE );if (n <HEADERSIZE ) {fprintf (stderr,"read error\n" );
git-compat-util.h +1 -0
@@ -39,6 +39,7 @@ #endif extern void usage(const char *err) NORETURN; extern void die(const char *err, ...) NORETURN __attribute__((format (printf, 1, 2)));extern int error (const char *err, ...) __attribute__((format (printf,1 ,2 ))); +extern void git_set_appname (const char *name);#ifdef NO_MMAP
git.c +2 -0
@@ -71,6 +71,8 @@ int main(int argc, const char **argv, chchar git_command[PATH_MAX +1 ];const char *exec_path =NULL ; +git_set_appname ("git" ); +/* * Take the basename of argv[0] as the command * name, and the dirname as the default exec_path
hash-object.c +2 -0
@@ -42,6 +42,8 @@ int main(int argc, char **argv)int prefix_length =-1 ;int no_more_flags =0 ; +git_set_appname ("git-hash-object" ); +for (i =1 ; i < argc; i++) {if (!no_more_flags && argv[i][0 ] =='-' ) {if (!strcmp (argv[i],"-t" )) {
http-fetch.c +2 -0
@@ -1222,6 +1222,8 @@ int main(int argc, char **argv)int arg =1 ;int rc =0 ; +git_set_appname ("git-http-fetch" ); +setup_git_directory ();while (arg < argc && argv[arg][0 ] =='-' ) {
http-push.c +2 -0
@@ -2315,6 +2315,8 @@ int main(int argc, char **argv)int new_refs;struct ref *ref; +git_set_appname ("git-http-push" ); +setup_git_directory ();setup_ident ();
index-pack.c +2 -0
@@ -425,6 +425,8 @@ int main(int argc, char **argv)char *index_name_buf =NULL ;unsigned char sha1[20 ]; +git_set_appname ("git-index-pack" ); +for (i =1 ; i < argc; i++) {const char *arg = argv[i];
init-db.c +2 -0
@@ -241,6 +241,8 @@ int main(int argc, char **argv)char *path, *template_dir =NULL ;int len, i; +git_set_appname ("git-init-db" ); +for (i =1 ; i < argc; i++, argv++) {char *arg = argv[1 ];if (!strncmp (arg,"--template=" ,11 ))
local-fetch.c +2 -0
@@ -207,6 +207,8 @@ int main(int argc, char **argv)char *commit_id;int arg =1 ; +git_set_appname ("git-local-fetch" ); +setup_git_directory ();while (arg < argc && argv[arg][0 ] =='-' ) {
ls-files.c +5 -3
@@ -383,7 +383,7 @@ static void show_dir_entry(const char *tint offset = prefix_offset;if (len >= ent->len) -die ("git-ls-files: internal error - directory entry not superset of prefix" ); +die ("internal error - directory entry not superset of prefix" );if (pathspec && !match (pathspec, ps_matched, ent->name, len))return ;
@@ -471,7 +471,7 @@ static void show_ce_entry(const char *taint offset = prefix_offset;if (len >=ce_namelen (ce)) -die ("git-ls-files: internal error - cache entry not superset of prefix" ); +die ("internal error - cache entry not superset of prefix" );if (pathspec && !match (pathspec, ps_matched, ce->name, len))return ;
@@ -630,7 +630,7 @@ static void verify_pathspec(void) }if (prefix_offset > max ||memcmp (prev, prefix, prefix_offset)) -die ("git-ls-files: cannot generate relative filenames containing '..'" ); +die ("cannot generate relative filenames containing '..'" ); real_prefix =NULL ; prefix_len = max;
@@ -653,6 +653,8 @@ int main(int argc, const char **argv)int i;int exc_given =0 ; +git_set_appname ("git-ls-files" ); + prefix =setup_git_directory ();if (prefix) prefix_offset =strlen (prefix);
ls-tree.c +2 -0
@@ -89,6 +89,8 @@ int main(int argc, const char **argv)unsigned char sha1[20 ];struct tree *tree; +git_set_appname ("git-ls-tree" ); + prefix =setup_git_directory ();git_config (git_default_config);if (prefix && *prefix)
mailinfo.c +2 -0
@@ -757,6 +757,8 @@ static const char mailinfo_usage[] =int main (int argc,char **argv) { +git_set_appname ("git-mailinfo" ); +/* NEEDSWORK: might want to do the optional .git/ directory * discovery */
mailsplit.c +2 -0
@@ -111,6 +111,8 @@ int main(int argc, const char **argv)static const char *stdin_only[] = {"-" ,NULL };char *name; +git_set_appname ("git-mailsplit" ); +for (argp = argv+1 ; *argp; argp++) {const char *arg = *argp;
merge-base.c +2 -0
@@ -236,6 +236,8 @@ int main(int argc, char **argv)struct commit *rev1, *rev2;unsigned char rev1key[20 ], rev2key[20 ]; +git_set_appname ("git-merge-base" ); +setup_git_directory ();git_config (git_default_config);
merge-index.c +5 -3
@@ -42,7 +42,7 @@ static int merge_entry(int pos, const chint found;if (pos >= active_nr) -die ("git-merge-index: %s not in the cache" , path); +die ("%s not in the cache" , path); arguments[0 ] = pgm; arguments[1 ] ="" ; arguments[2 ] ="" ;
@@ -67,7 +67,7 @@ static int merge_entry(int pos, const ch arguments[stage +4 ] = ownbuf[stage]; }while (++pos < active_nr);if (!found) -die ("git-merge-index: %s not in the cache" , path); +die ("%s not in the cache" , path);run_program ();return found; }
@@ -99,6 +99,8 @@ int main(int argc, char **argv) {int i, force_file =0 ; +git_set_appname ("git-merge-index" ); +if (argc <3 )usage ("git-merge-index [-o] [-q] <merge-program> (-a | <filename>*)" );
@@ -126,7 +128,7 @@ int main(int argc, char **argv)merge_all ();continue ; } -die ("git-merge-index: unknown option %s" , arg); +die ("unknown option %s" , arg); }merge_file (arg); }
merge-tree.c +2 -0
@@ -164,6 +164,8 @@ int main(int argc, char **argv)struct tree_desc t[3 ];void *buf1, *buf2, *buf3; +git_set_appname ("git-merge-tree" ); +if (argc <4 )usage (merge_tree_usage);
mktag.c +2 -0
@@ -109,6 +109,8 @@ int main(int argc, char **argv)char buffer[MAXSIZE ];unsigned char result_sha1[20 ]; +git_set_appname ("git-mktag" ); +if (argc !=1 )usage ("cat <signaturefile> | git-mktag" );
mktree.c +2 -0
@@ -79,6 +79,8 @@ int main(int ac, char **av)unsigned char sha1[20 ];int line_termination ='\n' ; +git_set_appname ("git-mktree" ); +setup_git_directory ();while ((1 < ac) && av[1 ][0 ] =='-' ) {
name-rev.c +2 -0
@@ -126,6 +126,8 @@ int main(int argc, char **argv)struct object_list **walker = &revs;int as_is =0 , all =0 , transform_stdin =0 ; +git_set_appname ("git-name-rev" ); +setup_git_directory ();git_config (git_default_config);
pack-objects.c +2 -0
@@ -1237,6 +1237,8 @@ int main(int argc, char **argv)int num_preferred_base =0 ;int i; +git_set_appname ("git-pack-objects" ); +setup_git_directory ();for (i =1 ; i < argc; i++) {
pack-redundant.c +2 -0
@@ -589,6 +589,8 @@ int main(int argc, char **argv)unsigned char *sha1;char buf[42 ];/* 40 byte sha1 + \n + \0 */ +git_set_appname ("git-pack-redundant" ); +setup_git_directory ();for (i =1 ; i < argc; i++) {
patch-id.c +2 -0
@@ -74,6 +74,8 @@ static const char patch_id_usage[] = "giint main (int argc,char **argv) { +git_set_appname ("git-patch-id" ); +if (argc !=1 )usage (patch_id_usage);
peek-remote.c +2 -0
@@ -29,6 +29,8 @@ int main(int argc, char **argv)pid_t pid;int nongit =0 ; +git_set_appname ("git-pack-remote" ); +setup_git_directory_gently (&nongit);for (i =1 ; i < argc; i++) {
prune-packed.c +2 -0
@@ -58,6 +58,8 @@ int main(int argc, char **argv) {int i; +git_set_appname ("git-prune-packed" ); +setup_git_directory ();for (i =1 ; i < argc; i++) {
read-tree.c +2 -0
@@ -723,6 +723,8 @@ int main(int argc, char **argv)unsigned char sha1[20 ];merge_fn_t fn =NULL ; +git_set_appname ("git-read-tree" ); +setup_git_directory ();git_config (git_default_config);
receive-pack.c +2 -0
@@ -304,6 +304,8 @@ int main(int argc, char **argv)int i;char *dir =NULL ; +git_set_appname ("git-receive-pack" ); + argv++;for (i =1 ; i < argc; i++) {char *arg = *argv++;
repo-config.c +2 -0
@@ -86,6 +86,8 @@ static int get_value(const char* key_, cint main (int argc,const char **argv) { +git_set_appname ("git-repo-config" ); +setup_git_directory ();while (1 < argc) {
rev-list.c +2 -0
@@ -296,6 +296,8 @@ int main(int argc, const char **argv)struct commit_list *list;int i; +git_set_appname ("git-rev-list" ); +init_revisions (&revs); revs.abbrev =0 ; revs.commit_format =CMIT_FMT_UNSPECIFIED ;
rev-parse.c +4 -1
@@ -164,8 +164,11 @@ int main(int argc, char **argv) {int i, as_is =0 , verify =0 ;unsigned char sha1[20 ]; -const char *prefix =setup_git_directory (); +const char *prefix; +git_set_appname ("git-rev-parse" ); + + prefix =setup_git_directory ();git_config (git_default_config);for (i =1 ; i < argc; i++) {
send-pack.c +2 -0
@@ -361,6 +361,8 @@ int main(int argc, char **argv)int fd[2 ], ret;pid_t pid; +git_set_appname ("git-send-pack" ); +setup_git_directory ();git_config (git_default_config);
shell.c +2 -0
@@ -32,6 +32,8 @@ int main(int argc, char **argv)char *prog;struct commands *cmd; +git_set_appname ("git-shell" ); +/* We want to see "-c cmd args", and nothing else */ if (argc !=3 ||strcmp (argv[1 ],"-c" ))die ("What do you think I am? A shell?" );
show-branch.c +2 -0
@@ -549,6 +549,8 @@ int main(int ac, char **av)int head_at =-1 ;int topics =0 ; +git_set_appname ("git-show-branch" ); +setup_git_directory ();git_config (git_show_branch_config);
show-index.c +2 -0
@@ -7,6 +7,8 @@ int main(int argc, char **argv)unsigned int entry[6 ];static unsigned int top_index[256 ]; +git_set_appname ("git-show-index" ); +if (fread (top_index,sizeof (top_index),1 , stdin) !=1 )die ("unable to read idex" ); nr =0 ;
ssh-fetch.c +2 -0
@@ -128,6 +128,8 @@ int main(int argc, char **argv)int arg =1 ;const char *prog; +git_set_appname ("git-ssh-fetch" ); + prog =getenv ("GIT_SSH_PUSH" );if (!prog) prog ="git-ssh-upload" ;
ssh-upload.c +2 -0
@@ -119,6 +119,8 @@ int main(int argc, char **argv)unsigned char sha1[20 ];char hex[41 ]; +git_set_appname ("git-ssh-upload" ); + prog =getenv (COUNTERPART_ENV_NAME );if (!prog) prog =COUNTERPART_PROGRAM_NAME ;
stripspace.c +2 -0
@@ -34,6 +34,8 @@ int main(int argc, char **argv)int incomplete =0 ;char line[1024 ]; +git_set_appname ("git-stripspace" ); +while (fgets (line,sizeof (line), stdin)) { incomplete =cleanup (line);
symbolic-ref.c +2 -0
@@ -19,6 +19,8 @@ static void check_symref(const char *HEAint main (int argc,const char **argv) { +git_set_appname ("git-symbolic-ref" ); +setup_git_directory ();git_config (git_default_config);switch (argc) {
tar-tree.c +4 -2
@@ -26,9 +26,9 @@ static void reliable_write(void *buf, unif (ret <0 ) {if (errno ==EPIPE )exit (0 ); -die ("git-tar-tree: %s" ,strerror (errno)); +die ("%s" ,strerror (errno)); }else if (!ret) { -die ("git-tar-tree: disk full?" ); +die ("disk full?" ); } size -= ret; buf += ret;
@@ -308,6 +308,8 @@ int main(int argc, char **argv)struct tree_desc tree;struct strbuf current_path; +git_set_appname ("git-tar-tree" ); + current_path.buf =xmalloc (PATH_MAX ); current_path.alloc =PATH_MAX ; current_path.len = current_path.eof =0 ;
test-date.c +2 -0
@@ -7,6 +7,8 @@ int main(int argc, char **argv) {int i; +git_set_appname ("git-test-date" ); +for (i =1 ; i < argc; i++) {char result[100 ];time_t t;
test-delta.c +2 -0
@@ -27,6 +27,8 @@ int main(int argc, char *argv[])void *from_buf, *data_buf, *out_buf;unsigned long from_size, data_size, out_size; +git_set_appname ("git-test-delta" ); +if (argc !=5 || (strcmp (argv[1 ],"-d" ) &&strcmp (argv[1 ],"-p" ))) {fprintf (stderr,"Usage: %s\n" , usage);return 1 ;
tree-diff.c +1 -1
@@ -191,7 +191,7 @@ int diff_tree(struct tree_desc *t1, struupdate_tree_entry (t2);continue ; } -die ("git-diff-tree: internal error" ); +die ("internal error" ); }return 0 ; }
unpack-file.c +2 -0
@@ -27,6 +27,8 @@ int main(int argc, char **argv) {unsigned char sha1[20 ]; +git_set_appname ("git-unpack-file" ); +if (argc !=2 ||get_sha1 (argv[1 ], sha1))usage ("git-unpack-file <sha1>" );
unpack-objects.c +2 -0
@@ -270,6 +270,8 @@ int main(int argc, char **argv)int i;unsigned char sha1[20 ]; +git_set_appname ("git-unpack-objects" ); +setup_git_directory (); quiet = !isatty (2 );
update-index.c +14 -9
@@ -370,7 +370,7 @@ static void update_one(const char *path,if (force_remove) {if (remove_file_from_cache (p)) -die ("git-update-index: unable to remove %s" , path); +die ("unable to remove %s" , path);report ("remove '%s'" , path);return ; }
@@ -446,7 +446,7 @@ static void read_index_info(int line_terif (!mode) {/* mode == 0 means there is no such path -- remove */ if (remove_file_from_cache (path_name)) -die ("git-update-index: unable to remove %s" , +die ("unable to remove %s" , ptr); }else {
@@ -456,7 +456,7 @@ static void read_index_info(int line_ter*/ ptr[-42 ] = ptr[-1 ] =0 ;if (add_cacheinfo (mode, sha1, path_name, stage)) -die ("git-update-index: unable to update %s" , +die ("unable to update %s" , path_name); }if (path_name != ptr)
@@ -476,8 +476,13 @@ int main(int argc, const char **argv)int i, newfd, entries, has_errors =0 , line_termination ='\n' ;int allow_options =1 ;int read_from_stdin =0 ; -const char *prefix =setup_git_directory (); -int prefix_length = prefix ?strlen (prefix) :0 ; +const char *prefix; +int prefix_length; + +git_set_appname ("git-unpack-index" ); + + prefix =setup_git_directory (); + prefix_length = prefix ?strlen (prefix) :0 ;git_config (git_default_config);
@@ -530,12 +535,12 @@ int main(int argc, const char **argv)unsigned int mode;if (i+3 >= argc) -die ("git-update-index: --cacheinfo <mode> <sha1> <path>" ); +die ("--cacheinfo <mode> <sha1> <path>" );if ((sscanf (argv[i+1 ],"%o" , &mode) !=1 ) ||get_sha1_hex (argv[i+2 ], sha1) ||add_cacheinfo (mode, sha1, argv[i+3 ],0 )) -die ("git-update-index: --cacheinfo" +die ("--cacheinfo" " cannot add %s" , argv[i+3 ]); i +=3 ;continue ;
@@ -543,9 +548,9 @@ int main(int argc, const char **argv)if (!strcmp (path,"--chmod=-x" ) || !strcmp (path,"--chmod=+x" )) {if (argc <= i+1 ) -die ("git-update-index: %s <path>" , path); +die ("%s <path>" , path);if (chmod_path (path[8 ], argv[++i])) -die ("git-update-index: %s cannot chmod %s" , path, argv[i]); +die ("%s cannot chmod %s" , path, argv[i]);continue ; }if (!strcmp (path,"--assume-unchanged" )) {
update-ref.c +2 -0
@@ -24,6 +24,8 @@ int main(int argc, char **argv)unsigned char sha1[20 ], oldsha1[20 ], currsha1[20 ];int fd, written; +git_set_appname ("git-update-ref" ); +setup_git_directory ();git_config (git_default_config);if (argc <3 || argc >4 )
update-server-info.c +3 -0
@@ -7,6 +7,9 @@ int main(int ac, char **av) {int i;int force =0 ; + +git_set_appname ("git-update-server-info" ); +for (i =1 ; i < ac; i++) {if (av[i][0 ] =='-' ) { if (!strcmp("--force", av[i]) ||
upload-pack.c +11 -9
@@ -38,10 +38,10 @@ static void create_pack_file(void)int create_full_pack = (nr_our_refs == nr_needs && !nr_has);if (pipe (fd) <0 ) -die ("git-upload-pack: unable to create pipe" ); +die ("unable to create pipe" ); pid =fork ();if (pid <0 ) -die ("git-upload-pack: unable to fork git-rev-list" ); +die ("unable to fork git-rev-list" );if (!pid) {int i;
@@ -84,19 +84,19 @@ static void create_pack_file(void) } *p++ =NULL ;execv_git_cmd (argv); -die ("git-upload-pack: unable to exec git-rev-list" ); +die ("unable to exec git-rev-list" ); }dup2 (fd[0 ],0 );close (fd[0 ]);close (fd[1 ]);execl_git_cmd ("pack-objects" ,"--stdout" ,NULL ); -die ("git-upload-pack: unable to exec git-pack-objects" ); +die ("unable to exec git-pack-objects" ); }static int got_sha1 (char *hex,unsigned char *sha1) {if (get_sha1_hex (hex, sha1)) -die ("git-upload-pack: expected SHA1 object, got '%s'" , hex); +die ("expected SHA1 object, got '%s'" , hex);if (!has_sha1_file (sha1))return 0 ;if (nr_has <MAX_HAS ) {
@@ -162,7 +162,7 @@ static int get_common_commits(void)packet_write (1 ,"NAK\n" );return -1 ; } -die ("git-upload-pack: expected SHA1 list, got '%s'" , line); +die ("expected SHA1 list, got '%s'" , line); } }
@@ -191,7 +191,7 @@ static int receive_needs(void) sha1_buf = needs_sha1[needs];if (strncmp ("want " , line,5 ) ||get_sha1_hex (line+5 , sha1_buf)) -die ("git-upload-pack: protocol error, " +die ("protocol error, " "expected to get sha, not '%s'" , line);if (strstr (line+45 ,"multi_ack" )) multi_ack =1 ;
@@ -208,7 +208,7 @@ static int receive_needs(void)*/ o =lookup_object (sha1_buf);if (!o || !(o->flags &OUR_REF )) -die ("git-upload-pack: not our ref %s" , line+5 ); +die ("not our ref %s" , line+5 );if (!(o->flags &WANTED )) { o->flags |=WANTED ; needs++;
@@ -222,7 +222,7 @@ static int send_ref(const char *refname,struct object *o =parse_object (sha1);if (!o) -die ("git-upload-pack: cannot find object %s:" ,sha1_to_hex (sha1)); +die ("cannot find object %s:" ,sha1_to_hex (sha1));if (capabilities) packet_write(1, "%s %s%c%s\n", sha1_to_hex(sha1), refname,
@@ -261,6 +261,8 @@ int main(int argc, char **argv)int i;int strict =0 ; +git_set_appname ("git-upload-pack" ); +for (i =1 ; i < argc; i++) {char *arg = argv[i];
usage.c +14 -0
@@ -5,8 +5,11 @@*/ #include "git-compat-util.h" +static char appname[32 +3 ]="" ;/* +3 for ': \0' */ +static void report (const char *prefix,const char *err,va_list params) { +fputs (appname[0 ]?appname:"" ,stderr);fputs (prefix, stderr);vfprintf (stderr, err, params);fputs ("\n" , stderr);
@@ -37,3 +40,14 @@ int error(const char *err, ...)va_end (params);return -1 ; } + +void git_set_appname (const char *name) +{ +size_t len=strlen (name && *name ? name :"" ); +if (0 ==len) +return ; +memcpy (appname,name,len>sizeof (appname)-3 ?sizeof (appname)-3 :len); + appname[len++]=':' ; + appname[len++]=' ' ; + appname[len++]='\0' ; +}
var.c +3 -0
@@ -54,6 +54,9 @@ static int show_config(const char *var,int main (int argc,char **argv) {const char *val; + +git_set_appname ("git-var" ); +if (argc !=2 ) {usage (var_usage); }
verify-pack.c +2 -0
@@ -35,6 +35,8 @@ int main(int ac, char **av)int verbose =0 ;int no_more_options =0 ; +git_set_appname ("git-verify-pack" ); +while (1 < ac) {char path[PATH_MAX ];
write-tree.c +6 -4
@@ -92,6 +92,8 @@ int main(int argc, char **argv)int entries;unsigned char sha1[20 ]; +git_set_appname ("git-write-tree" ); +setup_git_directory (); entries =read_cache ();
@@ -106,7 +108,7 @@ int main(int argc, char **argv)die ("too many options" );if (entries <0 ) -die ("git-write-tree: error reading cache" ); +die ("error reading cache" );/* Verify that the tree is merged */ funny =0 ;
@@ -121,7 +123,7 @@ int main(int argc, char **argv) } }if (funny) -die ("git-write-tree: not able to write tree" ); +die ("not able to write tree" );/* Also verify that the cache does not have path and path/file * at the same time. At this point we know the cache has only
@@ -148,11 +150,11 @@ int main(int argc, char **argv) } }if (funny) -die ("git-write-tree: not able to write tree" ); +die ("not able to write tree" );/* Ok, write it out */ if (write_tree (active_cache, entries,"" ,0 , sha1) != entries) -die ("git-write-tree: internal error" ); +die ("internal error" );printf ("%s\n" ,sha1_to_hex (sha1));return 0 ; }
Signature · 1 line
1.3.0.ge649-dirty
Quoted 4 lines · Rocco Rutte
Now,
git_set_appname()can be used to set the name of the binary as first call in a binary'smain()routine which will be used as prefix indie()anderror(). If it was not called, no prefix will be printed.
I agree with the general direction, but...
apply.c int main(int argc, char **argv) · line 1966
Quoted 8 lines
apply.c +1
-0@@ -1960,6 +1960,8 @@ int main(int argc, char **argv)int read_stdin =1 ;const char *whitespace_option =NULL ; +git_set_appname ("git-apply" ); +for (i =1 ; i < argc; i++) {const char *arg = argv[i];char *end;
... what's wrong with your mailer?
* Junio C Hamano <[email protected]>:
Quoted 1 line
... what's wrong with your mailer?
I don't know. I recall to have seen this earlier.
And while I'll look at it (I bet this an f=f issue), the patch is at:
<http://user.cs.tu-berlin.de/~pdmef/0001-Make-die-and-error-prefix-line-with-binary-name-if-set.txt>
bye, Rocco
Signature · 1 line
:wq!
Quoted 2 lines · Rocco Rutte
+ size_t len=strlen(name && *name ? name : ""); + if (0==len)
Wouldn't it be easier (and less idiomatic) to just do
+ size_t len= *name ? strlen(name) : 0;
+ if (0==len)
Signature · 2 lines
Jakub Narebski Warsaw, Poland
* Jakub Narebski <[email protected]>:
Quoted 1 line
Wouldn't it be easier (and less idiomatic) to just do
Oh, thanks for pointing it out. The second one I sent fixes it (and is against an updated master branch).
bye, Rocco
Signature · 1 line
:wq!