使用 Gerrit 审查代码

Gerrit Workflow

Alt none

启动 Gerrit

java -jar gerrit.war init -d /path/to/your/gerrit_application_directory

Set Permission(Nginx)

  • Create password file
    htpasswd -c /path/gerrit.password username
    
  • Add New User
    htpasswd -m /path/gerrit.password username
    
  • Nginx Configuration
    server {
       listen *:80;
       server_name gerrit;
       allow   all;
       deny    all;
    
       auth_basic "Welcomme to Gerrit !";
       auth_basic_user_file /path/gerrit.password;
    
       location / {
          proxy_pass  http://127.0.0.1:8080;
          proxy_set_header X-Forwarded-For $remote_addr;
          proxy_set_header Host $host;
       }
    }
    

Import Exist Project into gerrit

  • Checkout Exist Project
    cd $GERRIT_HOME/git
    git clone --bare ssh://[email protected]:PORT/TestGerrit.git
    

    Alt none

  • Restart Gerrit
    gerrit.sh  restart
    
  • Refresh Gerrit Projects Page Alt none

Create GitReview File

touch .gitreview

Edit gitreview file:

[gerrit]
host=192.168.1.109
port=29418
project=TestGerrit.git

Replication Configuration

cd $GERRIT_HOME/etc
touch replication.config

Edit replication.config file:

[remote "TestGerrit"]
url = ssh://[email protected]:PORT/${name}.git

Restart Gerrit

gerrit.sh  restart

Replication Plugin log file is located at $GERRIT_HOME/log/replication_log Alt none

Use git review command

Install git-review

  • Install Homebrew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
  • Install git review:
brew install git-review
  • Use git review
  git add files
  git commit
  git-review

Browse your commits

Alt none

Use git command

git add files
git commit
git push gerrit <branch>

Git repository configure:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    ignorecase = true
    precomposeunicode = true
[remote "origin"]
    url = ssh://[email protected]:PORT/TestGerrit
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master
[remote "gerrit"]
    url = ssh://[email protected]:PORT/TestGerrit.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    push = refs/heads/*:refs/for/*
[branch "DEV"]
    remote = origin
    merge = refs/heads/DEV
    push = refs/heads/DEV:refs/for/DEV

ref: https://review.openstack.org/Documentation/intro-quick.html

使用 htpasswd

Create New Password File

htpasswd -c /path/gerrit.password name

Add New User

htpasswd -m /path/gerrit.password user

Android JVM 修改 heap 大小

Gradle

Add the following lines to project build.gradle

android {
    dexOptions {
        javaMaxHeapSize "1g" 
    }
}  

Ant

set ANT_OPTS=-Xmx1024m

Misc

Alt none Alt none

ref: R1 R2

macOS Sierra Auto load ssh keys

OS: macOS 10.12.3

Create config file in your ssh folder:

vi ~/.ssh/config

Edit config file:

Host *
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa_build_server
IdentityFile ~/.ssh/id_rsa_mac

Replace the path with the path to you keys.

Shell Count the numbers of lines of code

Exclude empty & Comment lines.

find . -name “*.java”|xargs cat|grep -v -e ^$ -e ^\s*\/\/.*$|wc -l