Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cn/CN-Public/cn-2024/git-crdt-ledger-template
1 result
Show changes
Commits on Source (2)
...@@ -10,7 +10,15 @@ Table of content: ...@@ -10,7 +10,15 @@ Table of content:
## Dependencies ## Dependencies
Requires [Git](https://git-scm.com/) to be installed and in the `PATH` environment variable. Executing `which git` on Linux or MacOS on the commandline should return a non-empty path to the installation directory (ex: `/usr/local/bin/git`). Windows users may try the [Windows Subsystem for Linux (WSL)](https://learn.microsoft.com/en-us/windows/wsl/install) but we have not tested it. Requires [Git](https://git-scm.com/) to be installed and in the `PATH`
environment variable. Executing `which git` on Linux or MacOS on the
commandline should return a non-empty path to the installation directory (ex:
`/usr/local/bin/git`). Windows users may try the [Windows Subsystem for Linux
(WSL)](https://learn.microsoft.com/en-us/windows/wsl/install) but we have not
tested it.
This template has been tested with git version ``2.41.0``. If you get an error
mentioning that ``--allow-unrelated-histories``, your git version is too old.
## Installation ## Installation
......
...@@ -52,7 +52,7 @@ while true; do ...@@ -52,7 +52,7 @@ while true; do
git show-ref | grep "ledgers/$LDGID" | \ git show-ref | grep "ledgers/$LDGID" | \
awk '{ print $2 }' | \ awk '{ print $2 }' | \
git log --stdin $OPTN --graph --pretty=oneline --decorate-refs='refs/heads/*' --decorate-refs='refs/delivered/*' --format="%C(yellow)%h%Creset %Cgreen(%an)%Creset %s %Cred %d %Creset" --graph git log --stdin $OPTN --graph --pretty=oneline --decorate-refs='refs/heads/*' --decorate-refs='refs/delivered/*' --decorate-refs='refs/remotes/*' --format="%C(yellow)%h%Creset %Cgreen(%an)%Creset %s %Cred %d %Creset" --graph
if [ $DELAY -eq 0 ]; then if [ $DELAY -eq 0 ]; then
exit 0 exit 0
......
#!/usr/bin/env bash
SCRIPTDIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
if ! $SCRIPTDIR/repo-valid '.'; then
exit 1
fi
SENDER=$(cat .git/git-crdt-ledger-writer)
SHORTID=$1
if ! LDGID=$(git show -s $SHORTID --format='%H' 2>/dev/null); then
echo "Invalid ledger identifier '$SHORTID', no commit found" >&2
exit 1
fi
if [ $(git show -s $LDGID --format='%cn' 2>/dev/null) != 'ledger-create' ] ; then
echo "Invalid ledger identifier '$SHORTID', not a 'ledger-create' operation" >&2
exit 1
fi
FRONTIER="refs/heads/ledgers/$LDGID/$SENDER"
TREE=$(git show -s $FRONTIER --format="%T")
PING=$(echo "ledger-ping" | \
GIT_COMMITTER_NAME="$LDGID" \
GIT_COMMITTER_EMAIL="" \
GIT_AUTHOR_NAME="$SENDER" \
GIT_AUTHOR_EMAIL="" \
git commit-tree $TREE -p $FRONTIER )
echo $PING
git update-ref "$FRONTIER" $PING
...@@ -13,7 +13,7 @@ if ! UPDATE=$(git show -s $UPDATE_ --format='%H' 2>/dev/null); then ...@@ -13,7 +13,7 @@ if ! UPDATE=$(git show -s $UPDATE_ --format='%H' 2>/dev/null); then
exit 1 exit 1
fi fi
LDGOP=$(git show -s $UPDATE --format='%s' 2>/dev/null | grep -e "^ledger-") LDGOP=$(git show -s $UPDATE --format='%s' 2>/dev/null | grep -e "^ledger-" | awk '{ print $1 }' )
if [ -z $LDGOP ] ; then if [ -z $LDGOP ] ; then
echo "Invalid update '$UPDATE_', '$LDGOP' is not a ledger operation" >&2 echo "Invalid update '$UPDATE_', '$LDGOP' is not a ledger operation" >&2
...@@ -121,7 +121,8 @@ elif [ "$LDGOP" == "ledger-ready" ] ; then ...@@ -121,7 +121,8 @@ elif [ "$LDGOP" == "ledger-ready" ] ; then
# Update frontier # Update frontier
git update-ref "$FRONTIER" "$LDGCOUNTER" git update-ref "$FRONTIER" "$LDGCOUNTER"
fi fi
elif [ "$LDGOP" == "ledger-counter" ] ; then elif [ "$LDGOP" == "ledger-counter" ] ||
[ "$LDGOP" == "ledger-ping-done" ] ; then
if [ "$AUTHOR" != "$WRITER" ] ; then if [ "$AUTHOR" != "$WRITER" ] ; then
# Merge with our current counters list # Merge with our current counters list
FRONTIER="refs/heads/ledgers/$LDGID/$WRITER" FRONTIER="refs/heads/ledgers/$LDGID/$WRITER"
...@@ -139,6 +140,40 @@ elif [ "$LDGOP" == "ledger-counter" ] ; then ...@@ -139,6 +140,40 @@ elif [ "$LDGOP" == "ledger-counter" ] ; then
# Update frontier # Update frontier
git update-ref "$FRONTIER" "$MERGE" git update-ref "$FRONTIER" "$MERGE"
fi fi
elif [ "$LDGOP" == "ledger-ping" ] ; then
if [ "$AUTHOR" != "$WRITER" ] ; then
FRONTIER="refs/heads/ledgers/$LDGID/$WRITER"
TREE=$(git show -s "$FRONTIER" --format="%T")
PONG=$(echo "ledger-pong" | \
GIT_COMMITTER_NAME="$LDGID" \
GIT_COMMITTER_EMAIL="" \
GIT_AUTHOR_NAME="$WRITER" \
GIT_AUTHOR_EMAIL="" \
git commit-tree $TREE -p $FRONTIER -p $UPDATE \
)
# Update frontier
git update-ref "$FRONTIER" "$PONG"
fi
elif [ "$LDGOP" == "ledger-pong" ] ; then
if [ "$AUTHOR" != "$WRITER" ] ; then
PING=$(git show -s "$UPDATE^2" --format='%H')
FRONTIER="refs/heads/ledgers/$LDGID/$WRITER"
TREE=$(git show -s "$FRONTIER" --format='%T')
PINGDONE=$(echo "ledger-ping-done $PING" | \
GIT_COMMITTER_NAME="$LDGID" \
GIT_COMMITTER_EMAIL="" \
GIT_AUTHOR_NAME="$WRITER" \
GIT_AUTHOR_EMAIL="" \
git commit-tree $TREE -p $FRONTIER -p $UPDATE \
)
echo $PINGDONE
# Update frontier
git update-ref "$FRONTIER" "$PINGDONE"
fi
elif [ "$LDGOP" == "ledger-merge" ] ; then elif [ "$LDGOP" == "ledger-merge" ] ; then
# No operation # No operation
echo "" > /dev/null echo "" > /dev/null
......