سؤال

نريد فهرسة (مجموعة كبيرة إلى حد ما من) مستودعات git باستخدام opengrok، والشيء الوحيد الذي لم أتمكن من معرفة كيفية فهرسة جميع الفروع. من ما أستطيع أن أرى، يبدو أنني بحاجة إلى نسخ سحب من كل فرع أرغب في الفهرس، لذلك، إذا كان مستودع، فإن عشرات فروع، أحتاج إلى عشر نسخ منه، واحد لكل فرع، على سبيل المثال،

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 للعمل على أنظمة SCM متعددة التي لا تعمل مثل GIT، لذلك لسوء الحظ، عليك التحقق من كل فرع تريد الفهرس كمستودع منفصل GIT :-(

يمكنك دائما تقديم ملف RFE لدعم تصفح فروع متعددة في مستودع GIT.

نصائح أخرى

لقد كتبت نصي بالضبط لهذا الغرض: غون. وبعد سوف تحتاج إلى استخدام daun CLI بدلا من git cli في وظيفة كرون الخاص بك. لاحظ أنه لا يدعم تاريخ OpenGrok Git في وقت كتابة هذا التقرير حيث نحن مهتمون فقط بإمكانية البحث السريع OpenGrok. سوف نشير مستخدمينا OpenGrok إلى أدوات مثل Github / Bitbucket لتاريخ GIT المستندة إلى الويب.

هنا هو نص باش أنا كتبت للقيام بذلك بالضبط. سوف يستنسخ أي فروع جديدة وتحديث أي فروع حالية وحذف الفروع التي لم تعد موجودة. فيما يلي تعليمات أن "العمل"؛ قد تختار أن تجعل الأمور أكثر أمانا ولكن هذا جيد بما فيه الكفاية إذا كان الخادم الخاص بك يمكن الوصول إليه إلا على شبكة LAN الخاصة بك. لدي برنامج إعداد وظيفة كرون يديره كل 30 دقيقة على الخادم. لإعداد مهمة Cron لتشغيلها كجذر، تشغيل:

sudo crontab -e

ثم لصق في هذه المحتويات:

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

ثم الكتابة والإغلاق:

:wq

ستحتاج إلى تثبيت "توقع" الذي يستخدمه البرنامج النصي لإدخال كلمة مرور مفتاح SSH الخاص بك. ستعمل واحدة من هاتين النظامين اعتمادا على نظام التشغيل Linux الذي تستخدمه:

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

ربما تريد اختبار تشغيل البرنامج النصي يدويا والحصول على العمل، قبل توقع عمل كرون للعمل. هذا سيناريو معين كتبته لإعداد معين، لذلك قد تحتاج إلى وضع بعض بيانات الصدى والقيام ببعض تصحيح الأخطاء للحصول عليها بشكل صحيح:

sudo /usr/local/bin/opengrok_index.sh

ملاحظات إضافية:

  • يسجل هذا البرنامج النصي إلى GIT على SSH (وليس https). على هذا النحو، يجب أن يوجد GIT_USER الخاص بك على النظام، ولديك مفتاح SSH تحت /home/user/.ssh/id_rsa الذي يمكنه الوصول إلى Repo 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="$@"

  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...
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top