Domanda

Vogliamo indice nostro (abbastanza grande collezione di) repository git utilizzando OpenGrok, e l'unica cosa che non sono stato in grado di capire è come indice di tutti i rami. Da quello che posso vedere, sembra che ho bisogno di avere copie controllato-out di ciascun ramo che voglio indice, quindi, se un repository ha, diciamo, una decina di rami, ho bisogno di avere una dozzina di copie di esso, uno per ogni ramo, ad esempio,

git-repo-with-many-branches-master/
git-repo-with-many-branches-branch1/
git-repo-with-many-branches-branch2/
       :
git-repo-with-many-branches-branch12/

E 'proprio vero? O c'è un modo per dire OpenGrok di guardare tutti i rami quando si crea il suo indice?

È stato utile?

Soluzione

Gli altri livelli OpenGrok è progettato per funzionare su più sistemi SCM che non funzionano come git, così purtroppo per voi è necessario controllare ogni ramo si desidera indicizzare come un repository git separata: - (

Si può sempre presentare un RFE per il supporto per la navigazione più rami in un repository git.

Altri suggerimenti

Ho scritto una sceneggiatura esattamente per questo scopo: daun . Sarà necessario utilizzare daun cli invece di git cli nel vostro lavoro cron. Da notare che non supporta OpenGrok storia git al momento della scrittura come noi siamo interessati solo a capacità di ricerca rapida OpenGrok. Si segnala nostri utenti OpenGrok a strumenti come GitHub / Bitbucket per la storia git web-based.

Ecco uno script bash che ho scritto per fare esattamente questo. Sarà clonare eventuali nuove filiali, aggiornare le filiali esistenti ed eliminare i rami che non esistono più. Ecco le istruzioni che "lavoro"; si può scegliere di rendere le cose più sicuro, ma questo è abbastanza buono se il server è accessibile solo sulla LAN. Ho una configurazione job cron che appena lo gestisce ogni 30 minuti sul server. Per impostare il lavoro cron per eseguire come root, eseguire:

sudo crontab -e

Quindi incollare in questi contenuti:

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

Quindi scrivere e vicino:

:wq

È necessario installare "aspettarsi", che lo script utilizza per inserire la password della vostra chiave SSH. Uno di questi due comandi funzionerà a seconda quale sistema operativo Linux che si sta utilizzando:

sudo yum install expect
sudo apt-get install expect

Quindi creare un file a /usr/local/bin/opengrok_index.sh:

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

Quindi, incollare il contenuto dello script (dal fondo a questo post), e modificare le variabili in alto in base al sistema. Avanti, modificare le autorizzazioni in modo che solo root possa leggerlo (che ha le password in esso):

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

Probabilmente si desidera verificare l'esecuzione dello script manualmente e farlo funzionare, prima di aspettarsi il lavoro cron per lavorare. Si tratta di un particolare script che ho scritto per la mia configurazione particolare, quindi potrebbe essere necessario mettere in alcune dichiarazioni di eco e fare un po 'di debug per farlo funzionare correttamente:

sudo /usr/local/bin/opengrok_index.sh

Note aggiuntive:

  • Questo script accede al GIT su SSH (non HTTPS). Come tale, il tuo GIT_USER deve esistere sul sistema, e hanno una chiave SSH sotto /home/user/.ssh/id_rsa che ha accesso al repository GIT. Questo è roba GIT login standard, quindi non andrà oltre qui. Lo script entrare nel GIT_USER_SSH_PASSWORD quando richiesto
  • Lo script verifica tutti i file come GIT_USER, quindi potrebbe essere necessario "chown" il tuo CHECKOUT_LOCATION a tale utente

Script:

#!/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

Io non so niente di OpenGrok ma ovviamente è possibile modificare i rami utilizzando Git:

git checkout master
# do the indexing here
git checkout branch1
# indexing
git checkout branch2
# and so on...
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top