[PATCH 1/2] rebase -i: optimize the creation of the todo file

Subsystems: the rest

DORMANTno replies

6 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH 1/2] rebase -i: optimize the creation of the todo file

From: Dominique Quatravaux <hidden>
Date: 2016-06-15 22:53:15

Instead of obtaining short SHA1's from "git rev-list" and hitting the repository
once more with "git rev-parse" for the full-size SHA1's, obtain long SHA1's from
"git rev-list" and truncate them with "cut".
---
 git-rebase--interactive.sh |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 5812222..8dcb8b0 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -774,17 +774,17 @@ else
 	revisions=$onto...$orig_head
 	shortrevisions=$shorthead
 fi
-git rev-list $merges_option --pretty=oneline --abbrev-commit \
-	--abbrev=7 --reverse --left-right --topo-order \
+git rev-list $merges_option --pretty=oneline --no-abbrev-commit \
+	--reverse --left-right --topo-order \
 	$revisions | \
 	sed -n "s/^>//p" |
-while read -r shortsha1 rest
+while read -r sha1 rest
 do
+	shortsha1=$(echo $sha1 | cut -c1-7)
 	if test t != "$preserve_merges"
 	then
 		printf '%s\n' "pick $shortsha1 $rest" >> "$todo"
 	else
-		sha1=$(git rev-parse $shortsha1)
 		if test -z "$rebase_root"
 		then
 			preserve=t
-- 
1.7.7.3

[PATCH 2/2] rebase -i: new option --name-rev

From: Dominique Quatravaux <hidden>
Date: 2016-06-15 22:53:15

If set, the second column of the rebase todo contains named revisions (obtained
with git name-rev) instead of short SHA1s.
---
 Documentation/git-rebase.txt  |   11 +++++++++++
 git-rebase--interactive.sh    |   11 ++++++++---
 git-rebase.sh                 |   10 ++++++++++
 t/t3404-rebase-interactive.sh |   11 +++++++++++
 4 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-rebase.txt b/Documentation/git-rebase.txt
index 504945c..e7ecd2c 100644
--- a/Documentation/git-rebase.txt
+++ b/Documentation/git-rebase.txt
@@ -365,6 +365,17 @@ If the '--autosquash' option is enabled by default using the
 configuration variable `rebase.autosquash`, this option can be
 used to override and disable this setting.
 
+--name-rev::
+--no-name-rev::
+	Instead of showing short SHA1 hashes in the todo list, show
+	human-readable revisions obtained with linkgit:git-name-rev[1].
++
+This option is only valid when the '--interactive' option is used.
++
+If the '--name-rev' option is enabled by default using the
+configuration variable `rebase.interactivenamerev`, this option can be
+used to override and disable this setting.
+
 --no-ff::
 	With --interactive, cherry-pick all rebased commits instead of
 	fast-forwarding over the unchanged ones.  This ensures that the
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 8dcb8b0..5583dcb 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -780,10 +780,15 @@ git rev-list $merges_option --pretty=oneline --no-abbrev-commit \
 	sed -n "s/^>//p" |
 while read -r sha1 rest
 do
-	shortsha1=$(echo $sha1 | cut -c1-7)
+	if test t = "$name_rev"
+	then
+		rev="$(git name-rev $sha1 | cut -d\  -f2)"
+	else
+		rev=$(echo $sha1 | cut -c1-7)
+	fi
 	if test t != "$preserve_merges"
 	then
-		printf '%s\n' "pick $shortsha1 $rest" >> "$todo"
+		printf '%s\n' "pick $rev $rest" >> "$todo"
 	else
 		if test -z "$rebase_root"
 		then
@@ -801,7 +806,7 @@ do
 		if test f = "$preserve"
 		then
 			touch "$rewritten"/$sha1
-			printf '%s\n' "pick $shortsha1 $rest" >> "$todo"
+			printf '%s\n' "pick $rev $rest" >> "$todo"
 		fi
 	fi
 done
diff --git a/git-rebase.sh b/git-rebase.sh
index 69c1374..9330be3 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -43,6 +43,8 @@ s,strategy=!       use the given merge strategy
 no-ff!             cherry-pick all commits, even if unchanged
 m,merge!           use merging strategies to rebase
 i,interactive!     let the user edit the list of commits to rebase
+name-rev           show revisions by name in the list of commits
+no-name-rev        show revisions by short SHA1 in the list (default)
 f,force-rebase!    force rebase even if branch is up to date
 X,strategy-option=! pass the argument through to the merge strategy
 stat!              display a diffstat of what changed upstream
@@ -98,6 +100,8 @@ action=
 preserve_merges=
 autosquash=
 test "$(git config --bool rebase.autosquash)" = "true" && autosquash=t
+name_rev=
+test "$(git config --bool rebase.interactivenamerev)" = "true" && name_rev=t
 
 read_basic_state () {
 	head_name=$(cat "$state_dir"/head-name) &&
@@ -287,6 +291,12 @@ do
 	-f|--no-ff)
 		force_rebase=t
 		;;
+	--name-rev)
+		name_rev=t
+		;;
+	--no-name-rev)
+		name_rev=
+		;;
 	--rerere-autoupdate|--no-rerere-autoupdate)
 		allow_rerere_autoupdate="$1"
 		;;
diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh
index b981572..299ce40 100755
--- a/t/t3404-rebase-interactive.sh
+++ b/t/t3404-rebase-interactive.sh
@@ -163,6 +163,17 @@ test_expect_success 'exchange two commits' '
 	test G = $(git cat-file commit HEAD | sed -ne \$p)
 '
 
+cat > expect-rebase-todo <<EOF
+pick branch1~1 H
+pick branch1 G
+EOF
+
+test_expect_success 'Symbolic revisions in --name-rev' '
+	exec > debug.log 2>&1 &&
+	FAKE_LINES="exec_cp_.git/rebase-merge/git-rebase-todo_rebase-todo 1 2" git rebase -i --name-rev HEAD~2 &&
+	test_cmp expect-rebase-todo rebase-todo
+'
+
 cat > expect << EOF
 diff --git a/file1 b/file1
 index f70f10e..fd79235 100644
-- 
1.7.7.3

Re: [PATCH 1/2] rebase -i: optimize the creation of the todo file

From: Johannes Sixt <hidden>
Date: 2016-06-15 22:53:15

Am 3/8/2012 11:42, schrieb Dominique Quatravaux:
+	shortsha1=$(echo $sha1 | cut -c1-7)
-		sha1=$(git rev-parse $shortsha1)
Why do you call it "optimization" when you spend two or three subprocesses
instead of one?

-- Hannes

Re: [PATCH 1/2] rebase -i: optimize the creation of the todo file

From: Dominique Quatravaux <hidden>
Date: 2016-06-15 22:53:15

On Thu, Mar 8, 2012 at 12:20 PM, Johannes Sixt [off-list ref] wrote:
Am 3/8/2012 11:42, schrieb Dominique Quatravaux:
quoted
+     shortsha1=$(echo $sha1 | cut -c1-7)
quoted
-             sha1=$(git rev-parse $shortsha1)
Why do you call it "optimization" when you spend two or three subprocesses
instead of one?
echo is a shell internal. "git rev-parse" is two processes just as
"cut" and a pipe. The difference is that cut doesn't hit the git
repository.

But the real purpose of this first change is to lay the ground for the
next one, so I'd be happy to change the patch description...


-- 
  Dominique Quatravaux
  +41 79 609 40 72

Re: [PATCH 1/2] rebase -i: optimize the creation of the todo file

From: Dominique Quatravaux <hidden>
Date: 2016-06-15 22:53:15

On Thu, Mar 8, 2012 at 12:36 PM, Dominique Quatravaux [off-list ref] wrote:
On Thu, Mar 8, 2012 at 12:20 PM, Johannes Sixt [off-list ref] wrote:
quoted
Am 3/8/2012 11:42, schrieb Dominique Quatravaux:
quoted
+     shortsha1=$(echo $sha1 | cut -c1-7)
quoted
-             sha1=$(git rev-parse $shortsha1)
Why do you call it "optimization" when you spend two or three subprocesses
instead of one?
echo is a shell internal. "git rev-parse" is two processes just as
"cut" and a pipe.
My mistake, strace git rev-parse revals that this is only one process.
Still, I think that saving a bunch of filesystem access beats saving
one fork() (one of the two processes in my patched version is a shell,
so no execve() there) but I admit I haven't benchmarked this.


-- 
  Dominique Quatravaux
  +41 79 609 40 72

Re: [PATCH 1/2] rebase -i: optimize the creation of the todo file

From: Johannes Sixt <hidden>
Date: 2016-06-15 22:53:15

Am 3/8/2012 12:41, schrieb Dominique Quatravaux:
On Thu, Mar 8, 2012 at 12:36 PM, Dominique Quatravaux [off-list ref] wrote:
quoted
On Thu, Mar 8, 2012 at 12:20 PM, Johannes Sixt [off-list ref] wrote:
quoted
Am 3/8/2012 11:42, schrieb Dominique Quatravaux:
quoted
+     shortsha1=$(echo $sha1 | cut -c1-7)
quoted
-             sha1=$(git rev-parse $shortsha1)
Why do you call it "optimization" when you spend two or three subprocesses
instead of one?
echo is a shell internal. "git rev-parse" is two processes just as
"cut" and a pipe.
My mistake, strace git rev-parse revals that this is only one process.
Still, I think that saving a bunch of filesystem access beats saving
one fork()... 
Not so on Windows.

But you must look at the repository in any case to avoid truncating the
SHA1 too much, as Thomas pointed out.

-- Hannes
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help