2009-12-12 239 views
4

我們希望使用OpenGrok爲我們的(相當大的)git倉庫集合編制索引,而我一直無法弄清楚的是如何索引所有分支。從我所看到的情況來看,它似乎需要檢出我想要索引的每個分支的副本,因此,如果存儲庫有十幾個分支,我需要有十幾個副本,一個對於每個分支,例如,如何處理OpenGrok中的git分支?

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在創建索引時查看全部分支?

+0

這是4歲。是否有任何修改OpenGrok會在此期間改變答案? – 2014-05-08 20:10:10

+1

據我所知,沒有。 – ebneter 2014-05-08 20:52:14

回答

7

在OpenGrok其他層被設計爲在多個SCM系統並不像git的攜手,所以很遺憾你你有你想要的每個分支作爲一個單獨的git倉庫檢查出指數:-(

你總可以提起RFE支持在一個Git倉庫中瀏覽多個分支。

+1

啊,無賴。不過謝謝你的回答! – ebneter 2009-12-14 08:30:20

-2

我不知道OpenGrok什麼,但你當然可以用改變分支機構的Git:

git checkout master 
# do the indexing here 
git checkout branch1 
# indexing 
git checkout branch2 
# and so on... 
+0

問題是,據我所知,OpenGrok本身並不知道如何做到這一點。 – ebneter 2009-12-13 07:29:50

0

我有爲此寫了一個腳本構成:daun。您需要在您的cron工作中使用daun cli而不是git cli。請注意,由於我們只對OpenGrok快速搜索功能感興趣,因此它在撰寫本文時不支持OpenGrok git歷史記錄。我們將OpenGrok用戶指向GitHub/Bitbucket等基於Web的git歷史記錄工具。

0

這是我寫的一個bash腳本。它將克隆任何新分支,更新任何現有分支,並刪除不再存在的分支。這裏是「工作」的說明;您可以選擇讓事情更安全,但如果您的服務器只能在您的局域網上訪問,這已經足夠了。我有一個cron作業設置,每隔30分鐘在服務器上運行一次。要設置cron作業,以root身份運行,運行:

sudo crontab -e 

然後粘貼這些內容:

*/30 * * * * /usr/local/bin/opengrok_index.sh 

然後寫入和關閉:

:wq 

您需要安裝腳本用來輸入ssh密鑰的密碼的「expect」。

sudo yum install expect 
sudo apt-get install expect 

然後創建在/usr/local/bin/opengrok_index.sh文件:

sudo vi /usr/local/bin/opengrok_index.sh 

接下來,粘貼在單這兩個命令將根據您所使用的Linux操作系統工作腳本的內容(從這篇文章的底部),並根據您的系統更改頂部的變量。接下來,更改權限,以便只有root可以讀它(它有它的密碼):

sudo chmod 700 /usr/local/bin/opengrok_index.sh 

你可能想測試手動運行該腳本,並得到它的工作,期待cron作業工作之前。這是我寫的我的特別設置一個特定的腳本,所以你可能需要把一些回聲報表,並做一些調試以達到正常工作:

sudo /usr/local/bin/opengrok_index.sh 

其他注意事項:

  • 這腳本通過SSH(不是HTTPS)登錄到GIT。因此,您的系統上必須存在您的GIT_USER,並且在擁有訪問GIT倉庫的 /home/user/.ssh/id_rsa下有SSH密鑰。這是標準GIT登錄內容的 ,所以我不會在這裏重述。該腳本將 進入GIT_USER_SSH_PASSWORD當提示
  • 腳本檢查出所有的文件GIT_USER,所以你可能需要「CHOWN」你CHECKOUT_LOCATION到用戶

腳本:

#!/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="[email protected]" 

    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