Skip to content

Commit

Permalink
Merge branch 'fix-undesired-snapshotting'
Browse files Browse the repository at this point in the history
* Branch commit log:
  jj-fzf: split-files: process filenames via array and avoid changing @
  jj-fzf: vivifydivergent: avoid undesired snapshotting
	* Fix undesired snapshotting before jj new by overloading only ui.editor via --config-toml
  jj-fzf: split-interactive: avoid undesired snapshotting
	* Fix undesired snapshotting before jj split by overloading only ui.editor via --config-toml
	* Keep previous description (if any) together with content diff that is kept

Signed-off-by: Tim Janik <[email protected]>
  • Loading branch information
tim-janik committed Dec 5, 2024
2 parents 154ea4f + 459ebd7 commit 2d09677
Showing 1 changed file with 22 additions and 38 deletions.
60 changes: 22 additions & 38 deletions jj-fzf
Original file line number Diff line number Diff line change
Expand Up @@ -670,22 +670,20 @@ DOC['split-interactive']='Use `jj split` to interactively select content diff hu
split-interactive()
(
R="$(xrev "${1:-@}")"
# Use $EDITOR to implement --split-with-no-description, truncate the first
# (original) description, but keep the description for subsequent edits
# Override ui.editor to implement --split-with-no-description: truncate the first
# (original) description, then keep the other description for subsequent edits
temp_dir
cat > $TEMPD/trunc1st.sh <<-\__EOF__
cat > $TEMPD/noeditor <<-\__EOF__
#!/usr/bin/env bash
set -Eeuo pipefail #-x
TRUNCATE=y
TRUNCATE=n
test $TRUNCATE == y && echo -n > "$1" || :
gsed 's/TRUNCATE=./TRUNCATE=n/' -i "$0"
gsed 's/TRUNCATE=./TRUNCATE=y/' -i "$0"
__EOF__
chmod +x $TEMPD/trunc1st.sh
export JJ_CONFIG= # unset ui.editor
export EDITOR=$TEMPD/trunc1st.sh
chmod +x $TEMPD/noeditor
( set -x
jj split --interactive -r "$R"
) || sleep 1
jj split --interactive -r "$R" --config-toml "ui.editor='$TEMPD/noeditor'"
) || ERROR
)
KEYBINDINGS["Alt-I"]="split-interactive"

Expand Down Expand Up @@ -995,34 +993,21 @@ DOC['split-files']='Use `jj split` in a loop to split each file modified by the
split-files()
(
R="$(xrev "${1:-@}")"
# save @
AT="$(xrev @)"
cd "$JJROOT" # operate on root relative file names
# show undo hints
jj --no-pager op log -n1
# read files affected by $R
mapfile -t MAPFILE < <(git diff-tree --no-commit-id --name-only -r "$(rev_commitid "$R")")
[[ ${#MAPFILE[@]} -gt 1 ]] ||
return
# show undo hint
echo "# jj op restore $(jj op log -n1 --no-graph -T 'self.id().short()') # <- command to undo the following split"
# adjust working copy, so 'jj split' resulting change_id is predictable
test "$R" == "$AT" || (set -x; jj edit -r "$R")
# split for n-1 files
MFS=$(git diff-tree --no-commit-id --name-status -r "$(rev_commitid @)")
R1=true # skip first split, need n-1 splits for n files
while read M F ; do
$R1 && { R1=false; continue; } # skip first
export JJ_CONFIG= # unset ui.editor
export EDITOR=true
# 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
( set -x
jj split -r @ -- "$F"
)
done <<<"$MFS"
# restore working copy
test "$R" == "$AT" || {
EXISTS=$($JJFZFSHOW -r "$AT" -T '"true"' 2>/dev/null) # squash might have killed an empty commit
if [[ $EXISTS =~ ^true ]] ; then
(set -x; jj edit -r "$AT")
else
(set -x; jj new -r "@")
fi
}
jj split --config-toml 'ui.editor="true"' -r "$R" -- "${MAPFILE[@]}"
) || ERROR
done
)
KEYBINDINGS["Alt-F"]="split-files"

Expand Down Expand Up @@ -1330,11 +1315,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
export JJ_CONFIG= # unset ui.editor
export 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+"
jj squash --from "$COMMIT" --into "$COMMIT+" --config-toml 'ui.editor="true"'
) || ERROR
)
KEYBINDINGS["Alt-V"]="vivifydivergent" NEXTS="$NEXTS vivifydivergent"
Expand Down

0 comments on commit 2d09677

Please sign in to comment.