author | Tero Marttila <terom@paivola.fi> |
Thu, 19 Dec 2013 23:22:12 +0200 | |
branch | dns-new |
changeset 95 | a756f317d083 |
parent 89 | 51270237a6ff |
child 96 | bed4765fc56f |
permissions | -rw-r--r-- |
82 | 1 |
#!/bin/bash |
2 |
# |
|
3 |
# HG wrappers |
|
4 |
||
5 |
## Run `hg ...` within $REPO. |
|
6 |
function hg { |
|
89
51270237a6ff
cleanup update, reintroduce separate hg repo
Tero Marttila <terom@paivola.fi>
parents:
82
diff
changeset
|
7 |
local repo=$1; shift |
51270237a6ff
cleanup update, reintroduce separate hg repo
Tero Marttila <terom@paivola.fi>
parents:
82
diff
changeset
|
8 |
cmd $HG -R "$repo" "${HG_ARGS[@]}" "$@" |
82 | 9 |
} |
10 |
||
11 |
## Does the repo have local modifications? |
|
12 |
function hg_modified { |
|
95
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
13 |
hg $1 id -i | grep -q '+' |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
14 |
} |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
15 |
|
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
16 |
## Get the date for the current commit as an unix timestamp |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
17 |
function hg_time { |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
18 |
local repo=$1 |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
19 |
local hg_unix= |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
20 |
local hg_tz= |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
21 |
|
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
22 |
local hg_date=$(hg $repo log -r . --template '{date|hgdate}') |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
23 |
local hg_unix=${hg_date% *} |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
24 |
local hg_tz=${hg_date#* } |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
25 |
|
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
26 |
[ -n "$hg_unix" ] || fail "failed to read hg time" |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
27 |
|
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
28 |
echo "$hg_unix" |
82 | 29 |
} |
30 |
||
31 |
## Output possible -u flag for commit. |
|
32 |
function hg_user { |
|
33 |
if [ ${SUDO_USER:-} ]; then |
|
34 |
echo '-u' "$SUDO_USER" |
|
35 |
||
36 |
elif [ $HOME ] && [ -e $HOME/.hgrc ]; then |
|
37 |
debug "using .hgrc user" |
|
38 |
echo '' |
|
39 |
||
40 |
else |
|
41 |
echo '-u' "$USER" |
|
42 |
fi |
|
43 |
} |
|
44 |
||
45 |
## Show changes in repo |
|
46 |
# hg_diff [path ...] |
|
47 |
function hg_diff { |
|
89
51270237a6ff
cleanup update, reintroduce separate hg repo
Tero Marttila <terom@paivola.fi>
parents:
82
diff
changeset
|
48 |
local repo=$1; shift |
51270237a6ff
cleanup update, reintroduce separate hg repo
Tero Marttila <terom@paivola.fi>
parents:
82
diff
changeset
|
49 |
hg $repo diff "$@" |
82 | 50 |
} |
51 |
||
52 |
## Commit changes in repo, with given message: |
|
53 |
# |
|
54 |
# hg_commit $msg |
|
55 |
# |
|
56 |
# Automatically determines possible -u to use when running with sudo. |
|
57 |
function hg_commit { |
|
89
51270237a6ff
cleanup update, reintroduce separate hg repo
Tero Marttila <terom@paivola.fi>
parents:
82
diff
changeset
|
58 |
local repo=$1 |
51270237a6ff
cleanup update, reintroduce separate hg repo
Tero Marttila <terom@paivola.fi>
parents:
82
diff
changeset
|
59 |
local msg=$2 |
82 | 60 |
local user_opt=$(hg_user) |
61 |
local msg_opt= |
|
62 |
||
63 |
[ $msg ] && msg_opt=('-m' "$msg") |
|
64 |
||
65 |
debug "$user_opt: $msg" |
|
89
51270237a6ff
cleanup update, reintroduce separate hg repo
Tero Marttila <terom@paivola.fi>
parents:
82
diff
changeset
|
66 |
hg $repo commit ${user_opt[@]} ${msg_opt[@]} |
82 | 67 |
} |