]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add auxiliary git bash scripts
authorMatthias Maier <tamiko@43-1.org>
Wed, 24 May 2017 05:34:41 +0000 (07:34 +0200)
committerDenis Davydov <davydden@gmail.com>
Wed, 24 May 2017 05:49:27 +0000 (07:49 +0200)
cmake/scripts/get_closest_tag.sh [new file with mode: 0755]
cmake/scripts/get_latest_tag.sh [new file with mode: 0755]

diff --git a/cmake/scripts/get_closest_tag.sh b/cmake/scripts/get_closest_tag.sh
new file mode 100755 (executable)
index 0000000..5166c94
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/sh
+#
+# Find the TAG that
+#   - has a common ancestry with current HEAD
+#   - with shortest (positive) distance of the common ancestor to HEAD
+#
+
+head="$(git rev-parse HEAD)"
+
+tags="$(git tag --sort=-creatordate)"
+
+min_distance=0
+min_tag=""
+for tag in $tags; do
+  tag_commit="$(git rev-parse $tag^{commit})"
+
+  if [ "$tag_commit" = "$head" ]; then
+    echo "$tag"
+    exit 0;
+  fi
+
+  ancestor="$(git merge-base HEAD $tag)"
+
+  if [ "$ancestor" != "$head" ]; then
+    distance="$(git rev-list HEAD ^${ancestor} --count)"
+
+    if [ "$min_distance" = "0" ]; then
+      min_distance="$distance"
+      min_tag="$tag"
+    fi
+
+    if [ "$distance" -lt "$min_distance" ]; then
+      min_distance="$distance"
+      min_tag="$tag"
+    fi
+  fi
+
+done
+
+if [ "$min_distance" != "0" ]; then
+  echo $min_tag
+  exit 0
+else
+  exit 1
+fi
diff --git a/cmake/scripts/get_latest_tag.sh b/cmake/scripts/get_latest_tag.sh
new file mode 100755 (executable)
index 0000000..c29ace9
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/sh
+#
+# Find the latest TAG that has a common ancestry (of positive distance) with
+# current HEAD
+#
+
+head="$(git rev-parse HEAD)"
+
+tags="$(git tag --sort=-creatordate)"
+
+for tag in $tags; do
+  tag_commit="$(git rev-parse $tag^{commit})"
+
+  if [ "$tag_commit" = "$head" ]; then
+    echo "$tag"
+    exit 0;
+  fi
+
+  ancestor="$(git merge-base HEAD $tag)"
+
+  if [ "$ancestor" != "$head" ]; then
+    echo "$tag"
+    exit 0;
+  fi
+done
+
+exit 1

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.