-[alias]
- co = checkout
- ci = commit
-[default]
-lib = \
- error() { \
- echo "mr: $@" >&2; \
- exit 1; \
- }
-update = \
- if [ -d "$MR_REPO"/.svn ]; then \
- svn update "$@"; \
- elif [ -d "$MR_REPO"/.git ]; then \
- git pull origin master "$@"; \
- else \
- error "unknown repo type"; \
- fi
-status = \
- if [ -d "$MR_REPO"/.svn ]; then \
- svn status "$@"; \
- elif [ -d "$MR_REPO"/.git ]; then \
- git status "$@" || true; \
- else \
- error "unknown repo type"; \
- fi
-commit = \
- if [ -d "$MR_REPO"/.svn ]; then \
- svn commit "$@"; \
- elif [ -d "$MR_REPO"/.git ]; then \
- git commit -a "$@" && git push --all; \
- else \
- error "unknown repo type"; \
- fi
-diff = \
- if [ -d "$MR_REPO"/.svn ]; then \
- svn diff "$@"; \
- elif [ -d "$MR_REPO"/.git ]; then \
- git diff "$@"; \
- else \
- error "unknown repo type"; \
+[ALIAS]
+co = checkout
+ci = commit
+ls = list
+
+[DEFAULT]
+order = 10
+lib =
+ error() {
+ echo "mr: $@" >&2
+ exit 1
+ }
+ hours_since() {
+ if [ -z "$1" ] || [ -z "$2" ]; then
+ error "mr: usage: hours_since action num"
+ fi
+ for dir in .git .svn .bzr CVS .hg _darcs; do
+ if [ -e "$MR_REPO/$dir" ]; then
+ flagfile="$MR_REPO/$dir/.mr_last$1"
+ break
+ fi
+ done
+ if [ -z "$flagfile" ]; then
+ error "cannot determine flag filename"
+ fi
+ delta=$(perl -wle 'print -f shift() ? int((-M _) * 24) : 9999' "$flagfile")
+ if [ "$delta" -lt "$2" ]; then
+ exit 0
+ else
+ touch "$flagfile"
+ exit 1
+ fi
+ }
+ get_git_repo_type()
+ {
+ if [ -d "$1"/.git ] && [ -d "$1"/.git/refs/heads ] &&
+ [ -d "$1"/.git/objects ] && [ -f "$1"/.git/config ];
+ then
+ echo non-bare
+ elif [ -d "$1"/refs/heads ] && [ -d "$1"/refs/tags ] &&
+ [ -d "$1"/objects ] && [ -f "$1"/config ]; then
+ local bare
+ bare="$(GIT_CONFIG="$1"/config git-config --get core.bare)"
+ case "$bare" in
+ true) echo bare;;
+ false) echo fake-bare;;
+ *) return 255;;
+ esac
+ else
+ return 1
+ fi
+ }
+ is_git_repo() {
+ get_git_repo_type "$1" >/dev/null
+ }
+ get_repo_type() {
+ if [ -d "$1"/.svn ]; then
+ echo svn
+ elif is_git_repo "$1"; then
+ echo git
+ elif [ -d "$1"/.bzr ]; then
+ echo bzr
+ elif [ -d "$1"/CVS ]; then
+ echo CVS
+ elif [ -d "$1"/.hg ]; then
+ echo hg
+ elif [ -d "$1"/_darcs ]; then
+ echo darcs
+ else
+ echo unknown
+ fi
+ }
+
+update =
+ case "$(get_repo_type "$MR_REPO")" in
+ svn) svn update "$@";;
+ git)
+ # all this is because of a bug in git-fetch, which requires GIT_DIR set
+ local git_dir_override; git_dir_override=.git
+ case "$(get_git_repo_type "$MR_REPO")" in
+ fake-bare) git_dir_override="$MR_REPO";;
+ esac
+ args="$@"
+ [ -z "$args" ] && args="-t origin master"
+ eval GIT_DIR="$git_dir_override" git pull "$args"
+ ;;
+ bzr) bzr merge "$@";;
+ CVS) cvs update "$@";;
+ hg) hg pull "$@" && hg update "$@";;
+ darcs) darcs pull -a "$@";;
+ *) error "unknown repo type";;
+ esac
+
+status =
+ case "$(get_repo_type "$MR_REPO")" in
+ svn) svn status "$@";;
+ git) git status "$@" || :;;
+ bzr) bzr status "$@";;
+ CVS) cvs status "$@";;
+ hg) hg status "$@";;
+ darcs) darcs whatsnew -ls "$@";;
+ *) error "unknown repo type";;
+ esac
+
+commit =
+ case "$(get_repo_type "$MR_REPO")" in
+ svn) svn commit "$@";;
+ git)
+ case "$(get_git_repo_type "$MR_REPO")" in
+ bare) error "cannot commit to bare git repositories";;
+ fake-bare) error "commit does not work for fake bare git repositories (yet).";;
+ esac
+ git commit -a "$@" && git push --all
+ ;;
+ bzr) bzr commit "$@" && bzr push;;
+ CVS) cvs commit "$@";;
+ hg) hg commit -m "$@" && hg push;;
+ darcs) darcs commit -a -m "$@" && darcs push -a;;
+ *) error "unknown repo type";;
+ esac
+
+diff =
+ case "$(get_repo_type "$MR_REPO")" in
+ svn) svn diff "$@";;
+ git)
+ case "$(get_git_repo_type "$MR_REPO")" in
+ bare) error "cannot diff in bare git repositories";;
+ fake-bare) error "diff does not work for fake bare git repositories (yet).";;
+ esac
+ git diff "$@"
+ ;;
+ bzr) bzr diff "$@";;
+ CVS) cvs diff "$@";;
+ hg) hg diff "$@";;
+ darcs) darcs diff "$@";;
+ *) error "unknown repo type";;
+ esac
+
+log =
+ case "$(get_repo_type "$MR_REPO")" in
+ svn) svn log"$@";;
+ git) git log "$@";;
+ bzr) bzr log "$@";;
+ CVS) cvs log "$@";;
+ hg) hg log "$@";;
+ darcs) darcs changes "$@";;
+ *) error "unknown repo type";;
+ esac
+
+register =
+ if [ -n "$1" ]; then
+ cd "$1"