Opengrok에서 GIT 브랜치를 어떻게 처리합니까?
문제
OpenGrok을 사용하여 (상당히 큰) GIT 리포지토리를 색인하고 싶습니다. 내가 알아낼 수 없었던 것은 모든 지점을 색인화하는 방법입니다. 내가 볼 수있는 바에 따르면, 색인하려는 각 지점의 사본을 체크 아웃해야 할 것 같습니다. 따라서 저장소에 수십 개의 지점이 있으면 12 개의 사본이 있어야합니다. 각 지점에 대해
git-repo-with-many-branches-master/
git-repo-with-many-branches-branch1/
git-repo-with-many-branches-branch2/
:
git-repo-with-many-branches-branch12/
정말 사실인가요? 아니면 Opengrok에게 볼 수있는 방법이 있습니까? 모두 지수를 만들 때 분기?
해결책
OpenGrok의 다른 레이어는 GIT처럼 작동하지 않는 여러 SCM 시스템에서 작동하도록 설계되었으므로 불행히도 별도의 GIT 저장소로 색인하려는 각 지점을 확인해야합니다.
GIT 저장소에서 여러 가지를 탐색하기 위해 항상 RFE를 제출할 수 있습니다.
다른 팁
이 목적을 위해 정확히 대본을 작성했습니다. 만. 사용해야합니다 daun
대신 CLI git
당신의 크론 직업에서 클리. Opengrok 빠른 검색 기능에만 관심이 있기 때문에 글을 쓰는 시점에 Opengrok Git 역사를 지원하지 않습니다. 우리는 OpenGrok 사용자에게 웹 기반 GIT 기록을위한 GitHub/Bitbucket과 같은 도구를 지적 할 것입니다.
여기에 정확히 이것을하기 위해 쓴 bash 스크립트가 있습니다. 새 지점을 복제하고 기존 지점을 업데이트하며 더 이상 존재하지 않는 지점을 삭제합니다. 다음은 "일"하는 지침입니다. 당신은 물건을 더 안전하게 만들도록 선택할 수 있지만 서버가 LAN에서만 액세스 할 수있는 경우 충분합니다. 서버에서 30 분마다 실행하는 Cron 작업 설정이 있습니다. 루트로 실행하기 위해 Cron 작업을 설정하려면 실행하십시오.
sudo crontab -e
그런 다음이 내용에 붙여 넣습니다.
*/30 * * * * /usr/local/bin/opengrok_index.sh
그런 다음 쓰고 닫습니다.
:wq
스크립트가 SSH 키의 비밀번호를 입력하는 데 사용하는 "기대"를 설치해야합니다. 이 두 명령 중 하나는 사용중인 Linux OS에 따라 작동합니다.
sudo yum install expect
sudo apt-get install expect
그런 다음 /usr/local/bin/opengrok_index.sh에서 파일을 만듭니다.
sudo vi /usr/local/bin/opengrok_index.sh
다음으로 스크립트의 내용 (이 게시물 하단)에 붙여 넣고 시스템에 따라 상단의 변수를 변경하십시오. 다음으로 루트 만 읽을 수 있도록 권한을 변경하십시오 (비밀번호가 있습니다).
sudo chmod 700 /usr/local/bin/opengrok_index.sh
CRON 작업이 작동하기 전에 스크립트 실행을 수동으로 실행하고 작동하게하려고합니다. 이것은 내가 특정 설정에 대해 작성한 특정 스크립트이므로 에코 진술을 제시하고 올바르게 작동하도록 디버깅을해야 할 수도 있습니다.
sudo /usr/local/bin/opengrok_index.sh
추가 메모 :
- 이 스크립트는 SSH (HTTPS 아님)를 통해 GIT에 로그인합니다. 따라서 GIT_USER는 시스템에 존재해야하며 git repo에 액세스 할 수있는 /home/user/.ssh/id_rsa 아래에 SSH 키가 있어야합니다. 이것은 표준 git 로그인 물건이므로 여기서 넘어 가지 않을 것입니다. 스크립트는 프롬프트되면 git_user_ssh_password로 입력됩니다
- 스크립트는 모든 파일을 GIT_USER로 체크 아웃하므로 해당 사용자에게 checkout_location을 "chown"해야 할 수도 있습니다.
스크립트:
#!/bin/bash
SUDO_PASSWORD="password"
CHECKOUT_LOCATION="/var/opengrok/src/"
GIT_PROJECT_NAME="Android"
GIT_USER="username"
GIT_USER_SSH_PASSWORD="password"
GIT_URL="yourgit.domain.com"
OPENGROK_BINARY_FILE="/usr/local/opengrok-0.12.1.6/bin/OpenGrok"
# Run command as GIT_USER which has Git access
function runGitCommand {
git_command="$@"
expect_command="
spawn sudo -u $GIT_USER $git_command
expect {
\"*password for*\" {
send \"$SUDO_PASSWORD\"
send \"\r\"
exp_continue
}
\"*Enter passphrase for key*\" {
send \"$GIT_USER_SSH_PASSWORD\"
send \"\r\"
exp_continue
}
}"
command_result=$(expect -c "$expect_command" || exit 1)
}
# Checkout the specified branch over the network (slow)
function checkoutBranch {
branch=$1
# Check out branch if it does not exist
if [ ! -d "$branch" ]; then
runGitCommand git clone ssh://$GIT_URL/$GIT_PROJECT_NAME
# Rename project to the branch name
mv $GIT_PROJECT_NAME $branch || exit 1
# Otherwise update the existing branch
else
cd $branch || exit 1
runGitCommand git fetch
runGitCommand git pull origin $branch || exit 1
cd ..
fi
}
# If the branch directory does not exist, copy the master
# branch directory then switch to the desired branch.
# This is faster than checkout out over the network.
# Otherwise, update the exisiting branch directory
function updateBranch {
branch=$1
if [ ! -d "$branch" ]; then
mkdir $branch || exit 1
rsync -av master/ $branch || exit 1
cd $branch || exit 1
runGitCommand git checkout -b $branch origin/$branch
cd ..
else
cd $branch || exit 1
runGitCommand git pull origin $branch || exit 1
cd ..
fi
}
# Change to the OpenGrok indexing location to checkout code
cd $CHECKOUT_LOCATION || exit 1
# Check out master branch
checkoutBranch master
# Get a list of all remote branches
cd master || exit 1
old_ifs=$IFS
IFS=$'\n'
origin_branches=( $(git branch -r) )
IFS=$old_ifs
origin_branches_length=${#origin_branches[@]}
cd .. # Move out of "master" directory
# Loop through and check out all branches
branches=(master)
for origin_branch in "${origin_branches[@]}"
do
# Strip the "origin/" prefix from the branch name
branch=${origin_branch#*/}
# Ignore the "HEAD" branch
# Also skip master since it has already been updated
if [[ $branch == HEAD* ]] || [[ $branch == master* ]]; then
continue
fi
branches+=("$branch")
updateBranch $branch
done
# Get list of branches currently in OpenGrok
old_ifs=$IFS
IFS=$'\n'
local_branches=( $(ls -A1) )
size=${#local_branches[@]}
IFS=$old_ifs
# Get list of branches that are in OpenGrok, but do not exist
# remotely. These are branches that have been deleted
deleted_branches=()
for local_branch in "${local_branches[@]}"
do
skip=0
for branch in "${branches[@]}"
do
if [[ $local_branch == $branch ]]; then
skip=1;
break;
fi
done
if [[ $skip == "0" ]]; then
deleted_branches+=("$local_branch")
fi
done
# Change to checkout directory again, in case some future code
# change brings us somewhere else. We are deleting recursively
# here and cannot make a mistake!
cd $CHECKOUT_LOCATION
# Delete any branches that no longer exist remotely
for deleted_branch in ${deleted_branches[@]}
do
rm -rf ./$deleted_branch
done
# Reindex OpenGrok
$OPENGROK_BINARY_FILE index
나는 OpenGrok에 대해 아무것도 모르지만 물론 GIT를 사용하여 지점을 변경할 수 있습니다.
git checkout master
# do the indexing here
git checkout branch1
# indexing
git checkout branch2
# and so on...