We are almost there...

Signed-off-by: Junio C Hamano <gits...@pobox.com>
---
 Documentation/git-name-rev.txt | 14 ++++++++--
 t/t6039-name-rev.sh            | 62 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 73 insertions(+), 3 deletions(-)
 create mode 100755 t/t6039-name-rev.sh

diff --git a/Documentation/git-name-rev.txt b/Documentation/git-name-rev.txt
index ad1d146..f40027a 100644
--- a/Documentation/git-name-rev.txt
+++ b/Documentation/git-name-rev.txt
@@ -9,13 +9,13 @@ git-name-rev - Find symbolic names for given revs
 SYNOPSIS
 --------
 [verse]
-'git name-rev' [--tags] [--refs=<pattern>]
+'git name-rev' [--tags] [--refs=<pattern>] [--weight]
               ( --all | --stdin | <committish>... )
 
 DESCRIPTION
 -----------
-Finds symbolic names suitable for human digestion for revisions given in any
-format parsable by 'git rev-parse'.
+Finds symbolic names suitable for human digestion for revisions
+given in any format parsable by 'git rev-parse'.
 
 
 OPTIONS
@@ -47,6 +47,14 @@ OPTIONS
 --always::
        Show uniquely abbreviated commit object as fallback.
 
+--weight::
+       Name commits based on the oldest ref that contains it.  This
+       is way more expensive than the default behaviour of the
+       command, in which commits are named based on the ref that
+       is topologically the closest, but gives more intuitive
+       answer to the question: what is the oldest tag that contains
+       this commit?
+
 EXAMPLE
 -------
 
diff --git a/t/t6039-name-rev.sh b/t/t6039-name-rev.sh
new file mode 100755
index 0000000..315ce14
--- /dev/null
+++ b/t/t6039-name-rev.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+
+test_description='name-rev'
+. ./test-lib.sh
+
+# Prepare a history with this shape
+#
+# ---0--1--2--3--4--Y--5---7---Z
+#     \   /               /
+#      \ /               /
+#       X---------------6
+#
+
+test_expect_success setup '
+       test_tick &&
+       git commit --allow-empty -m 0 &&
+       git branch side &&
+       git commit --allow-empty -m 1 &&
+       git checkout side &&
+       git commit --allow-empty -m X &&
+       git branch X &&
+       git commit --allow-empty -m 6 &&
+       git checkout master &&
+       git merge -m 2 X &&
+       git commit --allow-empty -m 3 &&
+       git commit --allow-empty -m 4 &&
+       git commit --allow-empty -m Y &&
+       git tag Y &&
+       git commit --allow-empty -m 5 &&
+       git merge -m 7 side &&
+       git commit --allow-empty -m Z &&
+       git tag Z
+'
+
+test_expect_success 'name-rev (plain)' '
+       # We expect "X tags/Z~1^2~1" but it could
+       # be written as "X tags/Z^^2^"; the only two
+       # important things that matter are that it
+       # is named after Z (not Y), and it correctly
+       # names X.
+       git name-rev --tags X >actual &&
+       read X T <actual &&
+       test "z$X" = zX &&
+       expr "$T" : 'tags/Z[~^]' &&
+       H1=$(git rev-parse --verify "$T") &&
+       H2=$(git rev-parse --verify X) &&
+       test "z$H1" = "z$H2"
+'
+
+test_expect_success 'name-rev --weight' '
+       # Likewise; "X tags/Y~3^2" but we only care
+       # that it is based on Y.
+       git name-rev --weight --tags X >actual &&
+       read X T <actual &&
+       test "z$X" = zX &&
+       expr "$T" : 'tags/Y[~^]' &&
+       H1=$(git rev-parse --verify "$T") &&
+       H2=$(git rev-parse --verify X) &&
+       test "z$H1" = "z$H2"
+'
+
+test_done
-- 
1.7.12.286.g9df01f7

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to