* [PATCH v3 5/8] test-lib: set $TRASH_DIRECTORY earlier
From: SZEDER Gábor @ 2018-12-30 19:16 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Jeff King, git, SZEDER Gábor
In-Reply-To: <20181230191629.3232-1-szeder.dev@gmail.com>
A later patch in this series will need to know the path to the trash
directory early in 'test-lib.sh', but $TRASH_DIRECTORY is set much
later. Furthermore, the path to the trash directory depends on the
'--root=<path>' option, which, too, is parsed too late.
Move parsing '--root=...' to the early option parsing loop, and set
$TRASH_DIRECTORY where the other test-specific path variables are set.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
t/test-lib.sh | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 41457d1dcf..2b88ba2de1 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -186,6 +186,12 @@ fi
TEST_NAME="$(basename "$0" .sh)"
TEST_RESULTS_DIR="$TEST_OUTPUT_DIRECTORY/test-results"
TEST_RESULTS_BASE="$TEST_RESULTS_DIR/$TEST_NAME"
+TRASH_DIRECTORY="trash directory.$TEST_NAME"
+test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
+case "$TRASH_DIRECTORY" in
+/*) ;; # absolute path is good
+ *) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
+esac
# if --tee was passed, write the output not only to the terminal, but
# additionally to the file test-results/$BASENAME.out, too.
@@ -1046,12 +1052,6 @@ then
fi
# Test repository
-TRASH_DIRECTORY="trash directory.$TEST_NAME"
-test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
-case "$TRASH_DIRECTORY" in
-/*) ;; # absolute path is good
- *) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
-esac
rm -fr "$TRASH_DIRECTORY" || {
GIT_EXIT_OK=t
echo >&5 "FATAL: Cannot prepare test area"
--
2.20.1.151.gec613c4b75
^ permalink raw reply related
* [PATCH v3 4/8] test-lib: consolidate naming of test-results paths
From: SZEDER Gábor @ 2018-12-30 19:16 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Jeff King, git, SZEDER Gábor
In-Reply-To: <20181230191629.3232-1-szeder.dev@gmail.com>
There are two places where we strip off any leading path components
and the '.sh' suffix from the test script's pathname, and there are
four places where we construct the name of the 't/test-results'
directory or the name of various test-specific files in there. The
last patch in this series will add even more.
Factor these out into helper variables to avoid repeating ourselves.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
t/test-lib.sh | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/t/test-lib.sh b/t/test-lib.sh
index fcc04afdff..41457d1dcf 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -183,6 +183,10 @@ then
verbose=t
fi
+TEST_NAME="$(basename "$0" .sh)"
+TEST_RESULTS_DIR="$TEST_OUTPUT_DIRECTORY/test-results"
+TEST_RESULTS_BASE="$TEST_RESULTS_DIR/$TEST_NAME"
+
# if --tee was passed, write the output not only to the terminal, but
# additionally to the file test-results/$BASENAME.out, too.
if test "$GIT_TEST_TEE_STARTED" = "done"
@@ -190,12 +194,11 @@ then
: # do not redirect again
elif test -n "$tee"
then
- mkdir -p "$TEST_OUTPUT_DIRECTORY/test-results"
- BASE="$TEST_OUTPUT_DIRECTORY/test-results/$(basename "$0" .sh)"
+ mkdir -p "$TEST_RESULTS_DIR"
# Make this filename available to the sub-process in case it is using
# --verbose-log.
- GIT_TEST_TEE_OUTPUT_FILE=$BASE.out
+ GIT_TEST_TEE_OUTPUT_FILE=$TEST_RESULTS_BASE.out
export GIT_TEST_TEE_OUTPUT_FILE
# Truncate before calling "tee -a" to get rid of the results
@@ -203,8 +206,8 @@ then
>"$GIT_TEST_TEE_OUTPUT_FILE"
(GIT_TEST_TEE_STARTED=done ${TEST_SHELL_PATH} "$0" "$@" 2>&1;
- echo $? >"$BASE.exit") | tee -a "$GIT_TEST_TEE_OUTPUT_FILE"
- test "$(cat "$BASE.exit")" = 0
+ echo $? >"$TEST_RESULTS_BASE.exit") | tee -a "$GIT_TEST_TEE_OUTPUT_FILE"
+ test "$(cat "$TEST_RESULTS_BASE.exit")" = 0
exit
fi
@@ -835,12 +838,9 @@ test_done () {
if test -z "$HARNESS_ACTIVE"
then
- test_results_dir="$TEST_OUTPUT_DIRECTORY/test-results"
- mkdir -p "$test_results_dir"
- base=${0##*/}
- test_results_path="$test_results_dir/${base%.sh}.counts"
+ mkdir -p "$TEST_RESULTS_DIR"
- cat >"$test_results_path" <<-EOF
+ cat >"$TEST_RESULTS_BASE.counts" <<-EOF
total $test_count
success $test_success
fixed $test_fixed
@@ -1046,7 +1046,7 @@ then
fi
# Test repository
-TRASH_DIRECTORY="trash directory.$(basename "$0" .sh)"
+TRASH_DIRECTORY="trash directory.$TEST_NAME"
test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
case "$TRASH_DIRECTORY" in
/*) ;; # absolute path is good
--
2.20.1.151.gec613c4b75
^ permalink raw reply related
* [PATCH v3 8/8] test-lib: add the '--stress' option to run a test repeatedly under load
From: SZEDER Gábor @ 2018-12-30 19:16 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Jeff King, git, SZEDER Gábor
In-Reply-To: <20181230191629.3232-1-szeder.dev@gmail.com>
Unfortunately, we have a few flaky tests, whose failures tend to be
hard to reproduce. We've found that the best we can do to reproduce
such a failure is to run the test script repeatedly while the machine
is under load, and wait in the hope that the load creates enough
variance in the timing of the test's commands that a failure is
evenually triggered. I have a command to do that, and I noticed that
two other contributors have rolled their own scripts to do the same,
all choosing slightly different approaches.
To help reproduce failures in flaky tests, introduce the '--stress'
option to run a test script repeatedly in multiple parallel jobs until
one of them fails, thereby using the test script itself to increase
the load on the machine.
The number of parallel jobs is determined by, in order of precedence:
the number specified as '--stress=<N>', or the value of the
GIT_TEST_STRESS_LOAD environment variable, or twice the number of
available processors (as reported by the 'getconf' utility), or 8.
Make '--stress' imply '--verbose -x --immediate' to get the most
information about rare failures; there is really no point in spending
all the extra effort to reproduce such a failure, and then not know
which command failed and why.
To prevent the several parallel invocations of the same test from
interfering with each other:
- Include the parallel job's number in the name of the trash
directory and the various output files under 't/test-results/' as
a '.stress-<Nr>' suffix.
- Add the parallel job's number to the port number specified by the
user or to the test number, so even tests involving daemons
listening on a TCP socket can be stressed.
- Redirect each parallel test run's verbose output to
't/test-results/$TEST_NAME.stress-<nr>.out', because dumping the
output of several parallel running tests to the terminal would
create a big ugly mess.
For convenience, print the output of the failed test job at the end,
and rename its trash directory to end with the '.stress-failed'
suffix, so it's easy to find in a predictable path (OTOH, all absolute
paths recorded in the trash directory become invalid; we'll see
whether this causes any issues in practice). If, in an unlikely case,
more than one jobs were to fail nearly at the same time, then print
the output of all failed jobs, and rename the trash directory of only
the last one (i.e. with the highest job number), as it is the trash
directory of the test whose output will be at the bottom of the user's
terminal.
Based on Jeff King's 'stress' script.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
t/README | 19 ++++++-
t/test-lib-functions.sh | 7 ++-
t/test-lib.sh | 109 +++++++++++++++++++++++++++++++++++++++-
3 files changed, 130 insertions(+), 5 deletions(-)
diff --git a/t/README b/t/README
index 28711cc508..11ce7675e3 100644
--- a/t/README
+++ b/t/README
@@ -186,6 +186,22 @@ appropriately before running "make".
this feature by setting the GIT_TEST_CHAIN_LINT environment
variable to "1" or "0", respectively.
+--stress::
+--stress=<N>::
+ Run the test script repeatedly in multiple parallel jobs until
+ one of them fails. Useful for reproducing rare failures in
+ flaky tests. The number of parallel jobs is, in order of
+ precedence: <N>, or the value of the GIT_TEST_STRESS_LOAD
+ environment variable, or twice the number of available
+ processors (as shown by the 'getconf' utility), or 8.
+ Implies `--verbose -x --immediate` to get the most information
+ about the failure. Note that the verbose output of each test
+ job is saved to 't/test-results/$TEST_NAME.stress-<nr>.out',
+ and only the output of the failed test job is shown on the
+ terminal. The names of the trash directories get a
+ '.stress-<nr>' suffix, and the trash directory of the failed
+ test job is renamed to end with a '.stress-failed' suffix.
+
You can also set the GIT_TEST_INSTALLED environment variable to
the bindir of an existing git installation to test that installation.
You still need to have built this git sandbox, from which various
@@ -425,7 +441,8 @@ This test harness library does the following things:
- Creates an empty test directory with an empty .git/objects database
and chdir(2) into it. This directory is 't/trash
directory.$test_name_without_dotsh', with t/ subject to change by
- the --root option documented above.
+ the --root option documented above, and a '.stress-<N>' suffix
+ appended by the --stress option.
- Defines standard test helper functions for your scripts to
use. These functions are designed to make all scripts behave
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 4459bdda13..92cf8f812c 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -1288,8 +1288,6 @@ test_set_port () {
# root-only port, use a larger one instead.
port=$(($port + 10000))
fi
-
- eval $var=$port
;;
*[^0-9]*|0*)
error >&7 "invalid port number: $port"
@@ -1298,4 +1296,9 @@ test_set_port () {
# The user has specified the port.
;;
esac
+
+ # Make sure that parallel '--stress' test jobs get different
+ # ports.
+ port=$(($port + ${GIT_TEST_STRESS_JOB_NR:-0}))
+ eval $var=$port
}
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 7d77a26d44..16f74bd524 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -139,6 +139,19 @@ do
verbose_log=t
tee=t
;;
+ --stress)
+ stress=t ;;
+ --stress=*)
+ stress=${opt#--*=}
+ case "$stress" in
+ *[^0-9]*|0*|"")
+ echo "error: --stress=<N> requires the number of jobs to run" >&2
+ exit 1
+ ;;
+ *) # Good.
+ ;;
+ esac
+ ;;
*)
echo "error: unknown test option '$opt'" >&2; exit 1 ;;
esac
@@ -160,6 +173,13 @@ then
test -z "$verbose_log" && verbose=t
fi
+if test -n "$stress"
+then
+ verbose=t
+ trace=t
+ immediate=t
+fi
+
if test -n "$trace" && test -n "$test_untraceable"
then
# '-x' tracing requested, but this test script can't be reliably
@@ -183,16 +203,101 @@ then
verbose=t
fi
+TEST_STRESS_JOB_SFX="${GIT_TEST_STRESS_JOB_NR:+.stress-$GIT_TEST_STRESS_JOB_NR}"
TEST_NAME="$(basename "$0" .sh)"
TEST_RESULTS_DIR="$TEST_OUTPUT_DIRECTORY/test-results"
-TEST_RESULTS_BASE="$TEST_RESULTS_DIR/$TEST_NAME"
-TRASH_DIRECTORY="trash directory.$TEST_NAME"
+TEST_RESULTS_BASE="$TEST_RESULTS_DIR/$TEST_NAME$TEST_STRESS_JOB_SFX"
+TRASH_DIRECTORY="trash directory.$TEST_NAME$TEST_STRESS_JOB_SFX"
test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
case "$TRASH_DIRECTORY" in
/*) ;; # absolute path is good
*) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
esac
+# If --stress was passed, run this test repeatedly in several parallel loops.
+if test "$GIT_TEST_STRESS_STARTED" = "done"
+then
+ : # Don't stress test again.
+elif test -n "$stress"
+then
+ if test "$stress" != t
+ then
+ job_count=$stress
+ elif test -n "$GIT_TEST_STRESS_LOAD"
+ then
+ job_count="$GIT_TEST_STRESS_LOAD"
+ elif job_count=$(getconf _NPROCESSORS_ONLN 2>/dev/null) &&
+ test -n "$job_count"
+ then
+ job_count=$((2 * $job_count))
+ else
+ job_count=8
+ fi
+
+ mkdir -p "$TEST_RESULTS_DIR"
+ stressfail="$TEST_RESULTS_BASE.stress-failed"
+ rm -f "$stressfail"
+
+ stress_exit=0
+ trap '
+ kill $job_pids 2>/dev/null
+ wait
+ stress_exit=1
+ ' TERM INT HUP
+
+ job_pids=
+ job_nr=0
+ while test $job_nr -lt "$job_count"
+ do
+ (
+ GIT_TEST_STRESS_STARTED=done
+ GIT_TEST_STRESS_JOB_NR=$job_nr
+ export GIT_TEST_STRESS_STARTED GIT_TEST_STRESS_JOB_NR
+
+ trap '
+ kill $test_pid 2>/dev/null
+ wait
+ exit 1
+ ' TERM INT
+
+ cnt=0
+ while ! test -e "$stressfail"
+ do
+ $TEST_SHELL_PATH "$0" "$@" >"$TEST_RESULTS_BASE.stress-$job_nr.out" 2>&1 &
+ test_pid=$!
+
+ if wait $test_pid
+ then
+ printf "OK %2d.%d\n" $GIT_TEST_STRESS_JOB_NR $cnt
+ else
+ echo $GIT_TEST_STRESS_JOB_NR >>"$stressfail"
+ printf "FAIL %2d.%d\n" $GIT_TEST_STRESS_JOB_NR $cnt
+ fi
+ cnt=$(($cnt + 1))
+ done
+ ) &
+ job_pids="$job_pids $!"
+ job_nr=$(($job_nr + 1))
+ done
+
+ wait
+
+ if test -f "$stressfail"
+ then
+ echo "Log(s) of failed test run(s):"
+ for failed_job_nr in $(sort -n "$stressfail")
+ do
+ echo "Contents of '$TEST_RESULTS_BASE.stress-$failed_job_nr.out':"
+ cat "$TEST_RESULTS_BASE.stress-$failed_job_nr.out"
+ done
+ rm -rf "$TRASH_DIRECTORY.stress-failed"
+ # Move the last one.
+ mv "$TRASH_DIRECTORY.stress-$failed_job_nr" "$TRASH_DIRECTORY.stress-failed"
+ fi
+
+ exit $stress_exit
+fi
+
# if --tee was passed, write the output not only to the terminal, but
# additionally to the file test-results/$BASENAME.out, too.
if test "$GIT_TEST_TEE_STARTED" = "done"
--
2.20.1.151.gec613c4b75
^ permalink raw reply related
* Git extra hook, pre-upload
From: Xheroz 128 @ 2018-12-30 20:11 UTC (permalink / raw)
To: git
Hello,
My name is Kenneth Lee, a student at Teikyo University, Japan.
Currently, I’m doing my Final Year Project that requires a hook that executes automatically on the server side of the repository, before the objects been pulled to the client side, and after the objects have been pushed to the server side, which is "post-receive" hook. The post-receive hook work well for me, but I couldn’t find any hook to be executed immediately before an upload-operation is performed, i.e. before data is sent to the client.
Why Git doesn't have a hook that executed immediately before the data is sent to the client? Any advice on getting this hook or any similar function of the hook?
Thanks,
Kenneth Lee Zhen Kang
+8180-9828-2935
^ permalink raw reply
* Re: Git extra hook, pre-upload
From: Ævar Arnfjörð Bjarmason @ 2018-12-30 21:34 UTC (permalink / raw)
To: Xheroz 128; +Cc: git
In-Reply-To: <754B8F69-BD83-4EBB-9E86-6DF845624B1B@gmail.com>
On Sun, Dec 30 2018, Xheroz 128 wrote:
> Currently, I’m doing my Final Year Project that requires a hook that executes automatically on the server side of the repository, before the objects been pulled to the client side, and after the objects have been pushed to the server side, which is "post-receive" hook. The post-receive hook work well for me, but I couldn’t find any hook to be executed immediately before an upload-operation is performed, i.e. before data is sent to the client.
>
> Why Git doesn't have a hook that executed immediately before the data is sent to the client? Any advice on getting this hook or any similar function of the hook?
We do not have such a pre-upload hook, but could have one. There's an
old thread from 2011 detailing some potential downsides:
https://public-inbox.org/git/CAMK1S_jaEWV=F6iHKZw_6u5ncDW0bPosNx-03W9bOLOfEEEY1Q@mail.gmail.com/
FWIW I think most servers who find themselves needing such a hook use it
to e.g. log how many fetches a given repository might serve, and end up
instead wrapping git commands in some custom shell.
It's also possible to imagine a much deeper integration for such a hook,
e.g. something that would allow you to implement the functionality of
the uploadpack.* variables and more in your own code, but I don't know
if that's the sort of thing you're imagining.
^ permalink raw reply
* Re: [PATCH v3 5/8] test-lib: set $TRASH_DIRECTORY earlier
From: SZEDER Gábor @ 2018-12-30 22:44 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Jeff King, git
In-Reply-To: <20181230191629.3232-6-szeder.dev@gmail.com>
On Sun, Dec 30, 2018 at 08:16:26PM +0100, SZEDER Gábor wrote:
> A later patch in this series will need to know the path to the trash
> directory early in 'test-lib.sh', but $TRASH_DIRECTORY is set much
> later. Furthermore, the path to the trash directory depends on the
> '--root=<path>' option, which, too, is parsed too late.
>
> Move parsing '--root=...' to the early option parsing loop, and set
> $TRASH_DIRECTORY where the other test-specific path variables are set.
Sigh.
After moving the whole option parsing loop, I should have updated this
commit message as well.
Hang on for a sec...
> Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
> ---
> t/test-lib.sh | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/t/test-lib.sh b/t/test-lib.sh
> index 41457d1dcf..2b88ba2de1 100644
> --- a/t/test-lib.sh
> +++ b/t/test-lib.sh
> @@ -186,6 +186,12 @@ fi
> TEST_NAME="$(basename "$0" .sh)"
> TEST_RESULTS_DIR="$TEST_OUTPUT_DIRECTORY/test-results"
> TEST_RESULTS_BASE="$TEST_RESULTS_DIR/$TEST_NAME"
> +TRASH_DIRECTORY="trash directory.$TEST_NAME"
> +test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
> +case "$TRASH_DIRECTORY" in
> +/*) ;; # absolute path is good
> + *) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
> +esac
>
> # if --tee was passed, write the output not only to the terminal, but
> # additionally to the file test-results/$BASENAME.out, too.
> @@ -1046,12 +1052,6 @@ then
> fi
>
> # Test repository
> -TRASH_DIRECTORY="trash directory.$TEST_NAME"
> -test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
> -case "$TRASH_DIRECTORY" in
> -/*) ;; # absolute path is good
> - *) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
> -esac
> rm -fr "$TRASH_DIRECTORY" || {
> GIT_EXIT_OK=t
> echo >&5 "FATAL: Cannot prepare test area"
> --
> 2.20.1.151.gec613c4b75
>
^ permalink raw reply
* [PATCH v3.1 5/8] test-lib: set $TRASH_DIRECTORY earlier
From: SZEDER Gábor @ 2018-12-30 22:48 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Jeff King, git, SZEDER Gábor
In-Reply-To: <20181230224453.GC6120@szeder.dev>
A later patch in this series will need to know the path to the trash
directory early in 'test-lib.sh', but $TRASH_DIRECTORY is set much
later.
Set $TRASH_DIRECTORY earlier, where the other test-specific path
variables are set.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
---
Updated the commit message, the diff is the same.
t/test-lib.sh | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 41457d1dcf..2b88ba2de1 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -186,6 +186,12 @@ fi
TEST_NAME="$(basename "$0" .sh)"
TEST_RESULTS_DIR="$TEST_OUTPUT_DIRECTORY/test-results"
TEST_RESULTS_BASE="$TEST_RESULTS_DIR/$TEST_NAME"
+TRASH_DIRECTORY="trash directory.$TEST_NAME"
+test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
+case "$TRASH_DIRECTORY" in
+/*) ;; # absolute path is good
+ *) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
+esac
# if --tee was passed, write the output not only to the terminal, but
# additionally to the file test-results/$BASENAME.out, too.
@@ -1046,12 +1052,6 @@ then
fi
# Test repository
-TRASH_DIRECTORY="trash directory.$TEST_NAME"
-test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY"
-case "$TRASH_DIRECTORY" in
-/*) ;; # absolute path is good
- *) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;;
-esac
rm -fr "$TRASH_DIRECTORY" || {
GIT_EXIT_OK=t
echo >&5 "FATAL: Cannot prepare test area"
--
2.20.1.151.gec613c4b75
^ permalink raw reply related
* [PATCH 2/3] Add 'human' date format documentation
From: Stephen P. Smith @ 2018-12-31 0:31 UTC (permalink / raw)
To: git
Cc: Linus Torvalds, Junio C Hamano,
Ævar Arnfjörð Bjarmason, Stephen P . Smith
In-Reply-To: <20181231003150.8031-1-ischis2@cox.net>
Display date and time information in a format similar to how people
write dates in other contexts. If the year isn't specified then, the
reader infers the date is given is in the current year.
By not displaying the redundant information, the reader concentrates
on the information that is different. The patch reports relative dates
based on information inferred from the date on the machine running the
git command at the time the command is executed.
While the format is more useful to humans by dropping inferred
information, there is nothing that makes it actually human. If the
'relative' date format wasn't already implemented then using
'relative' would have been appropriate.
Signed-off-by: Stephen P. Smith <ischis2@cox.net>
---
Documentation/rev-list-options.txt | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index bab5f50b17..b491c3b999 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -835,6 +835,14 @@ Note that the `-local` option does not affect the seconds-since-epoch
value (which is always measured in UTC), but does switch the accompanying
timezone value.
+
+`--date=human` shows the timezone if it matches the current time-zone,
+and doesn't print the whole date if that matches (ie skip printing
+year for dates that are "this year", but also skip the whole date
+itself if it's in the last few days and we can just say what weekday
+it was).
++
+`--date=auto` defaults to human if we're using the pager.
++
`--date=unix` shows the date as a Unix epoch timestamp (seconds since
1970). As with `--raw`, this is always in UTC and therefore `-local`
has no effect.
--
2.20.1.2.gb21ebb671b
^ permalink raw reply related
* [PATCH 0/3] Add 'human' date format
From: Stephen P. Smith @ 2018-12-31 0:31 UTC (permalink / raw)
To: git; +Cc: Linus Torvalds, Junio C Hamano,
Ævar Arnfjörð Bjarmason
Added documentation and tests for the previously submitted patch. The
previous patch was rebased and the conflict in cache.h was resolved.
Range diff for Linus' original code:
1: 74e8221b52 ! 1: dd8ea66414 Add 'human' date format
@@ -26,6 +26,10 @@
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
+ Rebased lt/date-human to git version 2.20.1 and resolved a conflict.
+
+ Intentionally did not change logic or add documentation/tests to the
+ original commit so that the sign-offs would still be legitimate.
diff --git a/builtin/blame.c b/builtin/blame.c
--- a/builtin/blame.c
@@ -46,13 +50,13 @@
--- a/cache.h
+++ b/cache.h
@@
- struct date_mode {
- enum date_mode_type {
- DATE_NORMAL = 0,
-+ DATE_HUMAN,
- DATE_RELATIVE,
- DATE_SHORT,
- DATE_ISO8601,
+
+ enum date_mode_type {
+ DATE_NORMAL = 0,
++ DATE_HUMAN,
+ DATE_RELATIVE,
+ DATE_SHORT,
+ DATE_ISO8601,
diff --git a/date.c b/date.c
--- a/date.c
Linus Torvalds (1):
Add 'human' date format
Stephen P. Smith (2):
Add 'human' date format documentation
t0006-date.sh: add `human` date format tests.
Documentation/rev-list-options.txt | 8 ++
builtin/blame.c | 4 +
cache.h | 1 +
date.c | 130 ++++++++++++++++++++++++-----
t/t0006-date.sh | 24 ++++++
t/t4202-log.sh | 24 ++++++
t/t7007-show.sh | 25 ++++++
7 files changed, 196 insertions(+), 20 deletions(-)
--
2.20.1.2.gb21ebb671b
^ permalink raw reply
* [PATCH 3/3] t0006-date.sh: add `human` date format tests.
From: Stephen P. Smith @ 2018-12-31 0:31 UTC (permalink / raw)
To: git
Cc: Linus Torvalds, Junio C Hamano,
Ævar Arnfjörð Bjarmason, Stephen P . Smith
In-Reply-To: <20181231003150.8031-1-ischis2@cox.net>
The `human` date format varies based on two inputs: the date in the
reference time which is constant and the local computers date which
varies. Using hardcoded test expected output dates would require
holding the local machines date and time constant which is not
desireable.
Alternatively, letting the local date vary, which is the normal
situation, implies that the tests would be checking for formating
changes based on on a ref date relative to the local computers time.
When using `human` several fields are suppressed depending on the time
difference between the reference date and the local computer date. In
cases where the difference is less than a year, the year field is
supppressed. If the time is less than a day; the month and year is
suppressed.
Test using a regular expression to verify that fields that are
expected to be suppressed are not displayed.
Signed-off-by: Stephen P. Smith <ischis2@cox.net>
---
t/t0006-date.sh | 24 ++++++++++++++++++++++++
t/t4202-log.sh | 24 ++++++++++++++++++++++++
t/t7007-show.sh | 25 +++++++++++++++++++++++++
3 files changed, 73 insertions(+)
diff --git a/t/t0006-date.sh b/t/t0006-date.sh
index ffb2975e48..f208a80867 100755
--- a/t/t0006-date.sh
+++ b/t/t0006-date.sh
@@ -40,6 +40,16 @@ check_show () {
'
}
+check_human_date () {
+ time=$1
+ expect=$2
+ test_expect_success "check date ($format:$time)" '
+ echo "$time -> $expect" >expect &&
+ TZ=${zone:-$TZ} test-tool date show:"$format" "$time" >actual &&
+ grep "$expect" actual
+ '
+}
+
# arbitrary but sensible time for examples
TIME='1466000000 +0200'
check_show iso8601 "$TIME" '2016-06-15 16:13:20 +0200'
@@ -52,6 +62,20 @@ check_show unix "$TIME" '1466000000'
check_show iso-local "$TIME" '2016-06-15 14:13:20 +0000'
check_show raw-local "$TIME" '1466000000 +0000'
check_show unix-local "$TIME" '1466000000'
+check_show human "$TIME" 'Jun 15 2016'
+
+# Subtract some known constant time and look for expected field format
+TODAY_REGEX='5 hours ago'
+THIS_YEAR_REGEX='[A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-9]* [012][0-9]:[0-6][0-9]'
+MORE_THAN_A_YEAR_REGEX='[A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-9]* [0-9][0-9][0-9][0-9]'
+check_human_date "$(($(date +%s)-18000)) +0200" $TODAY_REGEX # 5 hours ago
+check_human_date "$(($(date +%s)-432000)) +0200" $THIS_YEAR_REGEX # 5 days ago
+check_human_date "$(($(date +%s)-1728000)) +0200" $THIS_YEAR_REGEX # 3 weeks ago
+check_human_date "$(($(date +%s)-13000000)) +0200" $THIS_YEAR_REGEX # 5 months ago
+check_human_date "$(($(date +%s)-31449600)) +0200" $THIS_YEAR_REGEX # 12 months ago
+check_human_date "$(($(date +%s)-37500000)) +0200" $MORE_THAN_A_YEAR_REGEX # 1 year, 2 months ago
+check_human_date "$(($(date +%s)-55188000)) +0200" $MORE_THAN_A_YEAR_REGEX # 1 year, 9 months ago
+check_human_date "$(($(date +%s)-630000000)) +0200" $MORE_THAN_A_YEAR_REGEX # 20 years ago
check_show 'format:%z' "$TIME" '+0200'
check_show 'format-local:%z' "$TIME" '+0000'
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index 819c24d10e..d7f3b73650 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -1707,4 +1707,28 @@ test_expect_success '--exclude-promisor-objects does not BUG-crash' '
test_must_fail git log --exclude-promisor-objects source-a
'
+check_human_date() {
+ commit_date=$1
+ expect=$2
+ test_expect_success "$commit_date" "
+ echo $expect $commit_date >dates &&
+ git add dates &&
+ git commit -m 'Expect String' --date=\"$commit_date\" dates &&
+ git log -1 --date=human | grep \"^Date:\" >actual &&
+ grep \"$expect\" actual
+"
+}
+
+TODAY_REGEX='[A-Z][a-z][a-z] [012][0-9]:[0-6][0-9] .0200'
+THIS_YEAR_REGEX='[A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-9]* [012][0-9]:[0-6][0-9]'
+MORE_THAN_A_YEAR_REGEX='[A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-9]* [0-9][0-9][0-9][0-9]'
+check_human_date "$(($(date +%s)-18000)) +0200" $TODAY_REGEX # 5 hours ago
+check_human_date "$(($(date +%s)-432000)) +0200" $THIS_YEAR_REGEX # 5 days ago
+check_human_date "$(($(date +%s)-1728000)) +0200" $THIS_YEAR_REGEX # 3 weeks ago
+check_human_date "$(($(date +%s)-13000000)) +0200" $THIS_YEAR_REGEX # 5 months ago
+check_human_date "$(($(date +%s)-31449600)) +0200" $THIS_YEAR_REGEX # 12 months ago
+check_human_date "$(($(date +%s)-37500000)) +0200" $MORE_THAN_A_YEAR_REGEX # 1 year, 2 months ago
+check_human_date "$(($(date +%s)-55188000)) +0200" $MORE_THAN_A_YEAR_REGEX # 1 year, 9 months ago
+check_human_date "$(($(date +%s)-630000000)) +0200" $MORE_THAN_A_YEAR_REGEX # 20 years ago
+
test_done
diff --git a/t/t7007-show.sh b/t/t7007-show.sh
index 42d3db6246..0a0334a8b5 100755
--- a/t/t7007-show.sh
+++ b/t/t7007-show.sh
@@ -128,4 +128,29 @@ test_expect_success 'show --graph is forbidden' '
test_must_fail git show --graph HEAD
'
+check_human_date() {
+ commit_date=$1
+ expect=$2
+ test_expect_success "$commit_date" "
+ echo $expect $commit_date >dates &&
+ git add dates &&
+ git commit -m 'Expect String' --date=\"$commit_date\" dates &&
+ git show --date=human | grep \"^Date:\" >actual &&
+ grep \"$expect\" actual
+"
+}
+
+TODAY_REGEX='[A-Z][a-z][a-z] [012][0-9]:[0-6][0-9] .0200'
+THIS_YEAR_REGEX='[A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-9]* [012][0-9]:[0-6][0-9]'
+MORE_THAN_A_YEAR_REGEX='[A-Z][a-z][a-z] [A-Z][a-z][a-z] [0-9]* [0-9][0-9][0-9][0-9]'
+check_human_date "$(($(date +%s)-18000)) +0200" $TODAY_REGEX # 5 hours ago
+check_human_date "$(($(date +%s)-432000)) +0200" $THIS_YEAR_REGEX # 5 days ago
+check_human_date "$(($(date +%s)-1728000)) +0200" $THIS_YEAR_REGEX # 3 weeks ago
+check_human_date "$(($(date +%s)-13000000)) +0200" $THIS_YEAR_REGEX # 5 months ago
+check_human_date "$(($(date +%s)-31449600)) +0200" $THIS_YEAR_REGEX # 12 months ago
+check_human_date "$(($(date +%s)-37500000)) +0200" $MORE_THAN_A_YEAR_REGEX # 1 year, 2 months ago
+check_human_date "$(($(date +%s)-55188000)) +0200" $MORE_THAN_A_YEAR_REGEX # 1 year, 9 months ago
+check_human_date "$(($(date +%s)-630000000)) +0200" $MORE_THAN_A_YEAR_REGEX # 20 years ago
+
+
test_done
--
2.20.1.2.gb21ebb671b
^ permalink raw reply related
* [PATCH 1/3] Add 'human' date format
From: Stephen P. Smith @ 2018-12-31 0:31 UTC (permalink / raw)
To: git
Cc: Linus Torvalds, Junio C Hamano,
Ævar Arnfjörð Bjarmason, Stephen P . Smith
In-Reply-To: <20181231003150.8031-1-ischis2@cox.net>
From: Linus Torvalds <torvalds@linux-foundation.org>
This adds --date=human, which skips the timezone if it matches the
current time-zone, and doesn't print the whole date if that matches (ie
skip printing year for dates that are "this year", but also skip the
whole date itself if it's in the last few days and we can just say what
weekday it was).
For really recent dates (same day), use the relative date stamp, while
for old dates (year doesn't match), don't bother with time and timezone.
Also add 'auto' date mode, which defaults to human if we're using the
pager. So you can do
git config --add log.date auto
and your "git log" commands will show the human-legible format unless
you're scripting things.
Note that this time format still shows the timezone for recent enough
events (but not so recent that they show up as relative dates). You can
combine it with the "-local" suffix to never show timezones for an even
more simplified view.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Stephen P. Smith <ischis2@cox.net>
---
builtin/blame.c | 4 ++
cache.h | 1 +
date.c | 130 ++++++++++++++++++++++++++++++++++++++++--------
3 files changed, 115 insertions(+), 20 deletions(-)
diff --git a/builtin/blame.c b/builtin/blame.c
index 6d798f9939..f684e31d82 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -925,6 +925,10 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
*/
blame_date_width = utf8_strwidth(_("4 years, 11 months ago")) + 1; /* add the null */
break;
+ case DATE_HUMAN:
+ /* If the year is shown, no time is shown */
+ blame_date_width = sizeof("Thu Oct 19 16:00");
+ break;
case DATE_NORMAL:
blame_date_width = sizeof("Thu Oct 19 16:00:04 2006 -0700");
break;
diff --git a/cache.h b/cache.h
index ca36b44ee0..c4396ebaa6 100644
--- a/cache.h
+++ b/cache.h
@@ -1439,6 +1439,7 @@ extern struct object *peel_to_type(const char *name, int namelen,
enum date_mode_type {
DATE_NORMAL = 0,
+ DATE_HUMAN,
DATE_RELATIVE,
DATE_SHORT,
DATE_ISO8601,
diff --git a/date.c b/date.c
index 9bc15df6f9..a8d50eb206 100644
--- a/date.c
+++ b/date.c
@@ -77,22 +77,16 @@ static struct tm *time_to_tm_local(timestamp_t time)
}
/*
- * What value of "tz" was in effect back then at "time" in the
- * local timezone?
+ * Fill in the localtime 'struct tm' for the supplied time,
+ * and return the local tz.
*/
-static int local_tzoffset(timestamp_t time)
+static int local_time_tzoffset(time_t t, struct tm *tm)
{
- time_t t, t_local;
- struct tm tm;
+ time_t t_local;
int offset, eastwest;
- if (date_overflows(time))
- die("Timestamp too large for this system: %"PRItime, time);
-
- t = (time_t)time;
- localtime_r(&t, &tm);
- t_local = tm_to_time_t(&tm);
-
+ localtime_r(&t, tm);
+ t_local = tm_to_time_t(tm);
if (t_local == -1)
return 0; /* error; just use +0000 */
if (t_local < t) {
@@ -107,6 +101,20 @@ static int local_tzoffset(timestamp_t time)
return offset * eastwest;
}
+/*
+ * What value of "tz" was in effect back then at "time" in the
+ * local timezone?
+ */
+static int local_tzoffset(timestamp_t time)
+{
+ struct tm tm;
+
+ if (date_overflows(time))
+ die("Timestamp too large for this system: %"PRItime, time);
+
+ return local_time_tzoffset((time_t)time, &tm);
+}
+
void show_date_relative(timestamp_t time, int tz,
const struct timeval *now,
struct strbuf *timebuf)
@@ -191,9 +199,80 @@ struct date_mode *date_mode_from_type(enum date_mode_type type)
return &mode;
}
+static void show_date_normal(struct strbuf *buf, timestamp_t time, struct tm *tm, int tz, struct tm *human_tm, int human_tz, int local)
+{
+ struct {
+ unsigned int year:1,
+ date:1,
+ wday:1,
+ time:1,
+ seconds:1,
+ tz:1;
+ } hide = { 0 };
+
+ hide.tz = local || tz == human_tz;
+ hide.year = tm->tm_year == human_tm->tm_year;
+ if (hide.year) {
+ if (tm->tm_mon == human_tm->tm_mon) {
+ if (tm->tm_mday > human_tm->tm_mday) {
+ /* Future date: think timezones */
+ } else if (tm->tm_mday == human_tm->tm_mday) {
+ hide.date = hide.wday = 1;
+ } else if (tm->tm_mday + 5 > human_tm->tm_mday) {
+ /* Leave just weekday if it was a few days ago */
+ hide.date = 1;
+ }
+ }
+ }
+
+ /* Show "today" times as just relative times */
+ if (hide.wday) {
+ struct timeval now;
+ gettimeofday(&now, NULL);
+ show_date_relative(time, tz, &now, buf);
+ return;
+ }
+
+ /*
+ * Always hide seconds for human-readable.
+ * Hide timezone if showing date.
+ * Hide weekday and time if showing year.
+ *
+ * The logic here is two-fold:
+ * (a) only show details when recent enough to matter
+ * (b) keep the maximum length "similar", and in check
+ */
+ if (human_tm->tm_year) {
+ hide.seconds = 1;
+ hide.tz |= !hide.date;
+ hide.wday = hide.time = !hide.year;
+ }
+
+ if (!hide.wday)
+ strbuf_addf(buf, "%.3s ", weekday_names[tm->tm_wday]);
+ if (!hide.date)
+ strbuf_addf(buf, "%.3s %d ", month_names[tm->tm_mon], tm->tm_mday);
+
+ /* Do we want AM/PM depending on locale? */
+ if (!hide.time) {
+ strbuf_addf(buf, "%02d:%02d", tm->tm_hour, tm->tm_min);
+ if (!hide.seconds)
+ strbuf_addf(buf, ":%02d", tm->tm_sec);
+ } else
+ strbuf_rtrim(buf);
+
+ if (!hide.year)
+ strbuf_addf(buf, " %d", tm->tm_year + 1900);
+
+ if (!hide.tz)
+ strbuf_addf(buf, " %+05d", tz);
+}
+
const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)
{
struct tm *tm;
+ struct tm human_tm = { 0 };
+ int human_tz = -1;
static struct strbuf timebuf = STRBUF_INIT;
if (mode->type == DATE_UNIX) {
@@ -202,6 +281,15 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)
return timebuf.buf;
}
+ if (mode->type == DATE_HUMAN) {
+ struct timeval now;
+
+ gettimeofday(&now, NULL);
+
+ /* Fill in the data for "current time" in human_tz and human_tm */
+ human_tz = local_time_tzoffset(now.tv_sec, &human_tm);
+ }
+
if (mode->local)
tz = local_tzoffset(time);
@@ -258,14 +346,7 @@ const char *show_date(timestamp_t time, int tz, const struct date_mode *mode)
strbuf_addftime(&timebuf, mode->strftime_fmt, tm, tz,
!mode->local);
else
- strbuf_addf(&timebuf, "%.3s %.3s %d %02d:%02d:%02d %d%c%+05d",
- weekday_names[tm->tm_wday],
- month_names[tm->tm_mon],
- tm->tm_mday,
- tm->tm_hour, tm->tm_min, tm->tm_sec,
- tm->tm_year + 1900,
- mode->local ? 0 : ' ',
- tz);
+ show_date_normal(&timebuf, time, tm, tz, &human_tm, human_tz, mode->local);
return timebuf.buf;
}
@@ -802,6 +883,11 @@ int parse_date(const char *date, struct strbuf *result)
return 0;
}
+static int auto_date_style(void)
+{
+ return (isatty(1) || pager_in_use()) ? DATE_HUMAN : DATE_NORMAL;
+}
+
static enum date_mode_type parse_date_type(const char *format, const char **end)
{
if (skip_prefix(format, "relative", end))
@@ -819,6 +905,10 @@ static enum date_mode_type parse_date_type(const char *format, const char **end)
return DATE_SHORT;
if (skip_prefix(format, "default", end))
return DATE_NORMAL;
+ if (skip_prefix(format, "human", end))
+ return DATE_HUMAN;
+ if (skip_prefix(format, "auto", end))
+ return auto_date_style();
if (skip_prefix(format, "raw", end))
return DATE_RAW;
if (skip_prefix(format, "unix", end))
--
2.20.1.2.gb21ebb671b
^ permalink raw reply related
* Re: [PATCH] log: add %S option (like --source) to log --format
From: Issac Trotts @ 2018-12-31 4:35 UTC (permalink / raw)
To: Derrick Stolee; +Cc: git, Noemi Mercado, Issac Trotts
In-Reply-To: <5dfd92d1-2e87-3006-1630-a33794b6066b@gmail.com>
Hi Derrick, thanks for your feedback.
I'll send out a new patch with the changes.
On Fri, Dec 28, 2018 at 12:20 AM Derrick Stolee <stolee@gmail.com> wrote:
>
> On 12/19/2018 3:33 AM, issac.trotts@gmail.com wrote:
> > From: Issac Trotts <issac.trotts@gmail.com>
> >
> > Make it possible to write for example
> >
> > git log --format="%H,%S"
> >
> > where the %S at the end is a new placeholder that prints out the ref
> > (tag/branch) for each commit.
> >
> > Using %d might seem like an alternative but it only shows the ref for the last
> > commit in the branch.
> >
> > Signed-off-by: Issac Trotts <issactrotts@google.com>
> >
> > ---
> >
> > This change is based on a question from Stack Overflow:
> > https://stackoverflow.com/questions/12712775/git-get-source-information-in-format
> > ---
> > Documentation/pretty-formats.txt | 2 ++
> > builtin/log.c | 2 +-
> > log-tree.c | 1 +
> > pretty.c | 15 ++++++++++
> > pretty.h | 1 +
> > t/t4205-log-pretty-formats.sh | 50 ++++++++++++++++++++++++++++++++
> > 6 files changed, 70 insertions(+), 1 deletion(-)
> >
> > diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
> > index 417b638cd..de6953108 100644
> > --- a/Documentation/pretty-formats.txt
> > +++ b/Documentation/pretty-formats.txt
> > @@ -134,6 +134,8 @@ The placeholders are:
> > - '%cI': committer date, strict ISO 8601 format
> > - '%d': ref names, like the --decorate option of linkgit:git-log[1]
> > - '%D': ref names without the " (", ")" wrapping.
> > +- '%S': ref name given on the command line by which the commit was reached
> > + (like `git log --source`), only works with `git log`
>
> This "only works with `git log`" made me think about what would happen
> with `git rev-list --pretty=format:"%h %S"` and the answer (on my
> machine) was a segfault.
Good find. Checking for c->pretty_ctx->rev == NULL prevents the seg fault.
> > - '%e': encoding
> > - '%s': subject
> > - '%f': sanitized subject line, suitable for a filename
> > diff --git a/builtin/log.c b/builtin/log.c
> > index e8e51068b..be3025657 100644
> > --- a/builtin/log.c
> > +++ b/builtin/log.c
> > @@ -203,7 +203,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
> > rev->diffopt.filter || rev->diffopt.flags.follow_renames)
> > rev->always_show_header = 0;
> >
> > - if (source) {
> > + if (source || (rev->pretty_given && (rev->commit_format == CMIT_FMT_USERFORMAT) && w.source)) {
> > init_revision_sources(&revision_sources);
> > rev->sources = &revision_sources;
> > }
>
> Likely, you'll want to duplicate this initialization in the revision
> machinery. Keep this one in builtin/log.c as it was before, but add
> something like this initialization to setup_revisions(). Add a test for
> rev-list.
Okay, I added a test to check that rev-list leaves %S alone and
implicitly that it doesn't segfault.
I'd like to limit the scope of this change to what's already here,
with the check preventing the segfault, if that's okay. Could support
for %S in rev-list be in a later patch?
>
> [snip]
>
> > @@ -1194,6 +1195,17 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
> > load_ref_decorations(NULL, DECORATE_SHORT_REFS);
> > format_decorations_extended(sb, commit, c->auto_color, "", ", ", "");
> > return 1;
> > + case 'S': /* tag/branch like --source */
> > + if (c->pretty_ctx->rev->sources == NULL) {
> Use "if (!c->pretty_ctx->rev->sources".
> > + return 0;
> > + }
> > + slot = revision_sources_at(c->pretty_ctx->rev->sources, commit);
> > + if (slot && *slot) {
> I'm not sure this check for 'slot' being non-null is necessary, as we
> would already get a failure in the commit-slab code (for
> revision_sources_at()) if the slab is not initialized.
> > + strbuf_addstr(sb, *slot);
> > + return 1;
> > + } else {
> > + die(_("failed to get info for %%S"));
>
> Here, you die() when you fail to get a slot but above you return 0 when
> the sources are not initialized.
>
> I don't see another use of die() in this method. Is that the right way
> to handle failure here? (I'm legitimately asking because I have
> over-used 'die()' in the past and am still unclear on when it is
> appropriate.)
Fixed.
>
> > '
> >
> > +test_expect_success 'set up %S tests' '
> > + git checkout --orphan source-a &&
> > + test_commit one &&
> > + test_commit two &&
> > + git checkout -b source-b HEAD^ &&
> > + test_commit three
> > +'
> > +
> > +test_expect_success 'log --format=%S paints branch names' '
> > + cat >expect <<-\EOF &&
> > + source-b
> > + source-a
> > + source-b
> > + EOF
> > + git log --format=%S source-a source-b >actual &&
> > + test_cmp expect actual
> > +'
> > +
> > +test_expect_success 'log --format=%S paints tag names' '
> > + git tag -m tagged source-tag &&
> > + cat >expect <<-\EOF &&
> > + source-tag
> > + source-a
> > + source-tag
> > + EOF
> > + git log --format=%S source-tag source-a >actual &&
> > + test_cmp expect actual
> > +'
> > +
> > +test_expect_success 'log --format=%S paints symmetric ranges' '
> > + cat >expect <<-\EOF &&
> > + source-b
> > + source-a
> > + EOF
> > + git log --format=%S source-a...source-b >actual &&
> > + test_cmp expect actual
> > +'
> > +
> > +test_expect_success '%S in git log --format works with other placeholders (part 1)' '
> > + git log --format="source-b %h" source-b >expect &&
> > + git log --format="%S %h" source-b >actual &&
> > + test_cmp expect actual
> > +'
> > +
> > +test_expect_success '%S in git log --format works with other placeholders (part 2)' '
> > + git log --format="%h source-b" source-b >expect &&
> > + git log --format="%h %S" source-b >actual &&
> > + test_cmp expect actual
> > +'
> > +
> > test_done
>
> Please also add a simple test to t6006-rev-list-format.sh.
Done.
>
> Thanks,
>
> -Stolee
>
^ permalink raw reply
* [PATCH] log: add %S option (like --source) to log --format
From: issac.trotts @ 2018-12-31 4:53 UTC (permalink / raw)
To: git, noemi; +Cc: Issac Trotts, Issac Trotts
From: Issac Trotts <issac.trotts@gmail.com>
Make it possible to write for example
git log --format="%H,%S"
where the %S at the end is a new placeholder that prints out the ref
(tag/branch) for each commit.
Using %d might seem like an alternative but it only shows the ref for the last
commit in the branch.
Signed-off-by: Issac Trotts <issactrotts@google.com>
---
This change is based on a question from Stack Overflow:
https://stackoverflow.com/questions/12712775/git-get-source-information-in-format
---
Documentation/pretty-formats.txt | 2 ++
builtin/log.c | 2 +-
log-tree.c | 1 +
pretty.c | 16 ++++++++++
pretty.h | 1 +
t/t4205-log-pretty-formats.sh | 50 ++++++++++++++++++++++++++++++++
t/t6006-rev-list-format.sh | 4 +++
7 files changed, 75 insertions(+), 1 deletion(-)
diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index 417b638cd..de6953108 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -134,6 +134,8 @@ The placeholders are:
- '%cI': committer date, strict ISO 8601 format
- '%d': ref names, like the --decorate option of linkgit:git-log[1]
- '%D': ref names without the " (", ")" wrapping.
+- '%S': ref name given on the command line by which the commit was reached
+ (like `git log --source`), only works with `git log`
- '%e': encoding
- '%s': subject
- '%f': sanitized subject line, suitable for a filename
diff --git a/builtin/log.c b/builtin/log.c
index e8e51068b..be3025657 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -203,7 +203,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
rev->diffopt.filter || rev->diffopt.flags.follow_renames)
rev->always_show_header = 0;
- if (source) {
+ if (source || (rev->pretty_given && (rev->commit_format == CMIT_FMT_USERFORMAT) && w.source)) {
init_revision_sources(&revision_sources);
rev->sources = &revision_sources;
}
diff --git a/log-tree.c b/log-tree.c
index 10680c139..3cb14256e 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -700,6 +700,7 @@ void show_log(struct rev_info *opt)
ctx.color = opt->diffopt.use_color;
ctx.expand_tabs_in_log = opt->expand_tabs_in_log;
ctx.output_encoding = get_log_output_encoding();
+ ctx.rev = opt;
if (opt->from_ident.mail_begin && opt->from_ident.name_begin)
ctx.from_ident = &opt->from_ident;
if (opt->graph)
diff --git a/pretty.c b/pretty.c
index b83a3ecd2..d1981871e 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1084,6 +1084,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
struct commit_list *p;
const char *arg;
int ch;
+ char **slot;
/* these are independent of the commit */
switch (placeholder[0]) {
@@ -1194,6 +1195,18 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
load_ref_decorations(NULL, DECORATE_SHORT_REFS);
format_decorations_extended(sb, commit, c->auto_color, "", ", ", "");
return 1;
+ case 'S': /* tag/branch like --source */
+ if (c->pretty_ctx->rev == NULL || c->pretty_ctx->rev->sources == NULL) {
+ return 0;
+ }
+ slot = revision_sources_at(c->pretty_ctx->rev->sources, commit);
+ if (!(slot && *slot)) {
+ return 0;
+ }
+ if (slot && *slot) {
+ strbuf_addstr(sb, *slot);
+ return 1;
+ }
case 'g': /* reflog info */
switch(placeholder[1]) {
case 'd': /* reflog selector */
@@ -1498,6 +1511,9 @@ static size_t userformat_want_item(struct strbuf *sb, const char *placeholder,
case 'N':
w->notes = 1;
break;
+ case 'S':
+ w->source = 1;
+ break;
}
return 0;
}
diff --git a/pretty.h b/pretty.h
index 7359d318a..87ca5dfcb 100644
--- a/pretty.h
+++ b/pretty.h
@@ -60,6 +60,7 @@ static inline int cmit_fmt_is_mail(enum cmit_fmt fmt)
struct userformat_want {
unsigned notes:1;
+ unsigned source:1;
};
/* Set the flag "w->notes" if there is placeholder %N in "fmt". */
diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
index 978a8a66f..7df8c3d4e 100755
--- a/t/t4205-log-pretty-formats.sh
+++ b/t/t4205-log-pretty-formats.sh
@@ -621,4 +621,54 @@ test_expect_success 'trailer parsing not fooled by --- line' '
test_cmp expect actual
'
+test_expect_success 'set up %S tests' '
+ git checkout --orphan source-a &&
+ test_commit one &&
+ test_commit two &&
+ git checkout -b source-b HEAD^ &&
+ test_commit three
+'
+
+test_expect_success 'log --format=%S paints branch names' '
+ cat >expect <<-\EOF &&
+ source-b
+ source-a
+ source-b
+ EOF
+ git log --format=%S source-a source-b >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'log --format=%S paints tag names' '
+ git tag -m tagged source-tag &&
+ cat >expect <<-\EOF &&
+ source-tag
+ source-a
+ source-tag
+ EOF
+ git log --format=%S source-tag source-a >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'log --format=%S paints symmetric ranges' '
+ cat >expect <<-\EOF &&
+ source-b
+ source-a
+ EOF
+ git log --format=%S source-a...source-b >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success '%S in git log --format works with other placeholders (part 1)' '
+ git log --format="source-b %h" source-b >expect &&
+ git log --format="%S %h" source-b >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success '%S in git log --format works with other placeholders (part 2)' '
+ git log --format="%h source-b" source-b >expect &&
+ git log --format="%h %S" source-b >actual &&
+ test_cmp expect actual
+'
+
test_done
diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh
index ec42c2f77..da113d975 100755
--- a/t/t6006-rev-list-format.sh
+++ b/t/t6006-rev-list-format.sh
@@ -185,6 +185,10 @@ test_expect_success 'basic colors' '
test_cmp expect actual
'
+test_expect_success '%S is not a placeholder for rev-list yet' '
+ git rev-list --format="%S" -1 master | grep "%S"
+'
+
test_expect_success 'advanced colors' '
cat >expect <<-EOF &&
commit $head2
--
2.19.1
^ permalink raw reply related
* Regression in git-subtree.sh, introduced in 2.20.1, after 315a84f9aa0e2e629b0680068646b0032518ebed
From: Marc Balmer @ 2018-12-31 10:28 UTC (permalink / raw)
To: git; +Cc: roger.strain, gitster
Hi
One of the last three commits in git-subtree.sh introduced a regression leading to a segfault.
Here is the error message when I try to split out my i18n files:
$ git subtree split --prefix=i18n
cache for e39a2a0c6431773a5d831eb3cb7f1cd40d0da623 already exists!
(Lots of output omitted)
436/627 (1819) [1455] <- Stays at 436/ while the numbers in () and [] increase, then segfaults:
/usr/libexec/git-core/git-subtree: line 751: 54693 Done eval "$grl"
54694 Segmentation fault (core dumped) | while read rev parents; do
process_split_commit "$rev" "$parents" 0;
done
Please note that this regression can not easily be reproduced, normally a subtree split just works.
Reverting the last three commits "fixes" the issue. So I kindly ask the last three commits to be reverted.
^ permalink raw reply
* Re: Regression in git-subtree.sh, introduced in 2.20.1, after 315a84f9aa0e2e629b0680068646b0032518ebed
From: Duy Nguyen @ 2018-12-31 10:51 UTC (permalink / raw)
To: Marc Balmer; +Cc: Git Mailing List, roger.strain, Junio C Hamano
In-Reply-To: <B81E8278-965A-4860-95E1-20ADCAB29BC9@msys.ch>
On Mon, Dec 31, 2018 at 5:44 PM Marc Balmer <marc@msys.ch> wrote:
>
> Hi
>
> One of the last three commits in git-subtree.sh introduced a regression leading to a segfault.
>
> Here is the error message when I try to split out my i18n files:
>
> $ git subtree split --prefix=i18n
> cache for e39a2a0c6431773a5d831eb3cb7f1cd40d0da623 already exists!
> (Lots of output omitted)
> 436/627 (1819) [1455] <- Stays at 436/ while the numbers in () and [] increase, then segfaults:
> /usr/libexec/git-core/git-subtree: line 751: 54693 Done eval "$grl"
> 54694 Segmentation fault (core dumped) | while read rev parents; do
Do you still have this core dump? Could you run it and see if it's
"git" that crashed (and where) or "sh"?
> process_split_commit "$rev" "$parents" 0;
> done
>
> Please note that this regression can not easily be reproduced, normally a subtree split just works.
>
> Reverting the last three commits "fixes" the issue. So I kindly ask the last three commits to be reverted.
Please provide the SHA-1 of the "good" commit you tested.
--
Duy
^ permalink raw reply
* Re: Regression in git-subtree.sh, introduced in 2.20.1, after 315a84f9aa0e2e629b0680068646b0032518ebed
From: Marc Balmer @ 2018-12-31 11:12 UTC (permalink / raw)
To: Duy Nguyen; +Cc: Git Mailing List, roger.strain, Junio C Hamano
In-Reply-To: <CACsJy8B7=xNBeyYYgMqh-aU_1-Rb8g5t5SwK5jvfbMw4ch-ZLQ@mail.gmail.com>
> Am 31.12.2018 um 11:51 schrieb Duy Nguyen <pclouds@gmail.com>:
>
> On Mon, Dec 31, 2018 at 5:44 PM Marc Balmer <marc@msys.ch> wrote:
>>
>> Hi
>>
>> One of the last three commits in git-subtree.sh introduced a regression leading to a segfault.
>>
>> Here is the error message when I try to split out my i18n files:
>>
>> $ git subtree split --prefix=i18n
>> cache for e39a2a0c6431773a5d831eb3cb7f1cd40d0da623 already exists!
>> (Lots of output omitted)
>> 436/627 (1819) [1455] <- Stays at 436/ while the numbers in () and [] increase, then segfaults:
>> /usr/libexec/git-core/git-subtree: line 751: 54693 Done eval "$grl"
>> 54694 Segmentation fault (core dumped) | while read rev parents; do
>
> Do you still have this core dump? Could you run it and see if it's
> "git" that crashed (and where) or "sh"?
It is /usr/bin/bash that segfaults. My guess is, that it runs out of memory (as described above, git-subtree enters an infinite loop untils it segafults).
>
>> process_split_commit "$rev" "$parents" 0;
>> done
>>
>> Please note that this regression can not easily be reproduced, normally a subtree split just works.
>>
>> Reverting the last three commits "fixes" the issue. So I kindly ask the last three commits to be reverted.
>
> Please provide the SHA-1 of the "good" commit you tested.
I reverted these three commits (actually the last three commits to contrib/subtree/git-subtree.sh):
19ad68d95d6f8104eca1e86f8d1dfae50c7fb268
68f8ff81513fb3599ef3dfc3dd11da36d868e91b
315a84f9aa0e2e629b0680068646b0032518ebed
And then it worked.
- Marc
--
> Duy
^ permalink raw reply
* Re: Regression in git-subtree.sh, introduced in 2.20.1, after 315a84f9aa0e2e629b0680068646b0032518ebed
From: Duy Nguyen @ 2018-12-31 11:20 UTC (permalink / raw)
To: Marc Balmer; +Cc: Git Mailing List, roger.strain, Junio C Hamano
In-Reply-To: <11AC6C27-4C74-43B1-89F6-98ABBFE74E0E@msys.ch>
On Mon, Dec 31, 2018 at 6:13 PM Marc Balmer <marc@msys.ch> wrote:
>
>
>
> > Am 31.12.2018 um 11:51 schrieb Duy Nguyen <pclouds@gmail.com>:
> >
> > On Mon, Dec 31, 2018 at 5:44 PM Marc Balmer <marc@msys.ch> wrote:
> >>
> >> Hi
> >>
> >> One of the last three commits in git-subtree.sh introduced a regression leading to a segfault.
> >>
> >> Here is the error message when I try to split out my i18n files:
> >>
> >> $ git subtree split --prefix=i18n
> >> cache for e39a2a0c6431773a5d831eb3cb7f1cd40d0da623 already exists!
> >> (Lots of output omitted)
> >> 436/627 (1819) [1455] <- Stays at 436/ while the numbers in () and [] increase, then segfaults:
> >> /usr/libexec/git-core/git-subtree: line 751: 54693 Done eval "$grl"
> >> 54694 Segmentation fault (core dumped) | while read rev parents; do
> >
> > Do you still have this core dump? Could you run it and see if it's
> > "git" that crashed (and where) or "sh"?
>
> It is /usr/bin/bash that segfaults. My guess is, that it runs out of memory (as described above, git-subtree enters an infinite loop untils it segafults).
Ah that's better (I was worried about "git" crashing). The problematic
commit should be 19ad68d95d (subtree: performance improvement for
finding unexpected parent commits - 2018-10-12) then, although I can't
see why.
I don't think we have any release coming up soon, so maybe Roger can
still have some time to fix it instead of a just a revert.
>
> >
> >> process_split_commit "$rev" "$parents" 0;
> >> done
> >>
> >> Please note that this regression can not easily be reproduced, normally a subtree split just works.
> >>
> >> Reverting the last three commits "fixes" the issue. So I kindly ask the last three commits to be reverted.
> >
> > Please provide the SHA-1 of the "good" commit you tested.
>
> I reverted these three commits (actually the last three commits to contrib/subtree/git-subtree.sh):
>
> 19ad68d95d6f8104eca1e86f8d1dfae50c7fb268
> 68f8ff81513fb3599ef3dfc3dd11da36d868e91b
> 315a84f9aa0e2e629b0680068646b0032518ebed
>
> And then it worked.
>
> - Marc
>
> --
> > Duy
>
--
Duy
^ permalink raw reply
* Re: Regression in git-subtree.sh, introduced in 2.20.1, after 315a84f9aa0e2e629b0680068646b0032518ebed
From: Marc Balmer @ 2018-12-31 11:24 UTC (permalink / raw)
To: Duy Nguyen; +Cc: Git Mailing List, roger.strain, Junio C Hamano
In-Reply-To: <CACsJy8AQ1raB+2wjEBtDrAvJm0v-3exJ-FVB2ZyL6VpRFQkspQ@mail.gmail.com>
> Am 31.12.2018 um 12:20 schrieb Duy Nguyen <pclouds@gmail.com>:
>
> On Mon, Dec 31, 2018 at 6:13 PM Marc Balmer <marc@msys.ch> wrote:
>>
>>
>>
>>> Am 31.12.2018 um 11:51 schrieb Duy Nguyen <pclouds@gmail.com>:
>>>
>>> On Mon, Dec 31, 2018 at 5:44 PM Marc Balmer <marc@msys.ch> wrote:
>>>>
>>>> Hi
>>>>
>>>> One of the last three commits in git-subtree.sh introduced a regression leading to a segfault.
>>>>
>>>> Here is the error message when I try to split out my i18n files:
>>>>
>>>> $ git subtree split --prefix=i18n
>>>> cache for e39a2a0c6431773a5d831eb3cb7f1cd40d0da623 already exists!
>>>> (Lots of output omitted)
>>>> 436/627 (1819) [1455] <- Stays at 436/ while the numbers in () and [] increase, then segfaults:
>>>> /usr/libexec/git-core/git-subtree: line 751: 54693 Done eval "$grl"
>>>> 54694 Segmentation fault (core dumped) | while read rev parents; do
>>>
>>> Do you still have this core dump? Could you run it and see if it's
>>> "git" that crashed (and where) or "sh"?
>>
>> It is /usr/bin/bash that segfaults. My guess is, that it runs out of memory (as described above, git-subtree enters an infinite loop untils it segafults).
>
> Ah that's better (I was worried about "git" crashing). The problematic
> commit should be 19ad68d95d (subtree: performance improvement for
> finding unexpected parent commits - 2018-10-12) then, although I can't
> see why.
>
> I don't think we have any release coming up soon, so maybe Roger can
> still have some time to fix it instead of a just a revert.
In a (private) Email to me, he indicated that had no time for a fix. Maybe he can speak up here?
In any case, if I can help testing, I am in. I just don't know the inner workings of git-subtree.sh (I am a mere user of it...)
>
>>
>>>
>>>> process_split_commit "$rev" "$parents" 0;
>>>> done
>>>>
>>>> Please note that this regression can not easily be reproduced, normally a subtree split just works.
>>>>
>>>> Reverting the last three commits "fixes" the issue. So I kindly ask the last three commits to be reverted.
>>>
>>> Please provide the SHA-1 of the "good" commit you tested.
>>
>> I reverted these three commits (actually the last three commits to contrib/subtree/git-subtree.sh):
>>
>> 19ad68d95d6f8104eca1e86f8d1dfae50c7fb268
>> 68f8ff81513fb3599ef3dfc3dd11da36d868e91b
>> 315a84f9aa0e2e629b0680068646b0032518ebed
>>
>> And then it worked.
>>
>> - Marc
>>
>> --
>>> Duy
>>
>
>
> --
> Duy
^ permalink raw reply
* Re: Regression in git-subtree.sh, introduced in 2.20.1, after 315a84f9aa0e2e629b0680068646b0032518ebed
From: Duy Nguyen @ 2018-12-31 11:36 UTC (permalink / raw)
To: Marc Balmer; +Cc: Git Mailing List, roger.strain, Junio C Hamano
In-Reply-To: <0F754615-C852-49D8-8E0C-DD2A00A15ED1@msys.ch>
On Mon, Dec 31, 2018 at 6:24 PM Marc Balmer <marc@msys.ch> wrote:
> In a (private) Email to me, he indicated that had no time for a fix. Maybe he can speak up here?
Well, I guess Junio will revert when he's back after the holidays
then. Meanwhile..
> In any case, if I can help testing, I am in. I just don't know the inner workings of git-subtree.sh (I am a mere user of it...)
If the repo you're facing the problem is publicly available, that
would be great so some of us could try reproduce.
Otherwise we'll need your help to track this problem down. in
git-subtree script line 640 (or somewhere close)
progress "$revcount/$revmax ($createcount) [$extracount]"
could you update it to show $parents and $rev as well, e.g.
progress "$revcount/$revmax ($createcount) [$extracount] ($parents) ($rev)"
Then please run these commands and post the output here
git rev-parse <that-rev>^@
and
git show -s --pretty=%P <that-rev>
where <that-rev> is $rev from the last few progress lines before bash crashes.
--
Duy
^ permalink raw reply
* Re: Regression in git-subtree.sh, introduced in 2.20.1, after 315a84f9aa0e2e629b0680068646b0032518ebed
From: Marc Balmer @ 2018-12-31 12:31 UTC (permalink / raw)
To: Duy Nguyen; +Cc: Git Mailing List, roger.strain, Junio C Hamano
In-Reply-To: <CACsJy8C8DVz7u7z01Q3T_vY+DY-StwCQLhkhDJ6XK5C2z0agLA@mail.gmail.com>
> Am 31.12.2018 um 12:36 schrieb Duy Nguyen <pclouds@gmail.com>:
>
> On Mon, Dec 31, 2018 at 6:24 PM Marc Balmer <marc@msys.ch> wrote:
>> In a (private) Email to me, he indicated that had no time for a fix. Maybe he can speak up here?
>
> Well, I guess Junio will revert when he's back after the holidays
> then. Meanwhile..
>
>> In any case, if I can help testing, I am in. I just don't know the inner workings of git-subtree.sh (I am a mere user of it...)
>
> If the repo you're facing the problem is publicly available, that
> would be great so some of us could try reproduce.
Unfortunately it is not.
>
> Otherwise we'll need your help to track this problem down. in
> git-subtree script line 640 (or somewhere close)
>
> progress "$revcount/$revmax ($createcount) [$extracount]"
>
> could you update it to show $parents and $rev as well, e.g.
>
> progress "$revcount/$revmax ($createcount) [$extracount] ($parents) ($rev)"
I did add this, plus changed progress to output a linefeed, and now just before the crash, the output looks like this:
436/627 (2013) [1649] (6e54a90a29e4e01fa2d6a42c232e02e08e912b2d) (2ca7b24e731ff91c94c9abf214686cb29cdc367e)
436/627 (2014) [1650] (1ef866e5a18012e80eed36315deb932c2b66d34a) (6e54a90a29e4e01fa2d6a42c232e02e08e912b2d)
436/627 (2015) [1651] (c8585f441548dd43f113a96ba48f6fa70363d388) (1ef866e5a18012e80eed36315deb932c2b66d34a)
436/627 (2016) [1652] (663bb110a58decfe889cf7c6b766f1d0c032ba39) (c8585f441548dd43f113a96ba48f6fa70363d388)
436/627 (2017) [1653] (edbdd28e009e52c8001bb54e53a56b059167e07d) (663bb110a58decfe889cf7c6b766f1d0c032ba39)
436/627 (2018) [1654] (c47739713912ae6e94714b9a1a6732407b236932) (edbdd28e009e52c8001bb54e53a56b059167e07d)
436/627 (2019) [1655] (d444823b97d9a8e53c4e721a44e4c49619d0b372) (c47739713912ae6e94714b9a1a6732407b236932)
436/627 (2020) [1656] (15a7ccecb2ca8bc47c77a997f8c74e7ac3b13325) (d444823b97d9a8e53c4e721a44e4c49619d0b372)
436/627 (2021) [1657] (b9bc5c9b33b100b57e23626ff422dac73f94384e) (15a7ccecb2ca8bc47c77a997f8c74e7ac3b13325)
436/627 (2022) [1658] (eec0f28c6fe5f7d664c41a913883d64cdf53c111) (b9bc5c9b33b100b57e23626ff422dac73f94384e)
436/627 (2023) [1659] (e0ddd9c60f71283996cfb169f1dbb77e8f7c4b94) (eec0f28c6fe5f7d664c41a913883d64cdf53c111)
436/627 (2024) [1660] (27b96988847caf3bfd71df2d7f58cbe6ba78208a) (e0ddd9c60f71283996cfb169f1dbb77e8f7c4b94)
436/627 (2025) [1661] (11e5861e50f88237ce362b6c7531e4e90bac86ac) (27b96988847caf3bfd71df2d7f58cbe6ba78208a)
/usr/libexec/git-core/git-subtree: line 751: 122202 Done eval "$grl"
122203 Segmentation fault (core dumped) | while read rev parents; do
process_split_commit "$rev" "$parents" 0;
done
>
> Then please run these commands and post the output here
>
> git rev-parse <that-rev>^@
Did that with the last three lines:
$ git rev-parse 27b96988847caf3bfd71df2d7f58cbe6ba78208a^@
11e5861e50f88237ce362b6c7531e4e90bac86ac
$ git rev-parse e0ddd9c60f71283996cfb169f1dbb77e8f7c4b94^@
27b96988847caf3bfd71df2d7f58cbe6ba78208a
$ git rev-parse eec0f28c6fe5f7d664c41a913883d64cdf53c111^@
e0ddd9c60f71283996cfb169f1dbb77e8f7c4b94
>
> and
>
> git show -s --pretty=%P <that-rev>
$ git show -s --pretty=%P 27b96988847caf3bfd71df2d7f58cbe6ba78208a
11e5861e50f88237ce362b6c7531e4e90bac86ac
$ git show -s --pretty=%P e0ddd9c60f71283996cfb169f1dbb77e8f7c4b94
27b96988847caf3bfd71df2d7f58cbe6ba78208a
$ git show -s --pretty=%P eec0f28c6fe5f7d664c41a913883d64cdf53c111
e0ddd9c60f71283996cfb169f1dbb77e8f7c4b94
>
> where <that-rev> is $rev from the last few progress lines before bash crashes.
> --
> Duy
^ permalink raw reply
* Re: [PATCH v3 6/8] test-lib: extract Bash version check for '-x' tracing
From: Carlo Arenas @ 2018-12-31 17:14 UTC (permalink / raw)
To: SZEDER Gábor; +Cc: Junio C Hamano, Jeff King, git
In-Reply-To: <20181230191629.3232-7-szeder.dev@gmail.com>
slightly offtopic and definitely not meant to be relevant as a critic
on this specific change which I found otherwise fine, but just a heads
up that this test itself is bash specific (since it uses arrays,
against the recommendation in Documentation/CodingGuidelines) and
therefore breaks, at least in NetBSD as reported in :
https://public-inbox.org/git/20181121224929.GD5348@jessie.local/
Carlo
^ permalink raw reply
* Unusual library path on OS X
From: Jeffrey Walton @ 2018-12-31 20:57 UTC (permalink / raw)
To: Git List
Hi Everyone,
I'm building Git 1.20.1 from sources on OS X. Git (and its dependents)
were configured with:
PKGCONFPATH: /usr/local/lib/pkgconfig
CPPFLAGS: -I/usr/local/include -DNDEBUG
CFLAGS: -g2 -O2 -march=native -fPIC
CXXFLAGS: -g2 -O2 -march=native -fPIC
LDFLAGS: -L/usr/local/lib -Wl,-rpath,/usr/local/lib
LDLIBS: -ldl -lpthread
For Git it results in a configure called with:
PERL="$SH_PERL" \
PKG_CONFIG_PATH="${BUILD_PKGCONFIG[*]}" \
CPPFLAGS="${BUILD_CPPFLAGS[*]}" \
CFLAGS="${BUILD_CFLAGS[*]}" \
CXXFLAGS="${BUILD_CXXFLAGS[*]}" \
LDFLAGS="${BUILD_LDFLAGS[*]}" \
LIBS="-lssl -lcrypto -lz ${BUILD_LIBS[*]}" \
./configure --prefix="$BUILD_PREFIX" --with-lib="$BUILD_LIBDIR" \
...
BUILD_PREFIX is /usr/local, and BUILD_LIBDIR=/usr/local/lib.
Linking produces the following, which seems a bit unusual. It looks
like PREFIX and LIBDIR are being concatenated:
LINK t/helper/test-fake-ssh
LINK t/helper/test-line-buffer
LINK t/helper/test-svn-fe
ld: warning: directory not found for option '-L/usr/local//usr/local/lib'
ld: warning: directory not found for option '-L/usr/local//usr/local/lib'
ld: warning: directory not found for option '-L/usr/local//usr/local/lib'
ld: warning: directory not found for option '-L/usr/local//usr/local/lib'
When I try to use --with-libdir=/usr/local/lib, I get:
configure: WARNING: unrecognized options: --with-libdir
Jeff
^ permalink raw reply
* [PATCH] log: add %S option (like --source) to log --format
From: issac.trotts @ 2018-12-31 21:48 UTC (permalink / raw)
To: git; +Cc: noemi, Issac Trotts, Issac Trotts
From: Issac Trotts <issac.trotts@gmail.com>
Make it possible to write for example
git log --format="%H,%S"
where the %S at the end is a new placeholder that prints out the ref
(tag/branch) for each commit.
Using %d might seem like an alternative but it only shows the ref for the last
commit in the branch.
Signed-off-by: Issac Trotts <issactrotts@google.com>
---
This change is based on a question from Stack Overflow:
https://stackoverflow.com/questions/12712775/git-get-source-information-in-format
---
Documentation/pretty-formats.txt | 2 ++
builtin/log.c | 2 +-
log-tree.c | 1 +
pretty.c | 14 +++++++++
pretty.h | 1 +
t/t4205-log-pretty-formats.sh | 50 ++++++++++++++++++++++++++++++++
t/t6006-rev-list-format.sh | 4 +++
7 files changed, 73 insertions(+), 1 deletion(-)
diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index 417b638cd..de6953108 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -134,6 +134,8 @@ The placeholders are:
- '%cI': committer date, strict ISO 8601 format
- '%d': ref names, like the --decorate option of linkgit:git-log[1]
- '%D': ref names without the " (", ")" wrapping.
+- '%S': ref name given on the command line by which the commit was reached
+ (like `git log --source`), only works with `git log`
- '%e': encoding
- '%s': subject
- '%f': sanitized subject line, suitable for a filename
diff --git a/builtin/log.c b/builtin/log.c
index e8e51068b..be3025657 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -203,7 +203,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
rev->diffopt.filter || rev->diffopt.flags.follow_renames)
rev->always_show_header = 0;
- if (source) {
+ if (source || (rev->pretty_given && (rev->commit_format == CMIT_FMT_USERFORMAT) && w.source)) {
init_revision_sources(&revision_sources);
rev->sources = &revision_sources;
}
diff --git a/log-tree.c b/log-tree.c
index 10680c139..3cb14256e 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -700,6 +700,7 @@ void show_log(struct rev_info *opt)
ctx.color = opt->diffopt.use_color;
ctx.expand_tabs_in_log = opt->expand_tabs_in_log;
ctx.output_encoding = get_log_output_encoding();
+ ctx.rev = opt;
if (opt->from_ident.mail_begin && opt->from_ident.name_begin)
ctx.from_ident = &opt->from_ident;
if (opt->graph)
diff --git a/pretty.c b/pretty.c
index b83a3ecd2..06075d625 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1084,6 +1084,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
struct commit_list *p;
const char *arg;
int ch;
+ char **slot;
/* these are independent of the commit */
switch (placeholder[0]) {
@@ -1194,6 +1195,16 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
load_ref_decorations(NULL, DECORATE_SHORT_REFS);
format_decorations_extended(sb, commit, c->auto_color, "", ", ", "");
return 1;
+ case 'S': /* tag/branch like --source */
+ if (c->pretty_ctx->rev == NULL || c->pretty_ctx->rev->sources == NULL) {
+ return 0;
+ }
+ slot = revision_sources_at(c->pretty_ctx->rev->sources, commit);
+ if (!(slot && *slot)) {
+ return 0;
+ }
+ strbuf_addstr(sb, *slot);
+ return 1;
case 'g': /* reflog info */
switch(placeholder[1]) {
case 'd': /* reflog selector */
@@ -1498,6 +1509,9 @@ static size_t userformat_want_item(struct strbuf *sb, const char *placeholder,
case 'N':
w->notes = 1;
break;
+ case 'S':
+ w->source = 1;
+ break;
}
return 0;
}
diff --git a/pretty.h b/pretty.h
index 7359d318a..87ca5dfcb 100644
--- a/pretty.h
+++ b/pretty.h
@@ -60,6 +60,7 @@ static inline int cmit_fmt_is_mail(enum cmit_fmt fmt)
struct userformat_want {
unsigned notes:1;
+ unsigned source:1;
};
/* Set the flag "w->notes" if there is placeholder %N in "fmt". */
diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
index 978a8a66f..7df8c3d4e 100755
--- a/t/t4205-log-pretty-formats.sh
+++ b/t/t4205-log-pretty-formats.sh
@@ -621,4 +621,54 @@ test_expect_success 'trailer parsing not fooled by --- line' '
test_cmp expect actual
'
+test_expect_success 'set up %S tests' '
+ git checkout --orphan source-a &&
+ test_commit one &&
+ test_commit two &&
+ git checkout -b source-b HEAD^ &&
+ test_commit three
+'
+
+test_expect_success 'log --format=%S paints branch names' '
+ cat >expect <<-\EOF &&
+ source-b
+ source-a
+ source-b
+ EOF
+ git log --format=%S source-a source-b >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'log --format=%S paints tag names' '
+ git tag -m tagged source-tag &&
+ cat >expect <<-\EOF &&
+ source-tag
+ source-a
+ source-tag
+ EOF
+ git log --format=%S source-tag source-a >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success 'log --format=%S paints symmetric ranges' '
+ cat >expect <<-\EOF &&
+ source-b
+ source-a
+ EOF
+ git log --format=%S source-a...source-b >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success '%S in git log --format works with other placeholders (part 1)' '
+ git log --format="source-b %h" source-b >expect &&
+ git log --format="%S %h" source-b >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success '%S in git log --format works with other placeholders (part 2)' '
+ git log --format="%h source-b" source-b >expect &&
+ git log --format="%h %S" source-b >actual &&
+ test_cmp expect actual
+'
+
test_done
diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh
index ec42c2f77..da113d975 100755
--- a/t/t6006-rev-list-format.sh
+++ b/t/t6006-rev-list-format.sh
@@ -185,6 +185,10 @@ test_expect_success 'basic colors' '
test_cmp expect actual
'
+test_expect_success '%S is not a placeholder for rev-list yet' '
+ git rev-list --format="%S" -1 master | grep "%S"
+'
+
test_expect_success 'advanced colors' '
cat >expect <<-EOF &&
commit $head2
--
2.19.1
^ permalink raw reply related
* [PATCH] doc: remove unneeded TODO for release_commit_memory
From: Albert Burt @ 2018-12-31 23:57 UTC (permalink / raw)
To: git; +Cc: gitster, stefanbeller, Albert Burt
The code that was merged with commit 1102405 left in an TODO that
is no longer relevant. It seems as if we can remove this todo.
util seems to not be a field of the struct commit,
definition of struct commit --> commit.c:27
The commit list also, does not contain a field for util.
____
By making a contribution to this project, I certify that:
a. The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
b. The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
c. The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
d. I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
____
Signed-off-by: Albert Burt <aburthinds@gmail.com>
---
commit.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/commit.c b/commit.c
index 2d94e0b199..2ff6dca0bc 100644
--- a/commit.c
+++ b/commit.c
@@ -357,8 +357,6 @@ void release_commit_memory(struct commit *c)
c->index = 0;
free_commit_buffer(c);
free_commit_list(c->parents);
- /* TODO: what about commit->util? */
-
c->object.parsed = 0;
}
--
2.17.2 (Apple Git-113)
^ permalink raw reply related
* Re: [PATCH] doc: remove unneeded TODO for release_commit_memory
From: Duy Nguyen @ 2019-01-01 10:40 UTC (permalink / raw)
To: Albert Burt; +Cc: Git Mailing List, Junio C Hamano, Stefan Beller
In-Reply-To: <20181231235713.76200-1-aburthinds@gmail.com>
On Tue, Jan 1, 2019 at 7:02 AM Albert Burt <aburthinds@gmail.com> wrote:
>
> The code that was merged with commit 1102405 left in an TODO that
People usually use something this to produce the commit reference
git show -s --date=short --pretty='format:%h (%s - %ad)'
which produces
110240588d (Merge branch 'sb/object-store-alloc' - 2018-06-25)
> is no longer relevant. It seems as if we can remove this todo.
> util seems to not be a field of the struct commit,
> definition of struct commit --> commit.c:27
> The commit list also, does not contain a field for util.
There was commit->util, which was deleted in 9d2c97016f (commit.h:
delete 'util' field in struct commit - 2018-05-19). You can mention it
too if you reroll this patch.
> ____
> By making a contribution to this project, I certify that:
>
> a. The contribution was created in whole or in part by me and I
> have the right to submit it under the open source license
> indicated in the file; or
>
> b. The contribution is based upon previous work that, to the best
> of my knowledge, is covered under an appropriate open source
> license and I have the right under that license to submit that
> work with modifications, whether created in whole or in part
> by me, under the same open source license (unless I am
> permitted to submit under a different license), as indicated
> in the file; or
>
> c. The contribution was provided directly to me by some other
> person who certified (a), (b) or (c) and I have not modified
> it.
>
> d. I understand and agree that this project and the contribution
> are public and that a record of the contribution (including all
> personal information I submit with it, including my sign-off) is
> maintained indefinitely and may be redistributed consistent with
> this project or the open source license(s) involved.
> ____
I think you can drop this. Your S-o-b below implies all this.
> Signed-off-by: Albert Burt <aburthinds@gmail.com>
> ---
> commit.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/commit.c b/commit.c
> index 2d94e0b199..2ff6dca0bc 100644
> --- a/commit.c
> +++ b/commit.c
> @@ -357,8 +357,6 @@ void release_commit_memory(struct commit *c)
> c->index = 0;
> free_commit_buffer(c);
> free_commit_list(c->parents);
> - /* TODO: what about commit->util? */
> -
Obviously correct :)
> c->object.parsed = 0;
> }
>
> --
> 2.17.2 (Apple Git-113)
>
--
Duy
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox