1/* 2 * Copyright (C) 2005 Junio C Hamano 3 */ 4#include"cache.h" 5 6/* 7 * This array must be sorted by its canonical name, because 8 * we do look-up by binary search. 9 */ 10static struct backward_compatible_env { 11const char*canonical; 12const char*old; 13} bc_name[] = { 14{"GIT_ALTERNATE_OBJECT_DIRECTORIES","SHA1_FILE_DIRECTORIES"}, 15{"GIT_AUTHOR_DATE","AUTHOR_DATE"}, 16{"GIT_AUTHOR_EMAIL","AUTHOR_EMAIL"}, 17{"GIT_AUTHOR_NAME","AUTHOR_NAME"}, 18{"GIT_COMMITTER_EMAIL","COMMIT_AUTHOR_EMAIL"}, 19{"GIT_COMMITTER_NAME","COMMIT_AUTHOR_NAME"}, 20{"GIT_OBJECT_DIRECTORY","SHA1_FILE_DIRECTORY"}, 21}; 22 23static voidwarn_old_environment(int pos) 24{ 25int i; 26static int warned =0; 27if(warned) 28return; 29 30 warned =1; 31fprintf(stderr, 32"warning: Attempting to use%s\n", 33 bc_name[pos].old); 34fprintf(stderr, 35"warning: GIT environment variables have been renamed.\n" 36"warning: Please adjust your scripts and environment.\n"); 37for(i =0; i <sizeof(bc_name) /sizeof(bc_name[0]); i++) { 38/* warning is needed only when old name is there and 39 * new name is not. 40 */ 41if(!getenv(bc_name[i].canonical) &&getenv(bc_name[i].old)) 42fprintf(stderr,"warning: old%s=> new%s\n", 43 bc_name[i].old, bc_name[i].canonical); 44} 45} 46 47char*gitenv_bc(const char*e) 48{ 49int first, last; 50char*val =getenv(e); 51if(val) 52die("gitenv_bc called on existing%s; fix the caller.", e); 53 54 first =0; 55 last =sizeof(bc_name) /sizeof(bc_name[0]); 56while(last > first) { 57int next = (last + first) >>1; 58int cmp =strcmp(e, bc_name[next].canonical); 59if(!cmp) { 60 val =getenv(bc_name[next].old); 61/* If the user has only old name, warn. 62 * otherwise stay silent. 63 */ 64if(val) 65warn_old_environment(next); 66return val; 67} 68if(cmp <0) { 69 last = next; 70continue; 71} 72 first = next+1; 73} 74return NULL; 75}