From 41c46815008323c5db1314ccc234587231537339 Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Fri, 20 Dec 2024 02:54:58 +0100 Subject: [PATCH 1/6] jj-fzf: show content diff when editing commit message Show the first few thausand lines of the content diff during commit message creation, inspired by git commit --verbose Signed-off-by: Tim Janik --- jj-fzf | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/jj-fzf b/jj-fzf index 9b665fb..66e495c 100755 --- a/jj-fzf +++ b/jj-fzf @@ -383,21 +383,34 @@ echo_commit_msg() # ensure signoff echo_signoff ) -# Run user editor: user_editor_on_var +# Run user editor: user_editor_on_var [COMMIT] user_editor_on_var() { - local FILE="$1" N= + local FILE="$1" COMMIT="${3:-}" N= declare -n _ueovMSG="$2" # alias # create msg file temp_dir local TEMPFILE="$TEMPD/$FILE" cat >"$TEMPFILE" <<<"$_ueovMSG" + test -z "$COMMIT" || { + jj diff --ignore-working-copy --no-pager --color=never -r "$COMMIT" | + head -n 4000 > "$TEMPFILE.diff" + test -s "$TEMPFILE.diff" && { + echo + echo '# -------- >8 -------- >8 -------- 8< -------- 8< --------' + echo '# Everything below the snippet mark will be ignored' + echo '#' + echo '# Content diff of this revision:' + cat "$TEMPFILE.diff" + } + rm -f "$TEMPFILE.diff" + } >> "$TEMPFILE" # edit commit msg JJ_EDITOR="$(jj config get ui.editor 2>/dev/null || echo "${EDITOR:-pico}")" $JJ_EDITOR "$TEMPFILE" && N="$(cat "$TEMPFILE")" && { test "$_ueovMSG" != "$N" && - _ueovMSG="$(cat "$TEMPFILE")" + _ueovMSG="$(gsed -r '/^# -+ >8 -+ >8 -+ 8< -+ 8< -+/Q' < "$TEMPFILE")" rm -f "$TEMPFILE" return 0 } @@ -547,15 +560,15 @@ commit() MSG="$(echo_commit_msg "$R")" O="$MSG" if test "$R" == "$W" -a "$IMMU" != true ; then - user_editor_on_var "COMMIT-$R.txt" MSG && + user_editor_on_var "COMMIT-$R.txt" MSG "$R" && test "$O" != "$MSG" || ERROR "Commit cancelled by user" ( set -x jj commit -m "$MSG" ) || sleep 1 - else # R is @ and mutable + else # R is not @, may be immutable [[ $IMMU =~ ^true ]] || { - user_editor_on_var "COMMIT-$R.txt" MSG && + user_editor_on_var "COMMIT-$R.txt" MSG "$R" && test "$O" != "$MSG" || ERROR "Commit cancelled by user" test "$O" != "$MSG" && @@ -638,7 +651,7 @@ describe() R="$(xrev_or_commit "${1:-@}")" MSG="$(echo_commit_msg "$R")" O="$MSG" - user_editor_on_var "CHANGE-$R.txt" MSG || + user_editor_on_var "CHANGE-$R.txt" MSG "$R" || ERROR "Describe cancelled by user" test "$O" != "$MSG" || return From 98c3cc4a601076d456b6840f653a63f3812f4205 Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Fri, 20 Dec 2024 04:15:37 +0100 Subject: [PATCH 2/6] jj-fzf: honor the JJ_EDITOR precedence The JJ docs describe the precedence: $JJ_EDITOR > ui.editor > $VISUAL > $EDITOR > pico https://jj-vcs.github.io/jj/latest/config/#editor Signed-off-by: Tim Janik --- jj-fzf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jj-fzf b/jj-fzf index 66e495c..f1e1433 100755 --- a/jj-fzf +++ b/jj-fzf @@ -406,7 +406,8 @@ user_editor_on_var() rm -f "$TEMPFILE.diff" } >> "$TEMPFILE" # edit commit msg - JJ_EDITOR="$(jj config get ui.editor 2>/dev/null || echo "${EDITOR:-pico}")" + test -n "${JJ_EDITOR:-}" || # https://jj-vcs.github.io/jj/latest/config/#editor + JJ_EDITOR="$(jj config get ui.editor 2>/dev/null || echo "${VISUAL:-${EDITOR:-pico}}")" $JJ_EDITOR "$TEMPFILE" && N="$(cat "$TEMPFILE")" && { test "$_ueovMSG" != "$N" && From 9dff3ca4b0d7bb201682a4f3dde6de986e2b15ca Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Fri, 20 Dec 2024 04:21:15 +0100 Subject: [PATCH 3/6] jj-fzf: use JJ_EDITOR to really override th JJ editor settings Signed-off-by: Tim Janik --- jj-fzf | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/jj-fzf b/jj-fzf index f1e1433..74db8d0 100755 --- a/jj-fzf +++ b/jj-fzf @@ -698,8 +698,7 @@ DOC['split-interactive']='Use `jj split` to interactively select content diff hu split-interactive() ( R="$(xrev "${1:-@}")" - # Override ui.editor to implement --split-with-no-description: truncate the first - # (original) description, then keep the other description for subsequent edits + # To avoid message editing, truncate all but the first (original) description temp_dir cat > $TEMPD/noeditor <<-\__EOF__ #!/usr/bin/env bash @@ -709,8 +708,9 @@ split-interactive() gsed 's/TRUNCATE=./TRUNCATE=y/' -i "$0" __EOF__ chmod +x $TEMPD/noeditor + export JJ_EDITOR="$TEMPD/noeditor" # Override ui.editor to implement --split-with-no-description ( set -x - jj split --interactive -r "$R" --config-toml "ui.editor='$TEMPD/noeditor'" + jj split --interactive -r "$R" ) || ERROR ) KEYBINDINGS["Alt-I"]="split-interactive" @@ -1048,9 +1048,9 @@ split-files() # create n-1 new commits from n files while [[ ${#MAPFILE[@]} -gt 1 ]] ; do unset 'MAPFILE[-1]' # unset 'MAPFILE[${#MAPFILE[@]}-1]' - # Override ui.editor to implement --split-with-no-description + export JJ_EDITOR='true' # Override ui.editor to implement --split-with-no-description ( set -x - jj split --config-toml 'ui.editor="true"' -r "$R" -- "${MAPFILE[@]}" + jj split -r "$R" -- "${MAPFILE[@]}" ) || ERROR done ) @@ -1360,10 +1360,10 @@ vivifydivergent() test "$COMMIT" == "$WCOPY" && NOEDIT= || NOEDIT=--no-edit echo "# $SELF vivifydivergent $COMMIT" >&2 jj --no-pager log --no-graph -T builtin_log_oneline -r "$COMMIT" # --ignore-working-copy - # Override ui.editor to implement --squash-with-no-description + export JJ_EDITOR='true' # Override ui.editor to implement --squash-with-no-description ( set -x jj new --insert-after "$COMMIT" $NOEDIT - jj squash --from "$COMMIT" --into "$COMMIT+" --config-toml 'ui.editor="true"' + jj squash --from "$COMMIT" --into "$COMMIT+" ) || ERROR ) KEYBINDINGS["Alt-V"]="vivifydivergent" NEXTS="$NEXTS vivifydivergent" From 68c80f7a9340045ee4b2e9c011218f3abd904f1b Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Fri, 20 Dec 2024 03:46:40 +0100 Subject: [PATCH 4/6] jj-fzf: add ui.default-description to commit messages Signed-off-by: Tim Janik --- jj-fzf | 1 + 1 file changed, 1 insertion(+) diff --git a/jj-fzf b/jj-fzf index 74db8d0..f134e0d 100755 --- a/jj-fzf +++ b/jj-fzf @@ -379,6 +379,7 @@ echo_commit_msg() test ${#FILES[@]} -gt 0 && printf "%s: \n" "${FILES[@]}" || echo "" + jj config --no-pager get 'ui.default-description' 2>/dev/null || : fi # ensure signoff echo_signoff From 1e0f9472316cd41c69a2d076b71780675b24c318 Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Fri, 20 Dec 2024 04:42:01 +0100 Subject: [PATCH 5/6] jj-fzf: echo_commit_msg: skip signoff if no files changed Signed-off-by: Tim Janik --- jj-fzf | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jj-fzf b/jj-fzf index f134e0d..4751c9e 100755 --- a/jj-fzf +++ b/jj-fzf @@ -371,6 +371,7 @@ echo_commit_msg() gsed '/^\([A-Z][a-z0-9-]*-by\|Cc\):/d' | # strip Signed-off-by: gsed '/^$/d ; s/^/\t/ ; s/^\t\f$/ (no description)/ ; s/^\t\f/ /' done + echo_signoff else # Commit message based on files # start with file name prefixes cd "$JJROOT" # create root relative file names @@ -380,9 +381,9 @@ echo_commit_msg() printf "%s: \n" "${FILES[@]}" || echo "" jj config --no-pager get 'ui.default-description' 2>/dev/null || : + test ${#FILES[@]} -le 0 || + echo_signoff fi - # ensure signoff - echo_signoff ) # Run user editor: user_editor_on_var [COMMIT] user_editor_on_var() From eb77b16a8e38d92422691a008704d198820c12f9 Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Sat, 21 Dec 2024 02:11:33 +0100 Subject: [PATCH 6/6] jj-fzf: commit: --message fixup Signed-off-by: Tim Janik --- jj-fzf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jj-fzf b/jj-fzf index 4751c9e..1777c9d 100755 --- a/jj-fzf +++ b/jj-fzf @@ -567,7 +567,7 @@ commit() test "$O" != "$MSG" || ERROR "Commit cancelled by user" ( set -x - jj commit -m "$MSG" + jj commit --message="$MSG" ) || sleep 1 else # R is not @, may be immutable [[ $IMMU =~ ^true ]] || { @@ -576,7 +576,7 @@ commit() ERROR "Commit cancelled by user" test "$O" != "$MSG" && ( set -x - jj describe --no-edit -r "$R" -m "$MSG" + jj describe --no-edit -r "$R" --message="$MSG" ) || sleep 1 } # open new empty working copy commit