* git_get_repos_info_: Rewrite with more generic code. Detect
authorBenoit Sigoure <[email protected]>
Wed, 21 Nov 2007 13:00:39 +0000 (21 14:00 +0100)
committerBenoit Sigoure <[email protected]>
Wed, 21 Nov 2007 13:00:47 +0000 (21 14:00 +0100)
git-svn repositories separately from Git repositories.
* git_warn_missing_prop: New.  Factor some code from...
* get_mailto_property: ... here.
* svn_commit: Use `--signoff' instead of `-s'.  Do not sign git-svn
commits.

Signed-off-by: Benoit Sigoure <[email protected]>
svn-wrapper.sh

index 69f11f4..0d57067 100755 (executable)
@@ -546,12 +546,24 @@ get_svn_diff_and_diffstat()
   fi
 }
 
-# Helper.  Sets the variables repos_url, git_branch, git_head, repos_root and
-# extra_repos_info properly.
+# Helper.  Sets the variables repos_url, git_branch, git_head, repos_root,
+# extra_repos_info and using_git_svn properly.
 git_get_repos_info_()
 {
   # FIXME: 1st commit: "fatal: bad default revision 'HEAD'" on stderr
-  repos_url=`git config --get svn-remote.svn.url`
+  git_config_list=`git config -l`
+  using_git_svn=false
+  case $git_config_list in #(
+    *svn-remote.*.url=*)
+      repos_url=`echo "$git_config_list" \
+                 | sed '/^svn-remote.svn.url=\(.*\)$/!d;s//\1/'`
+      using_git_svn=:
+      ;; #(
+    *remote.origin.url=*)
+      repos_url=`echo "$git_config_list" \
+                 | sed '/^remote.origin.url=\(.*\)$/!d;s//\1/'`
+      ;;
+  esac
   test -z "$repos_url" && repos_url='(git:unknown)'
   git_branch=`git branch | awk '/^\*/ { print substr($0, 3) }'`
   if [ x"$git_branch" = x'(no branch)' ]; then
@@ -563,6 +575,22 @@ git_get_repos_info_()
   repos_root=$repos_url
 }
 
+# git_warn_missing_prop(PROP-NAME, SAMPLE-VALUE)
+git_warn_missing_prop()
+{
+  if $using_git_svn; then
+    warn "No $1 property set for this repository.
+This is a git-svn repository, so you can set it in an SVN working copy:
+  svn propset $1 $2 .
+Otherwise you can just set the property in your git-svn repository:
+  git config svnw.$1 $2"
+  else
+    warn "No $1 property set for this repository.
+You can set it like this:
+  git config svnw.$1 $2"
+  fi
+}
+
 # Helper.  Find the `mailto' property, be it an SVN property or a git-config
 # option.  Relies on the value of $change_log_dir and sets the values of
 # $mailto (the value of the `mailto' property) and $to (a string to append in
@@ -582,11 +610,7 @@ get_mailto_property()
       mailto=`echo "$mailto" | sed "$sed_tmp"`
     fi
     if [ x"$mailto" = x ]; then
-      warn 'No mailto property set for this repository.
-If this is a git-svn repository, do this in a SVN working copy:
-  svn propset mailto [email protected],[email protected] .
-If this is a real git repository, do this:
-  git config svnw.mailto [email protected],[email protected]'
+      git_warn_missing_prop 'mailto' '[email protected],[email protected]'
     fi
   else
     mailto=`$SVN propget mailto "$change_log_dir"`
@@ -958,11 +982,7 @@ $internal_tags" >>"$tmp_log.tmp"
         projname=`echo "$projname" | sed "$sed_tmp"`
       fi
       if [ x"$projname" = x ]; then
-        warn 'No project name set for this repository.
-If this is a git-svn repository, do this in a SVN working copy:
-  svn propset project myproj .
-If this is a real git repository, do this:
-  git config svnw.project myproj'
+        git_warn_missing_prop 'project' 'myproj'
       fi
     else
       projname=`$SVN propget project "$change_log_dir"`
@@ -1309,8 +1329,8 @@ $mail_title"
     extra_files=`echo "$extra_files" | sed "$tmp_sed" | tr ':' '\n'`
   fi
 
-  # Always sign the commits with Git.
-  $git_mode && set dummy -s "$@" && shift
+  # Always sign the commits with Git (but not with git-svn).
+  $using_git_svn || $git_mode && set dummy --signoff "$@" && shift
 
   # Update the Git index if necessary (just in case the user changed his
   # working copy in the mean time)
@@ -1348,8 +1368,8 @@ $mail_title"
   if $git_mode; then
     svn_diff=`git diff --ignore-all-space --no-color -C 'HEAD^' HEAD`
     svn_diff_stat=`git diff --stat --ignore-all-space --no-color -C 'HEAD^' HEAD`
-    grep svn-remote "$change_log_dir/.git/config" >/dev/null 2>&1 && \
-      notice 'Do not forget to use: git-svn dcommit to push your commits in SVN'
+    $using_git_svn &&
+      notice 'Do not forget to use `git-svn dcommit` to push your commits in SVN'
   else
     # Fetch the ChangeSet and filter out the ChangeLog entry. We don't use
     # svn diff -c because this option is not portable to older svn versions.