From 1bc07cc4c421ba330ad7d8297aeea7862a3cb126 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 16 Mar 2013 18:07:50 -0400 Subject: Use git-sh-setup for git-rewrite-branch, clean up it's usage() --- git-rewrite-branch | 70 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/git-rewrite-branch b/git-rewrite-branch index c9838cf..5135fdc 100755 --- a/git-rewrite-branch +++ b/git-rewrite-branch @@ -1,4 +1,31 @@ -#!/bin/bash -euE +#!/bin/bash -eE +# +# Copyright (c) 2012-2013 Luke Shumaker +# + +USAGE='[-h] [-v] [--svn] ...' +LONG_USAGE='Like filter-branch, but can be used to update branches. + +This creates or updates from . If already +exists, it only runs new commits through the filter. This way, this can be +used to pull from a remote with a different layout than yours. + +This will append "git-rewrite-id" to all commit messages, similar to +"git-svn-id" with `git-svn`. + + -h Show this text + -v Be more verbose + --svn Use an existing "git-svn-id" instead of "git-rewrite-id" + (in-branch was generated by git-svn) + + is passed directly to `git filter-branch`, and therefore has the same +format. +' +SUBDIRECTORY_OP=Yes +OPTIONS_SPEC= +. git-sh-setup +. git-sh-i18n +require_work_tree_exists # when $gitmode is true, $ibranch's commits are used as IDs gitmode=true @@ -8,19 +35,19 @@ ibranch='' obranch='' wbranch='' -usage() { - echo 'malformed call to internal function' +panic() { + echo 'panic: malformed call to internal function' + exit 1 } verbose() { - : "$*" - #echo "$*" + : } ################################################################################ id2commit() { - [[ $# = 2 ]] || { usage; return 1; } + [[ $# = 2 ]] || panic local branch=$1 local id=$2 if [[ $branch == $ibranch ]] && $gitmode; then @@ -31,7 +58,7 @@ id2commit() { } commit2id() { - [[ $# = 2 ]] || { usage; return 1; } + [[ $# = 2 ]] || panic local branch=$1 local commit=$2 if [[ $branch == $ibranch ]] && $gitmode; then @@ -43,7 +70,7 @@ commit2id() { # commit2commit c2c() { - [[ $# = 3 ]] || { usage; return 1; } + [[ $# = 3 ]] || panic local from=$1 local to=$2 local commit=$3 @@ -60,15 +87,30 @@ c2c() { main() { # Parse command line arguments ######################################### - if [[ $1 = '--svn' ]]; then - gitmode=false - tag='git-svn-id' - shift - fi + while true; do + case "${1:-}" in + --svn) + gitmode=false + tag='git-svn-id' + shift + ;; + -h) + usage + return 0 + ;; + -v) + verbose() { echo "$*"; } + shift + ;; + *) + break + ;; + esac + done if [[ $# < 3 ]]; then usage - exit 1 + return 1 fi ibranch=$1 -- cgit v1.1-4-g5e80