From 197df5adc32433016bd48e1faefef1460143360b Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sun, 25 May 2014 04:26:23 +0000 Subject: [PATCH] enhanced code search. added configuration items: allow_set_time_limit and signin_for_code_search --- codepot/etc/codepot.ini.in | 14 ++++++ codepot/src/codepot/controllers/code.php | 3 +- .../codepot/language/english/code_lang.php | 2 + .../codepot/language/english/common_lang.php | 2 +- .../language/indonesian/common_lang.php | 2 +- .../src/codepot/language/korean/code_lang.php | 6 ++- .../codepot/language/korean/common_lang.php | 14 +++--- codepot/src/codepot/views/code_folder.php | 2 +- codepot/src/codepot/views/code_history.php | 2 +- codepot/src/codepot/views/code_revision.php | 2 +- codepot/src/codepot/views/code_search.php | 49 +++++++++++++------ codepot/src/config.php.in | 3 ++ 12 files changed, 70 insertions(+), 31 deletions(-) diff --git a/codepot/etc/codepot.ini.in b/codepot/etc/codepot.ini.in index 99f78514..ac722330 100644 --- a/codepot/etc/codepot.ini.in +++ b/codepot/etc/codepot.ini.in @@ -173,6 +173,20 @@ log_threshold = 0 ;------------------------------------------------------------------------------ force_project_delete = "no" +;------------------------------------------------------------------------------ +; When yes, a codepot page can use set_time_limit() to adjust the maximum +; execution time to override the global value. For example, the code search +; page can take very long if the code repository is very large. You can +; set this item to yes to allow such a page to complete its processing. +;------------------------------------------------------------------------------ +allow_set_time_limit = "no" + +;------------------------------------------------------------------------------ +; When yes, a user must sign in to be able to search code. +; When no, an anonymous user can search code. +;------------------------------------------------------------------------------ +signin_for_code_search = "yes" + ;------------------------------------------------------------------------------ ; customized footer ;------------------------------------------------------------------------------ diff --git a/codepot/src/codepot/controllers/code.php b/codepot/src/codepot/controllers/code.php index ccac3764..fe940184 100644 --- a/codepot/src/codepot/controllers/code.php +++ b/codepot/src/codepot/controllers/code.php @@ -507,7 +507,7 @@ class Code extends Controller $this->load->model ('SubversionModel', 'subversion'); $login = $this->login->getUser (); - if (CODEPOT_SIGNIN_COMPULSORY && $login['id'] == '') + if ((CODEPOT_SIGNIN_COMPULSORY || CODEPOT_SIGNIN_FOR_CODE_SEARCH) && $login['id'] == '') redirect ("main/signin/" . $this->converter->AsciiTohex(current_url())); $project = $this->projects->get ($projectid); @@ -533,7 +533,6 @@ class Code extends Controller redirect ("main/signin/" . $this->converter->AsciiTohex(current_url())); } - $this->_search_code ($project, $login); } } diff --git a/codepot/src/codepot/language/english/code_lang.php b/codepot/src/codepot/language/english/code_lang.php index aca71e1f..3541ef77 100644 --- a/codepot/src/codepot/language/english/code_lang.php +++ b/codepot/src/codepot/language/english/code_lang.php @@ -5,4 +5,6 @@ $lang['CODE_PROPERTY'] = 'Property'; $lang['CODE_MSG_COMMITTED_BY'] = 'Committed by %s'; $lang['CODE_MSG_COMMITTED_BY_ON'] = 'Committed by %s on %s'; + +$lang['CODE_BAD_SEARCH_PATTERN'] = 'Bad search pattern'; ?> diff --git a/codepot/src/codepot/language/english/common_lang.php b/codepot/src/codepot/language/english/common_lang.php index 38b17f6f..07035749 100644 --- a/codepot/src/codepot/language/english/common_lang.php +++ b/codepot/src/codepot/language/english/common_lang.php @@ -3,7 +3,6 @@ $lang['Administration'] = 'Administration'; $lang['All'] = 'All'; $lang['Attachment'] = 'Attachment'; $lang['Attachments'] = 'Attachments'; -$lang['Author'] = 'Author'; $lang['Blame'] = 'Blame'; $lang['Cancel'] = 'Cancel'; $lang['Change'] = 'Change'; @@ -12,6 +11,7 @@ $lang['Code'] = 'Code'; $lang['Code changes'] = 'Code changes'; $lang['Comment'] = 'Comment'; $lang['Commitable'] = 'Commitable'; +$lang['Commiter'] = 'Commiter'; $lang['Create'] = 'Create'; $lang['Created by'] = 'Created by'; $lang['Created on'] = 'Created on'; diff --git a/codepot/src/codepot/language/indonesian/common_lang.php b/codepot/src/codepot/language/indonesian/common_lang.php index b1efc997..2299d4ee 100644 --- a/codepot/src/codepot/language/indonesian/common_lang.php +++ b/codepot/src/codepot/language/indonesian/common_lang.php @@ -1,7 +1,6 @@ diff --git a/codepot/src/codepot/language/korean/common_lang.php b/codepot/src/codepot/language/korean/common_lang.php index 1d5b49f0..bc5efc25 100644 --- a/codepot/src/codepot/language/korean/common_lang.php +++ b/codepot/src/codepot/language/korean/common_lang.php @@ -3,7 +3,6 @@ $lang['Administration'] = '관리'; $lang['All'] = '모두'; $lang['Attachment'] = '첨부'; $lang['Attachments'] = '첨부'; -$lang['Author'] = '저자'; $lang['Blame'] = '책임전가'; $lang['Cancel'] = '취소'; $lang['Change'] = '변경'; @@ -12,6 +11,7 @@ $lang['Code'] = '코드'; $lang['Code changes'] = '코드변경'; $lang['Comment'] = '소견'; $lang['Commitable'] = '커밋가능'; +$lang['Commiter'] = '커밋터'; $lang['Create'] = '생성'; $lang['Created by'] = '최초생성인'; $lang['Created on'] = '최초생성시간'; @@ -87,12 +87,12 @@ $lang['Username'] = '사용자명'; $lang['Wiki'] = '위키'; $lang['Wikis'] = '위키'; -$lang['MSG_LOG_COMMIT_BY'] = '%s이(가) 커밋했습니다'; -$lang['MSG_LOG_CHANGE_BY'] = '%s이(가) 변경했습니다'; -$lang['MSG_LOG_CREATE_BY'] = '%s이(가) 생성했습니다'; -$lang['MSG_LOG_DELETE_BY'] = '%s이(가) 삭제했습니다'; -$lang['MSG_LOG_UPDATE_BY'] = '%s이(가) 갱신했습니다'; -$lang['MSG_LOG_REVPROP_CHANGE_BY'] = '리비전 속성 %s을(를) %s이(가) 변경했습니다'; +$lang['MSG_LOG_COMMIT_BY'] = '%s 커밋'; +$lang['MSG_LOG_CHANGE_BY'] = '%s 변경'; +$lang['MSG_LOG_CREATE_BY'] = '%s 생성'; +$lang['MSG_LOG_DELETE_BY'] = '%s 삭제'; +$lang['MSG_LOG_UPDATE_BY'] = '%s 갱신'; +$lang['MSG_LOG_REVPROP_CHANGE_BY'] = '리비전속성 %s 변경. 변경자 %s'; $lang['MSG_NO_DIFF'] = '차이점이 없습니다'; diff --git a/codepot/src/codepot/views/code_folder.php b/codepot/src/codepot/views/code_folder.php index eb9cab36..8cd88d90 100644 --- a/codepot/src/codepot/views/code_folder.php +++ b/codepot/src/codepot/views/code_folder.php @@ -184,7 +184,7 @@ $this->load->view ( print '' . $this->lang->line('Name') . ''; print '' . $this->lang->line('Revision') . ''; print '' . $this->lang->line('Size') . ''; - print '' . $this->lang->line('Author') . ''; + print '' . $this->lang->line('Commiter') . ''; print '' . $this->lang->line('Date') . ''; print '' . $this->lang->line('Blame') . ''; print '' . $this->lang->line('Difference') . ''; diff --git a/codepot/src/codepot/views/code_history.php b/codepot/src/codepot/views/code_history.php index b188bc3e..32da44b0 100644 --- a/codepot/src/codepot/views/code_history.php +++ b/codepot/src/codepot/views/code_history.php @@ -82,7 +82,7 @@ $this->load->view ( - + '; ?> diff --git a/codepot/src/codepot/views/code_revision.php b/codepot/src/codepot/views/code_revision.php index f9762165..b8503d9c 100644 --- a/codepot/src/codepot/views/code_revision.php +++ b/codepot/src/codepot/views/code_revision.php @@ -111,7 +111,7 @@ $history = $file['history']; id}/${xpar}/{$prev_revision}", '<<')?> lang->line('Revision')?>: id}/${xpar}/{$next_revision}", '>>')?> | - lang->line('Author')?>: | + lang->line('Committer')?>: | lang->line('Last updated on')?>: diff --git a/codepot/src/codepot/views/code_search.php b/codepot/src/codepot/views/code_search.php index efd869db..615db033 100644 --- a/codepot/src/codepot/views/code_search.php +++ b/codepot/src/codepot/views/code_search.php @@ -106,15 +106,19 @@ $this->load->view (
subversion->getFile ($project->id, $path, $revision); + //if ($file['type'] == 'file') return; + + $dirarray = array ($path); + + while (count($dirarray) > 0) { + $path = array_shift ($dirarray); + $file = $controller->subversion->getFile ($project->id, $path, $revision); + if ($file === FALSE || $file['type'] == 'file') continue;; + // search in a directory. $file_list = $file['content']; foreach ($file_list as $f) @@ -127,8 +131,15 @@ function search_and_show ($controller, $project, $file, $revision, $pattern) { $lines = explode ("\n", $file2['content']); //$matchkeys = preg_grep ("/{$pattern}/i", $lines, 0); - $matchlines = preg_grep ("/{$pattern}/", $lines, 0); - if (count($matchlines) > 0) + // TODO: allow regular expression + $escaped_pattern = preg_quote ($pattern, '/'); + $matchlines = @preg_grep ("/{$pattern}/", $lines, 0); + if ($matchlines === FALSE) + { + print $controller->lang->line('CODE_BAD_SEARCH_PATTERN'); + return; + } + else if (count($matchlines) > 0) { $hexpath = $controller->converter->AsciiToHex($fullpath); if ($revision <= 0) @@ -141,12 +152,12 @@ function search_and_show ($controller, $project, $file, $revision, $pattern) $revreq = "/{$file2['rev']}"; $revreqroot = '/' . $controller->converter->AsciiToHex ('.') . $revreq; } - + print '
  • '; print anchor ( "code/file/{$project->id}/{$hexpath}{$revreq}", htmlspecialchars($fullpath)); - + print '
    ';
     						foreach ($matchlines as $linenum => $line)
     						{
    @@ -155,21 +166,29 @@ function search_and_show ($controller, $project, $file, $revision, $pattern)
     							print "\n";
     						}
     						print '
    '; - + print '
  • '; } } else { - search_and_show ($controller, $project, $file2, $revision, $pattern); + + if ($recurse && count($file2['content']) > 0) + { + array_push ($dirarray, $fullpath); + } } } } } } -$file = $this->subversion->getFile ($project->id, $file['fullpath'], $revision); -search_and_show ($this, $project, $file, $revision, $pattern); +// the repository search can take very long. +// change the execution time limit to run this script forever if it's allowed. +if (CODEPOT_ALLOW_SET_TIME_LIMIT) set_time_limit (0); + +// TODO: prevent recursion to subdirectories depending on input +search_and_show ($this, $project, $file['fullpath'], $revision, $pattern, TRUE); ?>
    diff --git a/codepot/src/config.php.in b/codepot/src/config.php.in index c8547571..418def9b 100644 --- a/codepot/src/config.php.in +++ b/codepot/src/config.php.in @@ -74,6 +74,9 @@ function load_ini ($file) array ('log_threshold', 'integer', 0), array ('force_project_delete', 'boolean', FALSE), + array ('allow_set_time_limit', 'boolean', FALSE), + array ('signin_for_code_search', 'boolean', TRUE), + array ('footer', 'string', '') );
    lang->line('Revision')?>lang->line('Author')?>lang->line('Commiter')?> lang->line('Date')?> lang->line('Message')?>