@ -47,28 +47,26 @@ static int is_git_dir(const char *path)
struct cgit_repo * repo ;
struct cgit_repo * repo ;
repo_config_fn config_fn ;
repo_config_fn config_fn ;
char * owner ;
char * desc ;
char * section ;
static void repo_config ( const char * name , const char * value )
static void repo_config ( const char * name , const char * value )
{
{
config_fn ( repo , name , value ) ;
config_fn ( repo , name , value ) ;
}
}
static int gitweb _config ( const char * key , const char * value , void * cb )
static int gitconfig _config ( const char * key , const char * value , void * cb )
{
{
if ( ctx . cfg . enable_gitweb_owner & & ! strcmp ( key , " gitweb.owner " ) )
if ( ! strcmp ( key , " gitweb.owner " ) )
owner = xstrdup ( value ) ;
config_fn ( repo , " owner " , value ) ;
else if ( ctx . cfg . enable_gitweb_desc & & ! strcmp ( key , " gitweb.description " ) )
else if ( ! strcmp ( key , " gitweb.description " ) )
desc = xstrdup ( value ) ;
config_fn ( repo , " desc " , value ) ;
else if ( ctx . cfg . enable_gitweb_section & & ! strcmp ( key , " gitweb.category " ) )
else if ( ! strcmp ( key , " gitweb.category " ) )
section = xstrdup ( value ) ;
config_fn ( repo , " section " , value ) ;
else if ( ! prefixcmp ( key , " cgit. " ) )
config_fn ( repo , key + 5 , value ) ;
return 0 ;
return 0 ;
}
}
static char * xstrrchr ( char * s , char * from , int c )
static char * xstrrchr ( char * s , char * from , int c )
{
{
while ( from > = s & & * from ! = c )
while ( from > = s & & * from ! = c )
@ -96,11 +94,6 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
if ( ! stat ( fmt ( " %s/noweb " , path ) , & st ) )
if ( ! stat ( fmt ( " %s/noweb " , path ) , & st ) )
return ;
return ;
owner = NULL ;
desc = NULL ;
section = NULL ;
git_config_from_file ( gitweb_config , fmt ( " %s/config " , path ) , NULL ) ;
if ( base = = path )
if ( base = = path )
rel = xstrdup ( fmt ( " %s " , path ) ) ;
rel = xstrdup ( fmt ( " %s " , path ) ) ;
else
else
@ -110,12 +103,15 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
rel [ strlen ( rel ) - 5 ] = ' \0 ' ;
rel [ strlen ( rel ) - 5 ] = ' \0 ' ;
repo = cgit_add_repo ( rel ) ;
repo = cgit_add_repo ( rel ) ;
config_fn = fn ;
if ( ctx . cfg . enable_git_config )
git_config_from_file ( gitconfig_config , fmt ( " %s/config " , path ) , NULL ) ;
if ( ctx . cfg . remove_suffix )
if ( ctx . cfg . remove_suffix )
if ( ( p = strrchr ( repo - > url , ' . ' ) ) & & ! strcmp ( p , " .git " ) )
if ( ( p = strrchr ( repo - > url , ' . ' ) ) & & ! strcmp ( p , " .git " ) )
* p = ' \0 ' ;
* p = ' \0 ' ;
repo - > name = repo - > url ;
repo - > path = xstrdup ( path ) ;
repo - > path = xstrdup ( path ) ;
while ( ! owner ) {
while ( ! repo - > owner ) {
if ( ( pwd = getpwuid ( st . st_uid ) ) = = NULL ) {
if ( ( pwd = getpwuid ( st . st_uid ) ) = = NULL ) {
fprintf ( stderr , " Error reading owner-info for %s: %s (%d) \n " ,
fprintf ( stderr , " Error reading owner-info for %s: %s (%d) \n " ,
path , strerror ( errno ) , errno ) ;
path , strerror ( errno ) , errno ) ;
@ -124,13 +120,10 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
if ( pwd - > pw_gecos )
if ( pwd - > pw_gecos )
if ( ( p = strchr ( pwd - > pw_gecos , ' , ' ) ) )
if ( ( p = strchr ( pwd - > pw_gecos , ' , ' ) ) )
* p = ' \0 ' ;
* p = ' \0 ' ;
owner = xstrdup ( pwd - > pw_gecos ? pwd - > pw_gecos : pwd - > pw_name ) ;
repo - > owner = xstrdup ( pwd - > pw_gecos ? pwd - > pw_gecos : pwd - > pw_name ) ;
}
}
repo - > owner = owner ;
if ( desc )
if ( repo - > desc = = cgit_default_repo_desc | | ! repo - > desc ) {
repo - > desc = desc ;
else {
p = fmt ( " %s/description " , path ) ;
p = fmt ( " %s/description " , path ) ;
if ( ! stat ( p , & st ) )
if ( ! stat ( p , & st ) )
readfile ( p , & repo - > desc , & size ) ;
readfile ( p , & repo - > desc , & size ) ;
@ -141,8 +134,6 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
if ( ! stat ( p , & st ) )
if ( ! stat ( p , & st ) )
repo - > readme = " README.html " ;
repo - > readme = " README.html " ;
}
}
if ( section )
repo - > section = section ;
if ( ctx . cfg . section_from_path ) {
if ( ctx . cfg . section_from_path ) {
n = ctx . cfg . section_from_path ;
n = ctx . cfg . section_from_path ;
if ( n > 0 ) {
if ( n > 0 ) {
@ -167,10 +158,9 @@ static void add_repo(const char *base, const char *path, repo_config_fn fn)
}
}
p = fmt ( " %s/cgitrc " , path ) ;
p = fmt ( " %s/cgitrc " , path ) ;
if ( ! stat ( p , & st ) ) {
if ( ! stat ( p , & st ) )
config_fn = fn ;
parse_configfile ( xstrdup ( p ) , & repo_config ) ;
parse_configfile ( xstrdup ( p ) , & repo_config ) ;
}
free ( rel ) ;
free ( rel ) ;
}
}