[tasks] 02/02: Switch to JSON data format since that's easier to auto-merge
Ximin Luo
infinity0 at debian.org
Fri Oct 28 21:15:11 UTC 2016
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository tasks.
commit 70903ed87ce516e8f976deff82337b646bf1056e
Author: Ximin Luo <infinity0 at debian.org>
Date: Fri Oct 28 23:14:51 2016 +0200
Switch to JSON data format since that's easier to auto-merge
---
.gitattributes | 2 ++
README | 17 +++++++++++------
merge-tw-export | 35 +++++++++++++++++++++++++++++++++++
pending.z.json | 11 +++++++++++
task | 32 +++++++++++++++++++++++++++++++-
taskrc | 3 +++
6 files changed, 93 insertions(+), 7 deletions(-)
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..0dc187d
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+pending.data conflict-marker-size=72 merge=tw-export
+pending.z.json conflict-marker-size=72 merge=tw-export
diff --git a/README b/README
index 16891ef..0fb9acc 100644
--- a/README
+++ b/README
@@ -20,12 +20,17 @@ $ git pull # or git pull --rebase
$ ./task $hack $hack $hack # will automatically create a git commit
$ git push
-The raw data is stored in pending.data.
-
-From time to time you might have to manually merge it, e.g. if someone edited
-the same tasks as you. This may or may not be painful, time will tell... do
-note one case you have to handle with some care, see below. Everything else
-should just be a case of merging the fields of the task together.
+The raw data is stored in pending.data as well as pending.z.json. These two
+files are kept in-sync automatically by our scripts; you should not need to
+edit either of them during normal workflow. The other *.data files used by
+taskwarrior are autogenerated by task-history-git, and not checked in.
+
+pending.z.json is to help automated merges work a bit more smoothly, to reduce
+the amount of manual merge-conflict-resolution that is needed. Most of the
+time, you should not need to edit this file either. However, on occasion this
+can't be avoided, and you'll be *explicitly* asked to edit it. The JSON format
+hopefully makes this painless; time will tell if this is true. Note one case
+you have to handle with some care, see below:
IMPORTANT
=========
diff --git a/merge-tw-export b/merge-tw-export
new file mode 100755
index 0000000..ad19c25
--- /dev/null
+++ b/merge-tw-export
@@ -0,0 +1,35 @@
+#!/bin/bash
+# Git merge-driver to help with automatic merging of pending.data.
+#
+# This driver checks pending.z.json, and if it contains no merge conflict
+# markers then it simply imports that data into taskwarrior. This depends on
+# the hack that git will try to merge "pending.z.json" before "pending.data",
+# (I can't figure out why, must be something to do with hashing) and that is
+# why we call it "pending.z.json" not "pending.json".
+set -e
+target="$5"
+echo >&2 "$0: merging $target"
+# This is not necessary; the default git merge-driver works fine, but seeing
+# the previous message is useful to assure that pending.z.json is indeed being
+# merged before pending.data.
+if [ "$target" = "pending.z.json" ]; then
+ exec git merge-file -L "$target" --marker-size "$4" "$2" "$1" "$3"
+fi
+
+if ! grep -q "========================================================================" pending.z.json; then
+ echo >&2 "Auto-merging pending.data by importing pending.z.json into it."
+ rm -f pending.data; ./task rc.hooks=off import < pending.z.json
+ cat pending.data > "$2"
+else
+ cat >&2 <<eof
+================================================================================
+pending.z.json has conflicts. FIX THOSE MANUALLY FIRST, then run:
+ git add pending.z.json
+ rm -f pending.data; ./task rc.hooks=off import < pending.z.json
+ git add pending.data
+if this succeeds, then you can proceed with the rest of the merge - i.e. by
+fixing any other conflicts, then \`git add\` those, then finally git-commit.
+================================================================================
+eof
+ exit 1
+fi
diff --git a/pending.z.json b/pending.z.json
new file mode 100644
index 0000000..70047d2
--- /dev/null
+++ b/pending.z.json
@@ -0,0 +1,11 @@
+[
+ {
+ "description": "Add our initial tasks",
+ "entry": "20161024T161417Z",
+ "id": 1,
+ "modified": "20161024T161417Z",
+ "status": "pending",
+ "urgency": 0.0219178,
+ "uuid": "4c895653-e6aa-48e3-b123-6eff485211ea"
+ }
+]
diff --git a/task b/task
index 39f492f..329fcfa 100755
--- a/task
+++ b/task
@@ -2,6 +2,10 @@
set -e
workdir="$(git rev-parse --show-toplevel)"
+################################################################################
+
+# Set up. This part should be idempotent.
+
# Set up task-history-git
git submodule update --init
ln -rsf "$workdir/task-history-git/post-merge" "$(git rev-parse --git-dir)/hooks/post-merge"
@@ -9,6 +13,32 @@ ln -rsf "$workdir/task-history-git/post-merge" "$(git rev-parse --git-dir)/hooks
# Ensure local file exists
test -f "$workdir/taskrc.local" || touch "$workdir/taskrc.local"
+# Add our merge driver
+git config --local merge.conflictstyle diff3
+git config --local merge.tw-export.name "autogenerate pending.data from pending.z.json"
+git config --local merge.tw-export.driver "./merge-tw-export %O %A %B %L %P"
+
+################################################################################
+
export TASKRC="$workdir/taskrc"
export TASKDATA="$workdir"
-exec task "$@"
+
+set +e
+# Manually handle exit codes from here onwards
+
+#task import < pending.z.json 2>/dev/null 1>&2
+
+oldhead="$(git rev-parse HEAD)"
+task "$@"; x=$?
+# auto-export if we're not importing
+if ! echo "$*" | grep -q "\bimport\b"; then
+ # urgency values are autogenerated, rm them from the export
+ task rc.hooks=off export 2>/dev/null | python -m json.tool \
+ | grep -v '^ "urgency": ' > pending.z.json
+ newhead="$(git rev-parse HEAD)"
+ if [ "$oldhead" != "$newhead" ]; then
+ git add pending.z.json
+ git commit --amend --no-edit
+ fi
+fi
+exit $x
diff --git a/taskrc b/taskrc
index 4be74ff..dff79a3 100644
--- a/taskrc
+++ b/taskrc
@@ -4,5 +4,8 @@ verbose=blank,footnote,label,new-id,affected,edit,special,project,sync,filter,un
# Don't garbage collect, to have stable Task IDs
gc=off
+# Don't enable recurrence, we'd want a calendar for that anyways
+recurrence=no
+
# Include your own local overrides in taskrc.local
include ./taskrc.local
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/tasks.git
More information about the Reproducible-commits
mailing list