Skip to content

RFC: Git Evolve / Change#1356

Closed
poucet wants to merge 13 commits intogitgitgadget:masterfrom
poucet:evolve
Closed

RFC: Git Evolve / Change#1356
poucet wants to merge 13 commits intogitgitgadget:masterfrom
poucet:evolve

Conversation

@poucet
Copy link

@poucet poucet commented Sep 19, 2022

I'm reviving the original git evolve work that was started by sxenos@google.com (https://public-inbox.org/git/20190215043105.163688-1-sxenos@google.com/)

This work is intended to make it easier to deal with stacked changes.

The following set of patches introduces the design doc on the evolve command as well as the basics of the git change command.

Since the last update I've split the technical doc into multiple commits. I've also documented the git change command and ran clang-format on all the files.

cc: Jerry Zhang jerry@skydio.com
cc: Phillip Wood phillip.wood123@gmail.com
cc: Ævar Arnfjörð Bjarmason avarab@gmail.com
cc: Chris Poucet poucet@google.com
cc: Glen Choo chooglen@google.com

@gitgitgadget
Copy link

gitgitgadget bot commented Sep 19, 2022

Welcome to GitGitGadget

Hi @poucet, and welcome to GitGitGadget, the GitHub App to send patch series to the Git mailing list from GitHub Pull Requests.

Please make sure that your Pull Request has a good description, as it will be used as cover letter. You can CC potential reviewers by adding a footer to the PR description with the following syntax:

CC: Revi Ewer <revi.ewer@example.com>, Ill Takalook <ill.takalook@example.net>

Also, it is a good idea to review the commit messages one last time, as the Git project expects them in a quite specific form:

  • the lines should not exceed 76 columns,
  • the first line should be like a header and typically start with a prefix like "tests:" or "revisions:" to state which subsystem the change is about, and
  • the commit messages' body should be describing the "why?" of the change.
  • Finally, the commit messages should end in a Signed-off-by: line matching the commits' author.

It is in general a good idea to await the automated test ("Checks") in this Pull Request before contributing the patches, e.g. to avoid trivial issues such as unportable code.

Contributing the patches

Before you can contribute the patches, your GitHub username needs to be added to the list of permitted users. Any already-permitted user can do that, by adding a comment to your PR of the form /allow. A good way to find other contributors is to locate recent pull requests where someone has been /allowed:

Both the person who commented /allow and the PR author are able to /allow you.

An alternative is the channel #git-devel on the Libera Chat IRC network:

<newcontributor> I've just created my first PR, could someone please /allow me? https://github.com/gitgitgadget/git/pull/12345
<veteran> newcontributor: it is done
<newcontributor> thanks!

Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment /submit.

If you want to see what email(s) would be sent for a /submit request, add a PR comment /preview to have the email(s) sent to you. You must have a public GitHub email address for this. Note that any reviewers CC'd via the list in the PR description will not actually be sent emails.

After you submit, GitGitGadget will respond with another comment that contains the link to the cover letter mail in the Git mailing list archive. Please make sure to monitor the discussion in that thread and to address comments and suggestions (while the comments and suggestions will be mirrored into the PR by GitGitGadget, you will still want to reply via mail).

If you do not want to subscribe to the Git mailing list just to be able to respond to a mail, you can download the mbox from the Git mailing list archive (click the (raw) link), then import it into your mail program. If you use GMail, you can do this via:

curl -g --user "<EMailAddress>:<Password>" \
    --url "imaps://imap.gmail.com/INBOX" -T /path/to/raw.txt

To iterate on your change, i.e. send a revised patch or patch series, you will first want to (force-)push to the same branch. You probably also want to modify your Pull Request description (or title). It is a good idea to summarize the revision by adding something like this to the cover letter (read: by editing the first comment on the PR, i.e. the PR description):

Changes since v1:
- Fixed a typo in the commit message (found by ...)
- Added a code comment to ... as suggested by ...
...

To send a new iteration, just add another PR comment with the contents: /submit.

Need help?

New contributors who want advice are encouraged to join git-mentoring@googlegroups.com, where volunteers who regularly contribute to Git are willing to answer newbie questions, give advice, or otherwise provide mentoring to interested contributors. You must join in order to post or view messages, but anyone can join.

You may also be able to find help in real time in the developer IRC channel, #git-devel on Libera Chat. Remember that IRC does not support offline messaging, so if you send someone a private message and log out, they cannot respond to you. The scrollback of #git-devel is archived, though.

@dscho
Copy link
Member

dscho commented Sep 19, 2022

/allow

@gitgitgadget
Copy link

gitgitgadget bot commented Sep 19, 2022

User poucet is now allowed to use GitGitGadget.

@gitgitgadget
Copy link

gitgitgadget bot commented Sep 19, 2022

There are issues in commit fd9b58f:
evolve: add delete command
Commit not signed off

@gitgitgadget
Copy link

gitgitgadget bot commented Sep 23, 2022

There are issues in commit 6cc9f09:
commit-graph: Fix missing closedir in expire_commit_graphs
Prefixed commit message must be in lower case

@gitgitgadget
Copy link

gitgitgadget bot commented Sep 23, 2022

There are issues in commit f75f59b:
evolve: Add documentation for the git change command.
Commit checks stopped - the message is too short
Prefixed commit message must be in lower case
Commit not signed off

@gitgitgadget
Copy link

gitgitgadget bot commented Sep 23, 2022

There are issues in commit 2f0ab82:
evolve: Add documentation for the git change command.
Commit checks stopped - the message is too short
Prefixed commit message must be in lower case
Commit not signed off

@gitgitgadget
Copy link

gitgitgadget bot commented Sep 23, 2022

There are issues in commit c26b80f:
evolve: Add documentation for the git change command.
Prefixed commit message must be in lower case

@poucet
Copy link
Author

poucet commented Sep 23, 2022

/submit

@gitgitgadget
Copy link

gitgitgadget bot commented Sep 23, 2022

Submitted as pull.1356.git.1663959324.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-1356/poucet/evolve-v1

To fetch this version to local tag pr-1356/poucet/evolve-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-1356/poucet/evolve-v1

@gitgitgadget
Copy link

gitgitgadget bot commented Sep 23, 2022

User Jerry Zhang <jerry@skydio.com> has been added to the cc: list.

@gitgitgadget
Copy link

gitgitgadget bot commented Sep 25, 2022

On the Git mailing list, Phillip Wood wrote (reply to this):

Hi Christophe

On 23/09/2022 19:55, Christophe Poucet via GitGitGadget wrote:
> I'm reviving the original git evolve work that was started by
> sxenos@google.com
> (https://public-inbox.org/git/20190215043105.163688-1-sxenos@google.com/)
> > This work is intended to make it easier to deal with stacked changes.
> > The following set of patches introduces the design doc on the evolve command
> as well as the basics of the git change command.

Thanks for picking this up, having an evolve command would be a really useful addition to git. I read the final four patches as I was interested to see how a user would use "git change" to track changes to a set of commits. Unfortunately because there are no tests and scant documentation there are no examples of how to do this. Looking at the patches I felt like it would have been helpful to mark them as RFC to indicate that the author is requesting feedback but does not consider them ready for merging.

I'm confused as to why the command is called "change" (which I don't find particularly descriptive) when every patch subject is "evolve". It definitely makes sense to request feedback on a large topic like this before everything is implemented but I'd be nervous of merging the early stages before there is a working evolve command. For an example of a successful multipart topic see https://lore.kernel.org/git/pull.1248.git.1654545325.gitgitgadget@gmail.com/ Knowing the author of that series the commit messages should also give you a good idea of the level of detail expected.

Best Wishes

Phillip

> Chris Poucet (4):
>    sha1-array: implement oid_array_readonly_contains
>    ref-filter: add the metas namespace to ref-filter
>    evolve: add delete command
>    evolve: add documentation for `git change`
> > Stefan Xenos (6):
>    technical doc: add a design doc for the evolve command
>    evolve: add support for parsing metacommits
>    evolve: add the change-table structure
>    evolve: add support for writing metacommits
>    evolve: implement the git change command
>    evolve: add the git change list command
> >   .gitignore                         |    1 +
>   Documentation/git-change.txt       |   55 ++
>   Documentation/technical/evolve.txt | 1051 ++++++++++++++++++++++++++++
>   Makefile                           |    4 +
>   builtin.h                          |    1 +
>   builtin/change.c                   |  342 +++++++++
>   change-table.c                     |  179 +++++
>   change-table.h                     |  132 ++++
>   git.c                              |    1 +
>   metacommit-parser.c                |  110 +++
>   metacommit-parser.h                |   19 +
>   metacommit.c                       |  404 +++++++++++
>   metacommit.h                       |   58 ++
>   oid-array.c                        |   12 +
>   oid-array.h                        |    7 +
>   ref-filter.c                       |   10 +-
>   ref-filter.h                       |    8 +-
>   t/helper/test-oid-array.c          |    6 +
>   t/t0064-oid-array.sh               |   22 +
>   19 files changed, 2418 insertions(+), 4 deletions(-)
>   create mode 100644 Documentation/git-change.txt
>   create mode 100644 Documentation/technical/evolve.txt
>   create mode 100644 builtin/change.c
>   create mode 100644 change-table.c
>   create mode 100644 change-table.h
>   create mode 100644 metacommit-parser.c
>   create mode 100644 metacommit-parser.h
>   create mode 100644 metacommit.c
>   create mode 100644 metacommit.h
> > > base-commit: 4b79ee4b0cd1130ba8907029cdc5f6a1632aca26
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1356%2Fpoucet%2Fevolve-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1356/poucet/evolve-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/1356

@gitgitgadget
Copy link

gitgitgadget bot commented Sep 25, 2022

User Phillip Wood <phillip.wood123@gmail.com> has been added to the cc: list.

@gitgitgadget
Copy link

gitgitgadget bot commented Sep 26, 2022

User Ævar Arnfjörð Bjarmason <avarab@gmail.com> has been added to the cc: list.

@gitgitgadget
Copy link

gitgitgadget bot commented Sep 26, 2022

User Chris Poucet <poucet@google.com> has been added to the cc: list.

@poucet poucet changed the title Add the Git Change command RFC: Git Evolve / Change Oct 4, 2022
@gitgitgadget
Copy link

gitgitgadget bot commented Oct 4, 2022

On the Git mailing list, Chris P wrote (reply to this):

> Thanks for picking this up, having an evolve command would be a really
> useful addition to git. I read the final four patches as I was
> interested to see how a user would use "git change" to track changes to
> a set of commits. Unfortunately because there are no tests and scant
> documentation there are no examples of how to do this. Looking at the
> patches I felt like it would have been helpful to mark them as RFC to
> indicate that the author is requesting feedback but does not consider
> them ready for merging.

Thanks for the feedback, I'll mark them as RFC.

> I'm confused as to why the command is called "change" (which I don't
> find particularly descriptive) when every patch subject is "evolve". It
> definitely makes sense to request feedback on a large topic like this
> before everything is implemented but I'd be nervous of merging the early
> stages before there is a working evolve command. For an example of a
> successful multipart topic see
> https://lore.kernel.org/git/pull.1248.git.1654545325.gitgitgadget@gmail.com/
> Knowing the author of that series the commit messages should also give
> you a good idea of the level of detail expected.

The `git change` command is a lower-level command used to directly
manipulate changes, as a user you should not be engaging with those.
What is missing is the more complicated  `git evolve` command.
I admit that I don't yet know how to implement that or the changes that
need to happen to all create/modify commands.

Still learning git, so apologies for any mistakes and thank you for your
consideration

- simply chris

On Sun, Sep 25, 2022 at 10:40 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
>
> Hi Christophe
>
> On 23/09/2022 19:55, Christophe Poucet via GitGitGadget wrote:
> > I'm reviving the original git evolve work that was started by
> > sxenos@google.com
> > (https://public-inbox.org/git/20190215043105.163688-1-sxenos@google.com/)
> >
> > This work is intended to make it easier to deal with stacked changes.
> >
> > The following set of patches introduces the design doc on the evolve command
> > as well as the basics of the git change command.
>
> Thanks for picking this up, having an evolve command would be a really
> useful addition to git. I read the final four patches as I was
> interested to see how a user would use "git change" to track changes to
> a set of commits. Unfortunately because there are no tests and scant
> documentation there are no examples of how to do this. Looking at the
> patches I felt like it would have been helpful to mark them as RFC to
> indicate that the author is requesting feedback but does not consider
> them ready for merging.
>
> I'm confused as to why the command is called "change" (which I don't
> find particularly descriptive) when every patch subject is "evolve". It
> definitely makes sense to request feedback on a large topic like this
> before everything is implemented but I'd be nervous of merging the early
> stages before there is a working evolve command. For an example of a
> successful multipart topic see
> https://lore.kernel.org/git/pull.1248.git.1654545325.gitgitgadget@gmail.com/
> Knowing the author of that series the commit messages should also give
> you a good idea of the level of detail expected.
>
> Best Wishes
>
> Phillip
>
> > Chris Poucet (4):
> >    sha1-array: implement oid_array_readonly_contains
> >    ref-filter: add the metas namespace to ref-filter
> >    evolve: add delete command
> >    evolve: add documentation for `git change`
> >
> > Stefan Xenos (6):
> >    technical doc: add a design doc for the evolve command
> >    evolve: add support for parsing metacommits
> >    evolve: add the change-table structure
> >    evolve: add support for writing metacommits
> >    evolve: implement the git change command
> >    evolve: add the git change list command
> >
> >   .gitignore                         |    1 +
> >   Documentation/git-change.txt       |   55 ++
> >   Documentation/technical/evolve.txt | 1051 ++++++++++++++++++++++++++++
> >   Makefile                           |    4 +
> >   builtin.h                          |    1 +
> >   builtin/change.c                   |  342 +++++++++
> >   change-table.c                     |  179 +++++
> >   change-table.h                     |  132 ++++
> >   git.c                              |    1 +
> >   metacommit-parser.c                |  110 +++
> >   metacommit-parser.h                |   19 +
> >   metacommit.c                       |  404 +++++++++++
> >   metacommit.h                       |   58 ++
> >   oid-array.c                        |   12 +
> >   oid-array.h                        |    7 +
> >   ref-filter.c                       |   10 +-
> >   ref-filter.h                       |    8 +-
> >   t/helper/test-oid-array.c          |    6 +
> >   t/t0064-oid-array.sh               |   22 +
> >   19 files changed, 2418 insertions(+), 4 deletions(-)
> >   create mode 100644 Documentation/git-change.txt
> >   create mode 100644 Documentation/technical/evolve.txt
> >   create mode 100644 builtin/change.c
> >   create mode 100644 change-table.c
> >   create mode 100644 change-table.h
> >   create mode 100644 metacommit-parser.c
> >   create mode 100644 metacommit-parser.h
> >   create mode 100644 metacommit.c
> >   create mode 100644 metacommit.h
> >
> >
> > base-commit: 4b79ee4b0cd1130ba8907029cdc5f6a1632aca26
> > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1356%2Fpoucet%2Fevolve-v1
> > Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1356/poucet/evolve-v1
> > Pull-Request: https://github.com/gitgitgadget/git/pull/1356

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 4, 2022

On the Git mailing list, Phillip Wood wrote (reply to this):

Hi Chris

On 23/09/2022 19:55, Christophe Poucet via GitGitGadget wrote:
> I'm reviving the original git evolve work that was started by
> sxenos@google.com
> (https://public-inbox.org/git/20190215043105.163688-1-sxenos@google.com/)
> > This work is intended to make it easier to deal with stacked changes.
> > The following set of patches introduces the design doc on the evolve command
> as well as the basics of the git change command.

Our test suite can be a little tricky to get started with and I was impatient to
check the basic functionality of these patches so I've written some simple
example tests for the change command and a couple of fixups to make them pass.

Best Wishes

Phillip

---- >8 ----

From a7c38d0f388e4d8a1f3debcc3069a7fb43084eda Mon Sep 17 00:00:00 2001
From: Phillip Wood <phillip.wood@dunelm.org.uk>
Date: Tue, 4 Oct 2022 15:12:36 +0100
Subject: [PATCH 1/3] fixup! evolve: add support for writing metacommits

---
 metacommit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/metacommit.c b/metacommit.c
index d2b859a4d3..8f970fa104 100644
--- a/metacommit.c
+++ b/metacommit.c
@@ -296,7 +296,7 @@ int record_metacommit_withresult(
        if (override_change) {
                string_list_clear(changes, 0);
                overridden_head = get_change_head(chtable, override_change);
-               if (!overridden_head) {
+               if (overridden_head) {
                        /* This is an existing change */
                        old_head = &overridden_head->head;
                        if (!force) {
-- 
2.37.3.947.g1b8ba4da7f.dirty


From cc7e8ba0b1a90268ced85d3f0c91aed49f2246d6 Mon Sep 17 00:00:00 2001
From: Phillip Wood <phillip.wood@dunelm.org.uk>
Date: Tue, 4 Oct 2022 15:15:32 +0100
Subject: [PATCH 2/3] fixup! evolve: implement the git change command

---
 t/t9999-changes.sh | 126 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 126 insertions(+)
 create mode 100755 t/t9999-changes.sh

diff --git a/t/t9999-changes.sh b/t/t9999-changes.sh
new file mode 100755
index 0000000000..9e58925b23
--- /dev/null
+++ b/t/t9999-changes.sh
@@ -0,0 +1,126 @@
+#!/bin/sh
+
+test_description='git change - low level meta-commit management'
+
+. ./test-lib.sh
+
+. "$TEST_DIRECTORY"/lib-rebase.sh
+
+test_expect_success 'setup commits and meta-commits' '
+       for c in one two three
+       do
+               test_commit $c &&
+               git change update --content $c >actual 2>err &&
+               echo "Created change metas/$c" >expect &&
+               test_cmp expect actual &&
+               test_must_be_empty err &&
+               test_cmp_rev refs/metas/$c $c || return 1
+       done
+'
+
+# Check a meta-commit has the correct parents Call with the object
+# name of the meta-commit followed by pairs of type and parent
+check_meta_commit () {
+       name=$1
+       shift
+       while test $# -gt 0
+       do
+               printf '%s %s\n' $1 $(git rev-parse --verify $2)
+               shift
+               shift
+       done | sort >expect
+       git cat-file commit $name >metacommit &&
+       # commit body should consist of parent-type
+           types="$(sed -n '/^$/ {
+                       :loop
+                       n
+                       s/^parent-type //
+                       p
+                       b loop
+                   }' metacommit)" &&
+       while read key value
+       do
+               # TODO: don't sort the first parent
+               if test "$key" = "parent"
+               then
+                       type="${types%% *}"
+                       test -n "$type" || return 1
+                       printf '%s %s\n' $type $value
+                       types="${types#?}"
+                       types="${types# }"
+               elif test "$key" = "tree"
+               then
+                       test_cmp_rev "$value" $EMPTY_TREE || return 1
+               elif test -z "$key"
+               then
+                       # only parse commit headers
+                       break
+               fi
+       done <metacommit >actual-unsorted &&
+       test -z "$types" &&
+       sort >actual <actual-unsorted &&
+       test_cmp expect actual
+}
+
+test_expect_success 'update meta-commits after rebase' '
+       (
+               set_fake_editor &&
+               FAKE_AMEND=edited &&
+               FAKE_LINES="reword 1 pick 2 fixup 3" &&
+               export FAKE_AMEND FAKE_LINES &&
+               git rebase -i --root
+       ) &&
+
+       # update meta-commits
+       git change update --replace tags/one --content HEAD~1 >out 2>err &&
+       echo "Updated change metas/one" >expect &&
+       test_cmp expect out &&
+       test_must_be_empty err &&
+       git change update --replace tags/two --content HEAD@{2} &&
+       oid=$(git rev-parse --verify metas/two) &&
+       git change update --replace HEAD@{2} --replace tags/three \
+               --content HEAD &&
+
+       # check meta-commits
+       check_meta_commit metas/one c HEAD~1 r tags/one &&
+       check_meta_commit $oid c HEAD@{2} r tags/two &&
+       # NB this checks that "git change update" uses the meta-commit ($oid)
+       #    corresponding to the replaces commit (HEAD@2 above) given on the
+       #    commandline.
+       check_meta_commit metas/two c HEAD r $oid r tags/three &&
+       check_meta_commit metas/three c HEAD r $oid r tags/three
+'
+
+reset_meta_commits () {
+    for c in one two three
+    do
+       echo "update refs/metas/$c refs/tags/$c^0"
+    done | git update-ref --stdin
+}
+
+test_expect_success 'override change name' '
+       # TODO: builtin/change.c expects --change to be the full refname,
+       #       ideally it would prepend refs/metas to the string given by the
+       #       user.
+       git change update --change refs/metas/another-one --content one &&
+       test_cmp_rev metas/another-one one
+'
+
+test_expect_success 'non-fast forward meta-commit update refused' '
+       test_must_fail git change update --change refs/metas/one --content two \
+               >out 2>err &&
+       echo "error: non-fast-forward update to ${SQ}refs/metas/one${SQ}" \
+               >expect &&
+       test_cmp expect err &&
+       test_must_be_empty out
+'
+
+test_expect_success 'forced non-fast forward update succeeds' '
+       git change update --change refs/metas/one --content two --force \
+               >out 2>err &&
+       echo "Updated change metas/one" >expect &&
+       test_cmp expect out &&
+       test_must_be_empty err
+'
+
+test_done
-- 
2.37.3.947.g1b8ba4da7f.dirty


From 7784f253fa799dd11fcbc81fe815fb387af52d97 Mon Sep 17 00:00:00 2001
From: Phillip Wood <phillip.wood@dunelm.org.uk>
Date: Tue, 4 Oct 2022 15:16:05 +0100
Subject: [PATCH 3/3] fixup! evolve: add the git change list command

---
 builtin/change.c   | 16 +++++-----------
 t/t9999-changes.sh | 11 +++++++++++
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/builtin/change.c b/builtin/change.c
index 07d029d82d..888ef648fa 100644
--- a/builtin/change.c
+++ b/builtin/change.c
@@ -34,9 +34,8 @@ static int change_list(int argc, const char **argv, const char* prefix)
                OPT_END()
        };
        struct ref_filter filter;
-       /* TODO: See below
        struct ref_sorting *sorting;
-       struct string_list sorting_options = STRING_LIST_INIT_DUP; */
+       struct string_list sorting_options = STRING_LIST_INIT_DUP;
        struct ref_format format = REF_FORMAT_INIT;
        struct ref_array array;
        int i;
@@ -53,19 +52,15 @@ static int change_list(int argc, const char **argv, const char* prefix)
          filter_refs(&array, &filter, FILTER_REFS_CHANGES);
 -       /* TODO: This causes a crash. It sets one of the atom_value handlers to
-        * something invalid, which causes a crash later when we call
-        * show_ref_array_item. Figure out why this happens and put back the sorting.
-        *
-        * sorting = ref_sorting_options(&sorting_options);
-        * ref_array_sort(sorting, &array); */
-
        if (!format.format)
                format.format = "%(refname:lstrip=1)";
          if (verify_ref_format(&format))
                die(_("unable to parse format string"));
 +       sorting = ref_sorting_options(&sorting_options);
+       ref_array_sort(sorting, &array);
+
        for (i = 0; i < array.nr; i++) {
                struct strbuf output = STRBUF_INIT;
                struct strbuf err = STRBUF_INIT;
@@ -79,8 +74,7 @@ static int change_list(int argc, const char **argv, const char* prefix)
        }
          ref_array_clear(&array);
-       /* TODO: see above
-       ref_sorting_release(sorting); */
+       ref_sorting_release(sorting);
          return 0;
 }
diff --git a/t/t9999-changes.sh b/t/t9999-changes.sh
index 9e58925b23..9312eba86d 100755
--- a/t/t9999-changes.sh
+++ b/t/t9999-changes.sh
@@ -123,4 +123,15 @@ test_expect_success 'forced non-fast forward update succeeds' '
        test_must_be_empty err
 '
 +test_expect_success 'list changes' '
+       cat >expect <<-\EOF &&
+       metas/another-one
+       metas/one
+       metas/three
+       metas/two
+       EOF
+       git change list >actual &&
+       test_cmp expect actual
+'
+
 test_done
-- 
2.37.3.947.g1b8ba4da7f.dirty

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 4, 2022

On the Git mailing list, Chris P wrote (reply to this):

Thanks a lot.

Is there something special I must do to get these scripts to work? The
entire script fails for me, despite having build git-change.

On Tue, Oct 4, 2022 at 4:24 PM Phillip Wood <phillip.wood123@gmail.com> wrote:
>
> Hi Chris
>
> On 23/09/2022 19:55, Christophe Poucet via GitGitGadget wrote:
> > I'm reviving the original git evolve work that was started by
> > sxenos@google.com
> > (https://public-inbox.org/git/20190215043105.163688-1-sxenos@google.com/)
> >
> > This work is intended to make it easier to deal with stacked changes.
> >
> > The following set of patches introduces the design doc on the evolve command
> > as well as the basics of the git change command.
>
> Our test suite can be a little tricky to get started with and I was impatient to
> check the basic functionality of these patches so I've written some simple
> example tests for the change command and a couple of fixups to make them pass.
>
> Best Wishes
>
> Phillip
>
> ---- >8 ----
>
>  From a7c38d0f388e4d8a1f3debcc3069a7fb43084eda Mon Sep 17 00:00:00 2001
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
> Date: Tue, 4 Oct 2022 15:12:36 +0100
> Subject: [PATCH 1/3] fixup! evolve: add support for writing metacommits
>
> ---
>   metacommit.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/metacommit.c b/metacommit.c
> index d2b859a4d3..8f970fa104 100644
> --- a/metacommit.c
> +++ b/metacommit.c
> @@ -296,7 +296,7 @@ int record_metacommit_withresult(
>          if (override_change) {
>                  string_list_clear(changes, 0);
>                  overridden_head = get_change_head(chtable, override_change);
> -               if (!overridden_head) {
> +               if (overridden_head) {
>                          /* This is an existing change */
>                          old_head = &overridden_head->head;
>                          if (!force) {
> --
> 2.37.3.947.g1b8ba4da7f.dirty
>
>
>  From cc7e8ba0b1a90268ced85d3f0c91aed49f2246d6 Mon Sep 17 00:00:00 2001
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
> Date: Tue, 4 Oct 2022 15:15:32 +0100
> Subject: [PATCH 2/3] fixup! evolve: implement the git change command
>
> ---
>   t/t9999-changes.sh | 126 +++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 126 insertions(+)
>   create mode 100755 t/t9999-changes.sh
>
> diff --git a/t/t9999-changes.sh b/t/t9999-changes.sh
> new file mode 100755
> index 0000000000..9e58925b23
> --- /dev/null
> +++ b/t/t9999-changes.sh
> @@ -0,0 +1,126 @@
> +#!/bin/sh
> +
> +test_description='git change - low level meta-commit management'
> +
> +. ./test-lib.sh
> +
> +. "$TEST_DIRECTORY"/lib-rebase.sh
> +
> +test_expect_success 'setup commits and meta-commits' '
> +       for c in one two three
> +       do
> +               test_commit $c &&
> +               git change update --content $c >actual 2>err &&
> +               echo "Created change metas/$c" >expect &&
> +               test_cmp expect actual &&
> +               test_must_be_empty err &&
> +               test_cmp_rev refs/metas/$c $c || return 1
> +       done
> +'
> +
> +# Check a meta-commit has the correct parents Call with the object
> +# name of the meta-commit followed by pairs of type and parent
> +check_meta_commit () {
> +       name=$1
> +       shift
> +       while test $# -gt 0
> +       do
> +               printf '%s %s\n' $1 $(git rev-parse --verify $2)
> +               shift
> +               shift
> +       done | sort >expect
> +       git cat-file commit $name >metacommit &&
> +       # commit body should consist of parent-type
> +           types="$(sed -n '/^$/ {
> +                       :loop
> +                       n
> +                       s/^parent-type //
> +                       p
> +                       b loop
> +                   }' metacommit)" &&
> +       while read key value
> +       do
> +               # TODO: don't sort the first parent
> +               if test "$key" = "parent"
> +               then
> +                       type="${types%% *}"
> +                       test -n "$type" || return 1
> +                       printf '%s %s\n' $type $value
> +                       types="${types#?}"
> +                       types="${types# }"
> +               elif test "$key" = "tree"
> +               then
> +                       test_cmp_rev "$value" $EMPTY_TREE || return 1
> +               elif test -z "$key"
> +               then
> +                       # only parse commit headers
> +                       break
> +               fi
> +       done <metacommit >actual-unsorted &&
> +       test -z "$types" &&
> +       sort >actual <actual-unsorted &&
> +       test_cmp expect actual
> +}
> +
> +test_expect_success 'update meta-commits after rebase' '
> +       (
> +               set_fake_editor &&
> +               FAKE_AMEND=edited &&
> +               FAKE_LINES="reword 1 pick 2 fixup 3" &&
> +               export FAKE_AMEND FAKE_LINES &&
> +               git rebase -i --root
> +       ) &&
> +
> +       # update meta-commits
> +       git change update --replace tags/one --content HEAD~1 >out 2>err &&
> +       echo "Updated change metas/one" >expect &&
> +       test_cmp expect out &&
> +       test_must_be_empty err &&
> +       git change update --replace tags/two --content HEAD@{2} &&
> +       oid=$(git rev-parse --verify metas/two) &&
> +       git change update --replace HEAD@{2} --replace tags/three \
> +               --content HEAD &&
> +
> +       # check meta-commits
> +       check_meta_commit metas/one c HEAD~1 r tags/one &&
> +       check_meta_commit $oid c HEAD@{2} r tags/two &&
> +       # NB this checks that "git change update" uses the meta-commit ($oid)
> +       #    corresponding to the replaces commit (HEAD@2 above) given on the
> +       #    commandline.
> +       check_meta_commit metas/two c HEAD r $oid r tags/three &&
> +       check_meta_commit metas/three c HEAD r $oid r tags/three
> +'
> +
> +reset_meta_commits () {
> +    for c in one two three
> +    do
> +       echo "update refs/metas/$c refs/tags/$c^0"
> +    done | git update-ref --stdin
> +}
> +
> +test_expect_success 'override change name' '
> +       # TODO: builtin/change.c expects --change to be the full refname,
> +       #       ideally it would prepend refs/metas to the string given by the
> +       #       user.
> +       git change update --change refs/metas/another-one --content one &&
> +       test_cmp_rev metas/another-one one
> +'
> +
> +test_expect_success 'non-fast forward meta-commit update refused' '
> +       test_must_fail git change update --change refs/metas/one --content two \
> +               >out 2>err &&
> +       echo "error: non-fast-forward update to ${SQ}refs/metas/one${SQ}" \
> +               >expect &&
> +       test_cmp expect err &&
> +       test_must_be_empty out
> +'
> +
> +test_expect_success 'forced non-fast forward update succeeds' '
> +       git change update --change refs/metas/one --content two --force \
> +               >out 2>err &&
> +       echo "Updated change metas/one" >expect &&
> +       test_cmp expect out &&
> +       test_must_be_empty err
> +'
> +
> +test_done
> --
> 2.37.3.947.g1b8ba4da7f.dirty
>
>
>  From 7784f253fa799dd11fcbc81fe815fb387af52d97 Mon Sep 17 00:00:00 2001
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
> Date: Tue, 4 Oct 2022 15:16:05 +0100
> Subject: [PATCH 3/3] fixup! evolve: add the git change list command
>
> ---
>   builtin/change.c   | 16 +++++-----------
>   t/t9999-changes.sh | 11 +++++++++++
>   2 files changed, 16 insertions(+), 11 deletions(-)
>
> diff --git a/builtin/change.c b/builtin/change.c
> index 07d029d82d..888ef648fa 100644
> --- a/builtin/change.c
> +++ b/builtin/change.c
> @@ -34,9 +34,8 @@ static int change_list(int argc, const char **argv, const char* prefix)
>                  OPT_END()
>          };
>          struct ref_filter filter;
> -       /* TODO: See below
>          struct ref_sorting *sorting;
> -       struct string_list sorting_options = STRING_LIST_INIT_DUP; */
> +       struct string_list sorting_options = STRING_LIST_INIT_DUP;
>          struct ref_format format = REF_FORMAT_INIT;
>          struct ref_array array;
>          int i;
> @@ -53,19 +52,15 @@ static int change_list(int argc, const char **argv, const char* prefix)
>
>          filter_refs(&array, &filter, FILTER_REFS_CHANGES);
>
> -       /* TODO: This causes a crash. It sets one of the atom_value handlers to
> -        * something invalid, which causes a crash later when we call
> -        * show_ref_array_item. Figure out why this happens and put back the sorting.
> -        *
> -        * sorting = ref_sorting_options(&sorting_options);
> -        * ref_array_sort(sorting, &array); */
> -
>          if (!format.format)
>                  format.format = "%(refname:lstrip=1)";
>
>          if (verify_ref_format(&format))
>                  die(_("unable to parse format string"));
>
> +       sorting = ref_sorting_options(&sorting_options);
> +       ref_array_sort(sorting, &array);
> +
>          for (i = 0; i < array.nr; i++) {
>                  struct strbuf output = STRBUF_INIT;
>                  struct strbuf err = STRBUF_INIT;
> @@ -79,8 +74,7 @@ static int change_list(int argc, const char **argv, const char* prefix)
>          }
>
>          ref_array_clear(&array);
> -       /* TODO: see above
> -       ref_sorting_release(sorting); */
> +       ref_sorting_release(sorting);
>
>          return 0;
>   }
> diff --git a/t/t9999-changes.sh b/t/t9999-changes.sh
> index 9e58925b23..9312eba86d 100755
> --- a/t/t9999-changes.sh
> +++ b/t/t9999-changes.sh
> @@ -123,4 +123,15 @@ test_expect_success 'forced non-fast forward update succeeds' '
>          test_must_be_empty err
>   '
>
> +test_expect_success 'list changes' '
> +       cat >expect <<-\EOF &&
> +       metas/another-one
> +       metas/one
> +       metas/three
> +       metas/two
> +       EOF
> +       git change list >actual &&
> +       test_cmp expect actual
> +'
> +
>   test_done
> --
> 2.37.3.947.g1b8ba4da7f.dirty

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 4, 2022

On the Git mailing list, Chris P wrote (reply to this):

I got the tests to work, except the last one, that one fails.

How can I see the output of actual and expect?

On Tue, Oct 4, 2022 at 5:19 PM Chris P <christophe.poucet@gmail.com> wrote:
>
> Thanks a lot.
>
> Is there something special I must do to get these scripts to work? The
> entire script fails for me, despite having build git-change.
>
> On Tue, Oct 4, 2022 at 4:24 PM Phillip Wood <phillip.wood123@gmail.com> wrote:
> >
> > Hi Chris
> >
> > On 23/09/2022 19:55, Christophe Poucet via GitGitGadget wrote:
> > > I'm reviving the original git evolve work that was started by
> > > sxenos@google.com
> > > (https://public-inbox.org/git/20190215043105.163688-1-sxenos@google.com/)
> > >
> > > This work is intended to make it easier to deal with stacked changes.
> > >
> > > The following set of patches introduces the design doc on the evolve command
> > > as well as the basics of the git change command.
> >
> > Our test suite can be a little tricky to get started with and I was impatient to
> > check the basic functionality of these patches so I've written some simple
> > example tests for the change command and a couple of fixups to make them pass.
> >
> > Best Wishes
> >
> > Phillip
> >
> > ---- >8 ----
> >
> >  From a7c38d0f388e4d8a1f3debcc3069a7fb43084eda Mon Sep 17 00:00:00 2001
> > From: Phillip Wood <phillip.wood@dunelm.org.uk>
> > Date: Tue, 4 Oct 2022 15:12:36 +0100
> > Subject: [PATCH 1/3] fixup! evolve: add support for writing metacommits
> >
> > ---
> >   metacommit.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/metacommit.c b/metacommit.c
> > index d2b859a4d3..8f970fa104 100644
> > --- a/metacommit.c
> > +++ b/metacommit.c
> > @@ -296,7 +296,7 @@ int record_metacommit_withresult(
> >          if (override_change) {
> >                  string_list_clear(changes, 0);
> >                  overridden_head = get_change_head(chtable, override_change);
> > -               if (!overridden_head) {
> > +               if (overridden_head) {
> >                          /* This is an existing change */
> >                          old_head = &overridden_head->head;
> >                          if (!force) {
> > --
> > 2.37.3.947.g1b8ba4da7f.dirty
> >
> >
> >  From cc7e8ba0b1a90268ced85d3f0c91aed49f2246d6 Mon Sep 17 00:00:00 2001
> > From: Phillip Wood <phillip.wood@dunelm.org.uk>
> > Date: Tue, 4 Oct 2022 15:15:32 +0100
> > Subject: [PATCH 2/3] fixup! evolve: implement the git change command
> >
> > ---
> >   t/t9999-changes.sh | 126 +++++++++++++++++++++++++++++++++++++++++++++
> >   1 file changed, 126 insertions(+)
> >   create mode 100755 t/t9999-changes.sh
> >
> > diff --git a/t/t9999-changes.sh b/t/t9999-changes.sh
> > new file mode 100755
> > index 0000000000..9e58925b23
> > --- /dev/null
> > +++ b/t/t9999-changes.sh
> > @@ -0,0 +1,126 @@
> > +#!/bin/sh
> > +
> > +test_description='git change - low level meta-commit management'
> > +
> > +. ./test-lib.sh
> > +
> > +. "$TEST_DIRECTORY"/lib-rebase.sh
> > +
> > +test_expect_success 'setup commits and meta-commits' '
> > +       for c in one two three
> > +       do
> > +               test_commit $c &&
> > +               git change update --content $c >actual 2>err &&
> > +               echo "Created change metas/$c" >expect &&
> > +               test_cmp expect actual &&
> > +               test_must_be_empty err &&
> > +               test_cmp_rev refs/metas/$c $c || return 1
> > +       done
> > +'
> > +
> > +# Check a meta-commit has the correct parents Call with the object
> > +# name of the meta-commit followed by pairs of type and parent
> > +check_meta_commit () {
> > +       name=$1
> > +       shift
> > +       while test $# -gt 0
> > +       do
> > +               printf '%s %s\n' $1 $(git rev-parse --verify $2)
> > +               shift
> > +               shift
> > +       done | sort >expect
> > +       git cat-file commit $name >metacommit &&
> > +       # commit body should consist of parent-type
> > +           types="$(sed -n '/^$/ {
> > +                       :loop
> > +                       n
> > +                       s/^parent-type //
> > +                       p
> > +                       b loop
> > +                   }' metacommit)" &&
> > +       while read key value
> > +       do
> > +               # TODO: don't sort the first parent
> > +               if test "$key" = "parent"
> > +               then
> > +                       type="${types%% *}"
> > +                       test -n "$type" || return 1
> > +                       printf '%s %s\n' $type $value
> > +                       types="${types#?}"
> > +                       types="${types# }"
> > +               elif test "$key" = "tree"
> > +               then
> > +                       test_cmp_rev "$value" $EMPTY_TREE || return 1
> > +               elif test -z "$key"
> > +               then
> > +                       # only parse commit headers
> > +                       break
> > +               fi
> > +       done <metacommit >actual-unsorted &&
> > +       test -z "$types" &&
> > +       sort >actual <actual-unsorted &&
> > +       test_cmp expect actual
> > +}
> > +
> > +test_expect_success 'update meta-commits after rebase' '
> > +       (
> > +               set_fake_editor &&
> > +               FAKE_AMEND=edited &&
> > +               FAKE_LINES="reword 1 pick 2 fixup 3" &&
> > +               export FAKE_AMEND FAKE_LINES &&
> > +               git rebase -i --root
> > +       ) &&
> > +
> > +       # update meta-commits
> > +       git change update --replace tags/one --content HEAD~1 >out 2>err &&
> > +       echo "Updated change metas/one" >expect &&
> > +       test_cmp expect out &&
> > +       test_must_be_empty err &&
> > +       git change update --replace tags/two --content HEAD@{2} &&
> > +       oid=$(git rev-parse --verify metas/two) &&
> > +       git change update --replace HEAD@{2} --replace tags/three \
> > +               --content HEAD &&
> > +
> > +       # check meta-commits
> > +       check_meta_commit metas/one c HEAD~1 r tags/one &&
> > +       check_meta_commit $oid c HEAD@{2} r tags/two &&
> > +       # NB this checks that "git change update" uses the meta-commit ($oid)
> > +       #    corresponding to the replaces commit (HEAD@2 above) given on the
> > +       #    commandline.
> > +       check_meta_commit metas/two c HEAD r $oid r tags/three &&
> > +       check_meta_commit metas/three c HEAD r $oid r tags/three
> > +'
> > +
> > +reset_meta_commits () {
> > +    for c in one two three
> > +    do
> > +       echo "update refs/metas/$c refs/tags/$c^0"
> > +    done | git update-ref --stdin
> > +}
> > +
> > +test_expect_success 'override change name' '
> > +       # TODO: builtin/change.c expects --change to be the full refname,
> > +       #       ideally it would prepend refs/metas to the string given by the
> > +       #       user.
> > +       git change update --change refs/metas/another-one --content one &&
> > +       test_cmp_rev metas/another-one one
> > +'
> > +
> > +test_expect_success 'non-fast forward meta-commit update refused' '
> > +       test_must_fail git change update --change refs/metas/one --content two \
> > +               >out 2>err &&
> > +       echo "error: non-fast-forward update to ${SQ}refs/metas/one${SQ}" \
> > +               >expect &&
> > +       test_cmp expect err &&
> > +       test_must_be_empty out
> > +'
> > +
> > +test_expect_success 'forced non-fast forward update succeeds' '
> > +       git change update --change refs/metas/one --content two --force \
> > +               >out 2>err &&
> > +       echo "Updated change metas/one" >expect &&
> > +       test_cmp expect out &&
> > +       test_must_be_empty err
> > +'
> > +
> > +test_done
> > --
> > 2.37.3.947.g1b8ba4da7f.dirty
> >
> >
> >  From 7784f253fa799dd11fcbc81fe815fb387af52d97 Mon Sep 17 00:00:00 2001
> > From: Phillip Wood <phillip.wood@dunelm.org.uk>
> > Date: Tue, 4 Oct 2022 15:16:05 +0100
> > Subject: [PATCH 3/3] fixup! evolve: add the git change list command
> >
> > ---
> >   builtin/change.c   | 16 +++++-----------
> >   t/t9999-changes.sh | 11 +++++++++++
> >   2 files changed, 16 insertions(+), 11 deletions(-)
> >
> > diff --git a/builtin/change.c b/builtin/change.c
> > index 07d029d82d..888ef648fa 100644
> > --- a/builtin/change.c
> > +++ b/builtin/change.c
> > @@ -34,9 +34,8 @@ static int change_list(int argc, const char **argv, const char* prefix)
> >                  OPT_END()
> >          };
> >          struct ref_filter filter;
> > -       /* TODO: See below
> >          struct ref_sorting *sorting;
> > -       struct string_list sorting_options = STRING_LIST_INIT_DUP; */
> > +       struct string_list sorting_options = STRING_LIST_INIT_DUP;
> >          struct ref_format format = REF_FORMAT_INIT;
> >          struct ref_array array;
> >          int i;
> > @@ -53,19 +52,15 @@ static int change_list(int argc, const char **argv, const char* prefix)
> >
> >          filter_refs(&array, &filter, FILTER_REFS_CHANGES);
> >
> > -       /* TODO: This causes a crash. It sets one of the atom_value handlers to
> > -        * something invalid, which causes a crash later when we call
> > -        * show_ref_array_item. Figure out why this happens and put back the sorting.
> > -        *
> > -        * sorting = ref_sorting_options(&sorting_options);
> > -        * ref_array_sort(sorting, &array); */
> > -
> >          if (!format.format)
> >                  format.format = "%(refname:lstrip=1)";
> >
> >          if (verify_ref_format(&format))
> >                  die(_("unable to parse format string"));
> >
> > +       sorting = ref_sorting_options(&sorting_options);
> > +       ref_array_sort(sorting, &array);
> > +
> >          for (i = 0; i < array.nr; i++) {
> >                  struct strbuf output = STRBUF_INIT;
> >                  struct strbuf err = STRBUF_INIT;
> > @@ -79,8 +74,7 @@ static int change_list(int argc, const char **argv, const char* prefix)
> >          }
> >
> >          ref_array_clear(&array);
> > -       /* TODO: see above
> > -       ref_sorting_release(sorting); */
> > +       ref_sorting_release(sorting);
> >
> >          return 0;
> >   }
> > diff --git a/t/t9999-changes.sh b/t/t9999-changes.sh
> > index 9e58925b23..9312eba86d 100755
> > --- a/t/t9999-changes.sh
> > +++ b/t/t9999-changes.sh
> > @@ -123,4 +123,15 @@ test_expect_success 'forced non-fast forward update succeeds' '
> >          test_must_be_empty err
> >   '
> >
> > +test_expect_success 'list changes' '
> > +       cat >expect <<-\EOF &&
> > +       metas/another-one
> > +       metas/one
> > +       metas/three
> > +       metas/two
> > +       EOF
> > +       git change list >actual &&
> > +       test_cmp expect actual
> > +'
> > +
> >   test_done
> > --
> > 2.37.3.947.g1b8ba4da7f.dirty

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 4, 2022

On the Git mailing list, Phillip Wood wrote (reply to this):

On 04/10/2022 16:19, Chris P wrote:
> Thanks a lot.
> > Is there something special I must do to get these scripts to work? The
> entire script fails for me, despite having build git-change.

If you do

make
cd t
./t9999-changes.sh -v -i [--root=/dev/shm]

it should run. You need to change into the t directory before running our tests and if you've just run "make git" before then it wont have created the scripts in bin-wrappers that the tests use. Are you able to run any of the other tests successfully?

Phillip

> On Tue, Oct 4, 2022 at 4:24 PM Phillip Wood <phillip.wood123@gmail.com> wrote:
>>
>> Hi Chris
>>
>> On 23/09/2022 19:55, Christophe Poucet via GitGitGadget wrote:
>>> I'm reviving the original git evolve work that was started by
>>> sxenos@google.com
>>> (https://public-inbox.org/git/20190215043105.163688-1-sxenos@google.com/)
>>>
>>> This work is intended to make it easier to deal with stacked changes.
>>>
>>> The following set of patches introduces the design doc on the evolve command
>>> as well as the basics of the git change command.
>>
>> Our test suite can be a little tricky to get started with and I was impatient to
>> check the basic functionality of these patches so I've written some simple
>> example tests for the change command and a couple of fixups to make them pass.
>>
>> Best Wishes
>>
>> Phillip
>>
>> ---- >8 ----
>>
>>   From a7c38d0f388e4d8a1f3debcc3069a7fb43084eda Mon Sep 17 00:00:00 2001
>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>> Date: Tue, 4 Oct 2022 15:12:36 +0100
>> Subject: [PATCH 1/3] fixup! evolve: add support for writing metacommits
>>
>> ---
>>    metacommit.c | 2 +-
>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/metacommit.c b/metacommit.c
>> index d2b859a4d3..8f970fa104 100644
>> --- a/metacommit.c
>> +++ b/metacommit.c
>> @@ -296,7 +296,7 @@ int record_metacommit_withresult(
>>           if (override_change) {
>>                   string_list_clear(changes, 0);
>>                   overridden_head = get_change_head(chtable, override_change);
>> -               if (!overridden_head) {
>> +               if (overridden_head) {
>>                           /* This is an existing change */
>>                           old_head = &overridden_head->head;
>>                           if (!force) {
>> --
>> 2.37.3.947.g1b8ba4da7f.dirty
>>
>>
>>   From cc7e8ba0b1a90268ced85d3f0c91aed49f2246d6 Mon Sep 17 00:00:00 2001
>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>> Date: Tue, 4 Oct 2022 15:15:32 +0100
>> Subject: [PATCH 2/3] fixup! evolve: implement the git change command
>>
>> ---
>>    t/t9999-changes.sh | 126 +++++++++++++++++++++++++++++++++++++++++++++
>>    1 file changed, 126 insertions(+)
>>    create mode 100755 t/t9999-changes.sh
>>
>> diff --git a/t/t9999-changes.sh b/t/t9999-changes.sh
>> new file mode 100755
>> index 0000000000..9e58925b23
>> --- /dev/null
>> +++ b/t/t9999-changes.sh
>> @@ -0,0 +1,126 @@
>> +#!/bin/sh
>> +
>> +test_description='git change - low level meta-commit management'
>> +
>> +. ./test-lib.sh
>> +
>> +. "$TEST_DIRECTORY"/lib-rebase.sh
>> +
>> +test_expect_success 'setup commits and meta-commits' '
>> +       for c in one two three
>> +       do
>> +               test_commit $c &&
>> +               git change update --content $c >actual 2>err &&
>> +               echo "Created change metas/$c" >expect &&
>> +               test_cmp expect actual &&
>> +               test_must_be_empty err &&
>> +               test_cmp_rev refs/metas/$c $c || return 1
>> +       done
>> +'
>> +
>> +# Check a meta-commit has the correct parents Call with the object
>> +# name of the meta-commit followed by pairs of type and parent
>> +check_meta_commit () {
>> +       name=$1
>> +       shift
>> +       while test $# -gt 0
>> +       do
>> +               printf '%s %s\n' $1 $(git rev-parse --verify $2)
>> +               shift
>> +               shift
>> +       done | sort >expect
>> +       git cat-file commit $name >metacommit &&
>> +       # commit body should consist of parent-type
>> +           types="$(sed -n '/^$/ {
>> +                       :loop
>> +                       n
>> +                       s/^parent-type //
>> +                       p
>> +                       b loop
>> +                   }' metacommit)" &&
>> +       while read key value
>> +       do
>> +               # TODO: don't sort the first parent
>> +               if test "$key" = "parent"
>> +               then
>> +                       type="${types%% *}"
>> +                       test -n "$type" || return 1
>> +                       printf '%s %s\n' $type $value
>> +                       types="${types#?}"
>> +                       types="${types# }"
>> +               elif test "$key" = "tree"
>> +               then
>> +                       test_cmp_rev "$value" $EMPTY_TREE || return 1
>> +               elif test -z "$key"
>> +               then
>> +                       # only parse commit headers
>> +                       break
>> +               fi
>> +       done <metacommit >actual-unsorted &&
>> +       test -z "$types" &&
>> +       sort >actual <actual-unsorted &&
>> +       test_cmp expect actual
>> +}
>> +
>> +test_expect_success 'update meta-commits after rebase' '
>> +       (
>> +               set_fake_editor &&
>> +               FAKE_AMEND=edited &&
>> +               FAKE_LINES="reword 1 pick 2 fixup 3" &&
>> +               export FAKE_AMEND FAKE_LINES &&
>> +               git rebase -i --root
>> +       ) &&
>> +
>> +       # update meta-commits
>> +       git change update --replace tags/one --content HEAD~1 >out 2>err &&
>> +       echo "Updated change metas/one" >expect &&
>> +       test_cmp expect out &&
>> +       test_must_be_empty err &&
>> +       git change update --replace tags/two --content HEAD@{2} &&
>> +       oid=$(git rev-parse --verify metas/two) &&
>> +       git change update --replace HEAD@{2} --replace tags/three \
>> +               --content HEAD &&
>> +
>> +       # check meta-commits
>> +       check_meta_commit metas/one c HEAD~1 r tags/one &&
>> +       check_meta_commit $oid c HEAD@{2} r tags/two &&
>> +       # NB this checks that "git change update" uses the meta-commit ($oid)
>> +       #    corresponding to the replaces commit (HEAD@2 above) given on the
>> +       #    commandline.
>> +       check_meta_commit metas/two c HEAD r $oid r tags/three &&
>> +       check_meta_commit metas/three c HEAD r $oid r tags/three
>> +'
>> +
>> +reset_meta_commits () {
>> +    for c in one two three
>> +    do
>> +       echo "update refs/metas/$c refs/tags/$c^0"
>> +    done | git update-ref --stdin
>> +}
>> +
>> +test_expect_success 'override change name' '
>> +       # TODO: builtin/change.c expects --change to be the full refname,
>> +       #       ideally it would prepend refs/metas to the string given by the
>> +       #       user.
>> +       git change update --change refs/metas/another-one --content one &&
>> +       test_cmp_rev metas/another-one one
>> +'
>> +
>> +test_expect_success 'non-fast forward meta-commit update refused' '
>> +       test_must_fail git change update --change refs/metas/one --content two \
>> +               >out 2>err &&
>> +       echo "error: non-fast-forward update to ${SQ}refs/metas/one${SQ}" \
>> +               >expect &&
>> +       test_cmp expect err &&
>> +       test_must_be_empty out
>> +'
>> +
>> +test_expect_success 'forced non-fast forward update succeeds' '
>> +       git change update --change refs/metas/one --content two --force \
>> +               >out 2>err &&
>> +       echo "Updated change metas/one" >expect &&
>> +       test_cmp expect out &&
>> +       test_must_be_empty err
>> +'
>> +
>> +test_done
>> --
>> 2.37.3.947.g1b8ba4da7f.dirty
>>
>>
>>   From 7784f253fa799dd11fcbc81fe815fb387af52d97 Mon Sep 17 00:00:00 2001
>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>> Date: Tue, 4 Oct 2022 15:16:05 +0100
>> Subject: [PATCH 3/3] fixup! evolve: add the git change list command
>>
>> ---
>>    builtin/change.c   | 16 +++++-----------
>>    t/t9999-changes.sh | 11 +++++++++++
>>    2 files changed, 16 insertions(+), 11 deletions(-)
>>
>> diff --git a/builtin/change.c b/builtin/change.c
>> index 07d029d82d..888ef648fa 100644
>> --- a/builtin/change.c
>> +++ b/builtin/change.c
>> @@ -34,9 +34,8 @@ static int change_list(int argc, const char **argv, const char* prefix)
>>                   OPT_END()
>>           };
>>           struct ref_filter filter;
>> -       /* TODO: See below
>>           struct ref_sorting *sorting;
>> -       struct string_list sorting_options = STRING_LIST_INIT_DUP; */
>> +       struct string_list sorting_options = STRING_LIST_INIT_DUP;
>>           struct ref_format format = REF_FORMAT_INIT;
>>           struct ref_array array;
>>           int i;
>> @@ -53,19 +52,15 @@ static int change_list(int argc, const char **argv, const char* prefix)
>>
>>           filter_refs(&array, &filter, FILTER_REFS_CHANGES);
>>
>> -       /* TODO: This causes a crash. It sets one of the atom_value handlers to
>> -        * something invalid, which causes a crash later when we call
>> -        * show_ref_array_item. Figure out why this happens and put back the sorting.
>> -        *
>> -        * sorting = ref_sorting_options(&sorting_options);
>> -        * ref_array_sort(sorting, &array); */
>> -
>>           if (!format.format)
>>                   format.format = "%(refname:lstrip=1)";
>>
>>           if (verify_ref_format(&format))
>>                   die(_("unable to parse format string"));
>>
>> +       sorting = ref_sorting_options(&sorting_options);
>> +       ref_array_sort(sorting, &array);
>> +
>>           for (i = 0; i < array.nr; i++) {
>>                   struct strbuf output = STRBUF_INIT;
>>                   struct strbuf err = STRBUF_INIT;
>> @@ -79,8 +74,7 @@ static int change_list(int argc, const char **argv, const char* prefix)
>>           }
>>
>>           ref_array_clear(&array);
>> -       /* TODO: see above
>> -       ref_sorting_release(sorting); */
>> +       ref_sorting_release(sorting);
>>
>>           return 0;
>>    }
>> diff --git a/t/t9999-changes.sh b/t/t9999-changes.sh
>> index 9e58925b23..9312eba86d 100755
>> --- a/t/t9999-changes.sh
>> +++ b/t/t9999-changes.sh
>> @@ -123,4 +123,15 @@ test_expect_success 'forced non-fast forward update succeeds' '
>>           test_must_be_empty err
>>    '
>>
>> +test_expect_success 'list changes' '
>> +       cat >expect <<-\EOF &&
>> +       metas/another-one
>> +       metas/one
>> +       metas/three
>> +       metas/two
>> +       EOF
>> +       git change list >actual &&
>> +       test_cmp expect actual
>> +'
>> +
>>    test_done
>> --
>> 2.37.3.947.g1b8ba4da7f.dirty

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 4, 2022

On the Git mailing list, Phillip Wood wrote (reply to this):

On 04/10/2022 16:55, Chris P wrote:
> I got the tests to work, except the last one, that one fails.
> > How can I see the output of actual and expect?

If you run the test with -i then it will stop at the first failure and you can inspect the files in the directory 'trash directory.t9999-changes'. Running with -v (verbose) -x (shell tracing) is also useful when debugging.

Phillip

> On Tue, Oct 4, 2022 at 5:19 PM Chris P <christophe.poucet@gmail.com> wrote:
>>
>> Thanks a lot.
>>
>> Is there something special I must do to get these scripts to work? The
>> entire script fails for me, despite having build git-change.
>>
>> On Tue, Oct 4, 2022 at 4:24 PM Phillip Wood <phillip.wood123@gmail.com> wrote:
>>>
>>> Hi Chris
>>>
>>> On 23/09/2022 19:55, Christophe Poucet via GitGitGadget wrote:
>>>> I'm reviving the original git evolve work that was started by
>>>> sxenos@google.com
>>>> (https://public-inbox.org/git/20190215043105.163688-1-sxenos@google.com/)
>>>>
>>>> This work is intended to make it easier to deal with stacked changes.
>>>>
>>>> The following set of patches introduces the design doc on the evolve command
>>>> as well as the basics of the git change command.
>>>
>>> Our test suite can be a little tricky to get started with and I was impatient to
>>> check the basic functionality of these patches so I've written some simple
>>> example tests for the change command and a couple of fixups to make them pass.
>>>
>>> Best Wishes
>>>
>>> Phillip
>>>
>>> ---- >8 ----
>>>
>>>   From a7c38d0f388e4d8a1f3debcc3069a7fb43084eda Mon Sep 17 00:00:00 2001
>>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>> Date: Tue, 4 Oct 2022 15:12:36 +0100
>>> Subject: [PATCH 1/3] fixup! evolve: add support for writing metacommits
>>>
>>> ---
>>>    metacommit.c | 2 +-
>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/metacommit.c b/metacommit.c
>>> index d2b859a4d3..8f970fa104 100644
>>> --- a/metacommit.c
>>> +++ b/metacommit.c
>>> @@ -296,7 +296,7 @@ int record_metacommit_withresult(
>>>           if (override_change) {
>>>                   string_list_clear(changes, 0);
>>>                   overridden_head = get_change_head(chtable, override_change);
>>> -               if (!overridden_head) {
>>> +               if (overridden_head) {
>>>                           /* This is an existing change */
>>>                           old_head = &overridden_head->head;
>>>                           if (!force) {
>>> --
>>> 2.37.3.947.g1b8ba4da7f.dirty
>>>
>>>
>>>   From cc7e8ba0b1a90268ced85d3f0c91aed49f2246d6 Mon Sep 17 00:00:00 2001
>>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>> Date: Tue, 4 Oct 2022 15:15:32 +0100
>>> Subject: [PATCH 2/3] fixup! evolve: implement the git change command
>>>
>>> ---
>>>    t/t9999-changes.sh | 126 +++++++++++++++++++++++++++++++++++++++++++++
>>>    1 file changed, 126 insertions(+)
>>>    create mode 100755 t/t9999-changes.sh
>>>
>>> diff --git a/t/t9999-changes.sh b/t/t9999-changes.sh
>>> new file mode 100755
>>> index 0000000000..9e58925b23
>>> --- /dev/null
>>> +++ b/t/t9999-changes.sh
>>> @@ -0,0 +1,126 @@
>>> +#!/bin/sh
>>> +
>>> +test_description='git change - low level meta-commit management'
>>> +
>>> +. ./test-lib.sh
>>> +
>>> +. "$TEST_DIRECTORY"/lib-rebase.sh
>>> +
>>> +test_expect_success 'setup commits and meta-commits' '
>>> +       for c in one two three
>>> +       do
>>> +               test_commit $c &&
>>> +               git change update --content $c >actual 2>err &&
>>> +               echo "Created change metas/$c" >expect &&
>>> +               test_cmp expect actual &&
>>> +               test_must_be_empty err &&
>>> +               test_cmp_rev refs/metas/$c $c || return 1
>>> +       done
>>> +'
>>> +
>>> +# Check a meta-commit has the correct parents Call with the object
>>> +# name of the meta-commit followed by pairs of type and parent
>>> +check_meta_commit () {
>>> +       name=$1
>>> +       shift
>>> +       while test $# -gt 0
>>> +       do
>>> +               printf '%s %s\n' $1 $(git rev-parse --verify $2)
>>> +               shift
>>> +               shift
>>> +       done | sort >expect
>>> +       git cat-file commit $name >metacommit &&
>>> +       # commit body should consist of parent-type
>>> +           types="$(sed -n '/^$/ {
>>> +                       :loop
>>> +                       n
>>> +                       s/^parent-type //
>>> +                       p
>>> +                       b loop
>>> +                   }' metacommit)" &&
>>> +       while read key value
>>> +       do
>>> +               # TODO: don't sort the first parent
>>> +               if test "$key" = "parent"
>>> +               then
>>> +                       type="${types%% *}"
>>> +                       test -n "$type" || return 1
>>> +                       printf '%s %s\n' $type $value
>>> +                       types="${types#?}"
>>> +                       types="${types# }"
>>> +               elif test "$key" = "tree"
>>> +               then
>>> +                       test_cmp_rev "$value" $EMPTY_TREE || return 1
>>> +               elif test -z "$key"
>>> +               then
>>> +                       # only parse commit headers
>>> +                       break
>>> +               fi
>>> +       done <metacommit >actual-unsorted &&
>>> +       test -z "$types" &&
>>> +       sort >actual <actual-unsorted &&
>>> +       test_cmp expect actual
>>> +}
>>> +
>>> +test_expect_success 'update meta-commits after rebase' '
>>> +       (
>>> +               set_fake_editor &&
>>> +               FAKE_AMEND=edited &&
>>> +               FAKE_LINES="reword 1 pick 2 fixup 3" &&
>>> +               export FAKE_AMEND FAKE_LINES &&
>>> +               git rebase -i --root
>>> +       ) &&
>>> +
>>> +       # update meta-commits
>>> +       git change update --replace tags/one --content HEAD~1 >out 2>err &&
>>> +       echo "Updated change metas/one" >expect &&
>>> +       test_cmp expect out &&
>>> +       test_must_be_empty err &&
>>> +       git change update --replace tags/two --content HEAD@{2} &&
>>> +       oid=$(git rev-parse --verify metas/two) &&
>>> +       git change update --replace HEAD@{2} --replace tags/three \
>>> +               --content HEAD &&
>>> +
>>> +       # check meta-commits
>>> +       check_meta_commit metas/one c HEAD~1 r tags/one &&
>>> +       check_meta_commit $oid c HEAD@{2} r tags/two &&
>>> +       # NB this checks that "git change update" uses the meta-commit ($oid)
>>> +       #    corresponding to the replaces commit (HEAD@2 above) given on the
>>> +       #    commandline.
>>> +       check_meta_commit metas/two c HEAD r $oid r tags/three &&
>>> +       check_meta_commit metas/three c HEAD r $oid r tags/three
>>> +'
>>> +
>>> +reset_meta_commits () {
>>> +    for c in one two three
>>> +    do
>>> +       echo "update refs/metas/$c refs/tags/$c^0"
>>> +    done | git update-ref --stdin
>>> +}
>>> +
>>> +test_expect_success 'override change name' '
>>> +       # TODO: builtin/change.c expects --change to be the full refname,
>>> +       #       ideally it would prepend refs/metas to the string given by the
>>> +       #       user.
>>> +       git change update --change refs/metas/another-one --content one &&
>>> +       test_cmp_rev metas/another-one one
>>> +'
>>> +
>>> +test_expect_success 'non-fast forward meta-commit update refused' '
>>> +       test_must_fail git change update --change refs/metas/one --content two \
>>> +               >out 2>err &&
>>> +       echo "error: non-fast-forward update to ${SQ}refs/metas/one${SQ}" \
>>> +               >expect &&
>>> +       test_cmp expect err &&
>>> +       test_must_be_empty out
>>> +'
>>> +
>>> +test_expect_success 'forced non-fast forward update succeeds' '
>>> +       git change update --change refs/metas/one --content two --force \
>>> +               >out 2>err &&
>>> +       echo "Updated change metas/one" >expect &&
>>> +       test_cmp expect out &&
>>> +       test_must_be_empty err
>>> +'
>>> +
>>> +test_done
>>> --
>>> 2.37.3.947.g1b8ba4da7f.dirty
>>>
>>>
>>>   From 7784f253fa799dd11fcbc81fe815fb387af52d97 Mon Sep 17 00:00:00 2001
>>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>> Date: Tue, 4 Oct 2022 15:16:05 +0100
>>> Subject: [PATCH 3/3] fixup! evolve: add the git change list command
>>>
>>> ---
>>>    builtin/change.c   | 16 +++++-----------
>>>    t/t9999-changes.sh | 11 +++++++++++
>>>    2 files changed, 16 insertions(+), 11 deletions(-)
>>>
>>> diff --git a/builtin/change.c b/builtin/change.c
>>> index 07d029d82d..888ef648fa 100644
>>> --- a/builtin/change.c
>>> +++ b/builtin/change.c
>>> @@ -34,9 +34,8 @@ static int change_list(int argc, const char **argv, const char* prefix)
>>>                   OPT_END()
>>>           };
>>>           struct ref_filter filter;
>>> -       /* TODO: See below
>>>           struct ref_sorting *sorting;
>>> -       struct string_list sorting_options = STRING_LIST_INIT_DUP; */
>>> +       struct string_list sorting_options = STRING_LIST_INIT_DUP;
>>>           struct ref_format format = REF_FORMAT_INIT;
>>>           struct ref_array array;
>>>           int i;
>>> @@ -53,19 +52,15 @@ static int change_list(int argc, const char **argv, const char* prefix)
>>>
>>>           filter_refs(&array, &filter, FILTER_REFS_CHANGES);
>>>
>>> -       /* TODO: This causes a crash. It sets one of the atom_value handlers to
>>> -        * something invalid, which causes a crash later when we call
>>> -        * show_ref_array_item. Figure out why this happens and put back the sorting.
>>> -        *
>>> -        * sorting = ref_sorting_options(&sorting_options);
>>> -        * ref_array_sort(sorting, &array); */
>>> -
>>>           if (!format.format)
>>>                   format.format = "%(refname:lstrip=1)";
>>>
>>>           if (verify_ref_format(&format))
>>>                   die(_("unable to parse format string"));
>>>
>>> +       sorting = ref_sorting_options(&sorting_options);
>>> +       ref_array_sort(sorting, &array);
>>> +
>>>           for (i = 0; i < array.nr; i++) {
>>>                   struct strbuf output = STRBUF_INIT;
>>>                   struct strbuf err = STRBUF_INIT;
>>> @@ -79,8 +74,7 @@ static int change_list(int argc, const char **argv, const char* prefix)
>>>           }
>>>
>>>           ref_array_clear(&array);
>>> -       /* TODO: see above
>>> -       ref_sorting_release(sorting); */
>>> +       ref_sorting_release(sorting);
>>>
>>>           return 0;
>>>    }
>>> diff --git a/t/t9999-changes.sh b/t/t9999-changes.sh
>>> index 9e58925b23..9312eba86d 100755
>>> --- a/t/t9999-changes.sh
>>> +++ b/t/t9999-changes.sh
>>> @@ -123,4 +123,15 @@ test_expect_success 'forced non-fast forward update succeeds' '
>>>           test_must_be_empty err
>>>    '
>>>
>>> +test_expect_success 'list changes' '
>>> +       cat >expect <<-\EOF &&
>>> +       metas/another-one
>>> +       metas/one
>>> +       metas/three
>>> +       metas/two
>>> +       EOF
>>> +       git change list >actual &&
>>> +       test_cmp expect actual
>>> +'
>>> +
>>>    test_done
>>> --
>>> 2.37.3.947.g1b8ba4da7f.dirty

@poucet
Copy link
Author

poucet commented Oct 5, 2022

/submit

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 5, 2022

Submitted as pull.1356.v2.git.1664981957.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-1356/poucet/evolve-v2

To fetch this version to local tag pr-1356/poucet/evolve-v2:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-1356/poucet/evolve-v2

@@ -0,0 +1,1070 @@
Evolve
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Chris Poucet wrote (reply to this):

One thing that is not clear to me is whether this is the desired
direction. I took at look at the git review notes but it was hard to
get a sense of where people are at.

Would love input on the design.


On Wed, Oct 5, 2022 at 4:59 PM Stefan Xenos via GitGitGadget
<gitgitgadget@gmail.com> wrote:
>
> From: Stefan Xenos <sxenos@google.com>
>
> This document describes what a change graph for
> git would look like, the behavior of the evolve command,
> and the changes planned for other commands.
>
> It was originally proposed in 2018, see
> https://public-inbox.org/git/20181115005546.212538-1-sxenos@google.com/
>
> Signed-off-by: Stefan Xenos <sxenos@google.com>
> Signed-off-by: Chris Poucet <poucet@google.com>
> ---
>  Documentation/technical/evolve.txt | 1070 ++++++++++++++++++++++++++++
>  1 file changed, 1070 insertions(+)
>  create mode 100644 Documentation/technical/evolve.txt
>
> diff --git a/Documentation/technical/evolve.txt b/Documentation/technical/evolve.txt
> new file mode 100644
> index 00000000000..2051ea77b8a
> --- /dev/null
> +++ b/Documentation/technical/evolve.txt
> @@ -0,0 +1,1070 @@
> +Evolve
> +======
> +
> +Objective
> +=========
> +Create an "evolve" command to help users craft a high quality commit history.
> +Users can improve commits one at a time and in any order, then run git evolve to
> +rewrite their recent history to ensure everything is up-to-date. We track
> +amendments to a commit over time in a change graph. Users can share their
> +progress with others by exchanging their change graphs using the standard push,
> +fetch, and format-patch commands.
> +
> +Status
> +======
> +This proposal has not been implemented yet.
> +
> +Background
> +==========
> +Imagine you have three sequential changes up for review and you receive feedback
> +that requires editing all three changes. We'll define the word "change"
> +formally later, but for the moment let's say that a change is a work-in-progress
> +whose final version will be submitted as a commit in the future.
> +
> +While you're editing one change, more feedback arrives on one of the others.
> +What do you do?
> +
> +The evolve command is a convenient way to work with chains of commits that are
> +under review. Whenever you rebase or amend a commit, the repository remembers
> +that the old commit is obsolete and has been replaced by the new one. Then, at
> +some point in the future, you can run "git evolve" and the correct sequence of
> +rebases will occur in the correct order such that no commit has an obsolete
> +parent.
> +
> +Part of making the "evolve" command work involves tracking the edits to a commit
> +over time, which is why we need an change graph. However, the change
> +graph will also bring other benefits:
> +
> +- Users can view the history of a change directly (the sequence of amends and
> +  rebases it has undergone, orthogonal to the history of the branch it is on).
> +- It will be possible to quickly locate and list all the changes the user
> +  currently has in progress.
> +- It can be used as part of other high-level commands that combine or split
> +  changes.
> +- It can be used to decorate commits (in git log, gitk, etc) that are either
> +  obsolete or are the tip of a work in progress.
> +- By pushing and pulling the change graph, users can collaborate more
> +  easily on changes-in-progress. This is better than pushing and pulling the
> +  commits themselves since the change graph can be used to locate a more
> +  specific merge base, allowing for better merges between different versions of
> +  the same change.
> +- It could be used to correctly rebase local changes and other local branches
> +  after running git-filter-branch.
> +- It can replace the change-id footer used by gerrit.
> +
> +Goals
> +-----
> +Legend: Goals marked with P0 are required. Goals marked with Pn should be
> +attempted unless they interfere with goals marked with Pn-1.
> +
> +P0. All commands that modify commits (such as the normal commit --amend or
> +    rebase command) should mark the old commit as being obsolete and replaced by
> +    the new one. No additional commands should be required to keep the
> +    change graph up-to-date.
> +P0. Any commit that may be involved in a future evolve command should not be
> +    garbage collected. Specifically:
> +    - Commits that obsolete another should not be garbage collected until
> +      user-specified conditions have occurred and the change has expired from
> +      the reflog. User specified conditions for removing changes include:
> +      - The user explicitly deleted the change.
> +      - The change was merged into a specific branch.
> +    - Commits that have been obsoleted by another should not be garbage
> +      collected if any of their replacements are still being retained.
> +P0. A commit can be obsoleted by more than one replacement (called divergence).
> +P0. Users must be able to resolve divergence (convergence).
> +P1. Users should be able to share chains of obsolete changes in order to
> +    collaborate on WIP changes.
> +P2. Such sharing should be at the user’s option. That is, it should be possible
> +    to directly share a change without also sharing the file states or commit
> +    comments from the obsolete changes that led up to it, and the choice not to
> +    share those commits should not require changing any commit hashes.
> +P2. It should be possible to discard part or all of the change graph
> +    without discarding the commits themselves that are already present in
> +    branches and the reflog.
> +P2. Provide sufficient information to replace gerrit's Change-Id footers.
> +
> +Similar technologies
> +--------------------
> +There are some other technologies that address the same end-user problem.
> +
> +Rebase -i can be used to solve the same problem, but users can't easily switch
> +tasks midway through an interactive rebase or have more than one interactive
> +rebase going on at the same time. It can't handle the case where you have
> +multiple changes sharing the same parent when that parent needs to be rebased
> +and won't let you collaborate with others on resolving a complicated interactive
> +rebase. You can think of rebase -i as a top-down approach and the evolve command
> +as the bottom-up approach to the same problem.
> +
> +Revup amend (https://github.com/Skydio/revup/blob/main/docs/amend.md)
> +allows insertion of cached changes into any commit in
> +the current history, and then reapplies the rest of history on top of
> +those changes. It uses a "git apply --cached" engine under the hood so
> +doesn't touch the working directory (although it will soon use the new
> +git merge-tree). When paired with "revup upload" which creates and
> +pushes multiple branches in the background for you, its possible to
> +work on a "graph" of changes on a single branch linearly, then have
> +the true graph structure created at upload time.
> +
> +git-revise (https://github.com/mystor/git-revise) does some very
> +similar things except it uses "git merge-file" combined with manually
> +merging the resulting trees. git branchstack
> +(https://github.com/krobelus/git-branchstack) can also create branches
> +in the background with the same mechanism.
> +
> +These tools don't store any external state, but as such also don't
> +provide any specific collaboration mechanism for individual changes.
> +
> +Several patch queue managers have been built on top of git (such as topgit,
> +stgit, and quilt). They address the same user need. However they also rely on
> +state managed outside git that needs to be kept in sync. Such state can be
> +easily damaged when running a git native command that is unaware of the patch
> +queue. They also typically require an explicit initialization step to be done by
> +the user which creates workflow problems.
> +
> +Mercurial implements a very similar feature in its EvolveExtension. The behavior
> +of the evolve command itself is very similar, but the storage format for the
> +change graph differs. In the case of mercurial, each change set can have one or
> +more obsolescence markers that point to other changesets that they replace. This
> +is similar to the "Commit Headers" approach considered in the other options
> +appendix. The approach proposed here stores obsolescence information in a
> +separate metacommit graph, which makes exchanging of obsolescence information
> +optional.
> +
> +Mercurial's default behavior makes it easy to find and switch between
> +non-obsolete changesets that aren't currently on any branch. We introduce the
> +notion of a new ref namespace that enables a similar workflow via a different
> +mechanism. Mercurial has the notion of changeset phases which isn't present
> +in git and creates new ways for a changeset to diverge. Git doesn't need
> +to deal with these issues, but it has to deal with the problems of picking an
> +upstream branch as a target for rebases and protecting obsolescence information
> +from GC. We also introduce some additional transformations (see
> +obsolescence-over-cherry-pick, below) that aren't present in the mercurial
> +implementation.
> +
> +Semi-related work
> +-----------------
> +There are other technologies that address different problems but have some
> +similarities with this proposal.
> +
> +Replacements (refs/replace) are superficially similar to obsolescences in that
> +they describe that one commit should be replaced by another. However, they
> +differ in both how they are created and how they are intended to be used.
> +Obsolescences are created automatically by the commands a user runs, and they
> +describe the user’s intent to perform a future rebase. Obsolete commits still
> +appear in branches, logs, etc like normal commits (possibly with an extra
> +decoration that marks them as obsolete). Replacements are typically created
> +explicitly by the user, they are meant to be kept around for a long time, and
> +they describe a replacement to be applied at read-time rather than as the input
> +to a future operation. When a replaced commit is queried, it is typically hidden
> +and swapped out with its replacement as though the replacement has already
> +occurred.
> +
> +Git-imerge is a project to help make complicated merges easier, particularly
> +when merging or rebasing long chains of patches. It is not an alternative to
> +the change graph, but its algorithm of applying smaller incremental merges
> +could be used as part of the evolve algorithm in the future.
> +
> +Overview
> +========
> +We introduce the notion of “meta-commits” which describe how one commit was
> +created from other commits. A branch of meta-commits is known as a change.
> +Changes are created and updated automatically whenever a user runs a command
> +that creates a commit. They are used for locating obsolete commits, providing a
> +list of a user’s unsubmitted work in progress, and providing a stable name for
> +each unsubmitted change.
> +
> +Users can exchange edit histories by pushing and fetching changes.
> +
> +New commands will be introduced for manipulating changes and resolving
> +divergence between them. Existing commands that create commits will be updated
> +to modify the meta-commit graph and create changes where necessary.
> +
> +Example usage
> +-------------
> +# First create three dependent changes
> +$ echo foo>bar.txt && git add .
> +$ git commit -m "This is a test"
> +created change metas/this_is_a_test
> +$ echo foo2>bar2.txt && git add .
> +$ git commit -m "This is also a test"
> +created change metas/this_is_also_a_test
> +$ echo foo3>bar3.txt && git add .
> +$ git commit -m "More testing"
> +created change metas/more_testing
> +
> +# List all our changes in progress
> +$ git change list
> +metas/this_is_a_test
> +metas/this_is_also_a_test
> +* metas/more_testing
> +metas/some_change_already_merged_upstream
> +
> +# Now modify the earliest change, using its stable name
> +$ git reset --hard metas/this_is_a_test
> +$ echo morefoo>>bar.txt && git add . && git commit --amend --no-edit
> +
> +# Use git-evolve to fix up any dependent changes
> +$ git evolve
> +rebasing metas/this_is_also_a_test onto metas/this_is_a_test
> +rebasing metas/more_testing onto metas/this_is_also_a_test
> +Done
> +
> +# Use git-obslog to view the history of the this_is_a_test change
> +$ git log --obslog
> +93f110 metas/this_is_a_test@{0} commit (amend): This is a test
> +930219 metas/this_is_a_test@{1} commit: This is a test
> +
> +# Now create an unrelated change
> +$ git reset --hard origin/master
> +$ echo newchange>unrelated.txt && git add .
> +$ git commit -m "Unrelated change"
> +created change metas/unrelated_change
> +
> +# Fetch the latest code from origin/master and use git-evolve
> +# to rebase all dependent changes.
> +$ git fetch origin master
> +$ git evolve origin/master
> +deleting metas/some_change_already_merged_upstream
> +rebasing metas/this_is_a_test onto origin/master
> +rebasing metas/this_is_also_a_test onto metas/this_is_a_test
> +rebasing metas/more_testing onto metas/this_is_also_a_test
> +rebasing metas/unrelated_change onto origin/master
> +Conflict detected! Resolve it and then use git evolve --continue to resume.
> +
> +# Sort out the conflict
> +$ git mergetool
> +$ git evolve origin/master
> +Done
> +
> +# Share the full history of edits for the this_is_a_test change
> +# with a review server
> +$ git push origin metas/this_is_a_test:refs/for/master
> +# Share the lastest commit for “Unrelated change”, without history
> +$ git push origin HEAD:refs/for/master
> +
> +Detailed design
> +===============
> +Obsolescence information is stored as a graph of meta-commits. A meta-commit is
> +a specially-formatted merge commit that describes how one commit was created
> +from others.
> +
> +Meta-commits look like this:
> +
> +$ git cat-file -p <example_meta_commit>
> +tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904
> +parent aa7ce55545bf2c14bef48db91af1a74e2347539a
> +parent d64309ee51d0af12723b6cb027fc9f195b15a5e9
> +parent 7e1bbcd3a0fa854a7a9eac9bf1eea6465de98136
> +author Stefan Xenos <sxenos@gmail.com> 1540841596 -0700
> +committer Stefan Xenos <sxenos@gmail.com> 1540841596 -0700
> +parent-type c r o
> +
> +This says “commit aa7ce555 makes commit d64309ee obsolete. It was created by
> +cherry-picking commit 7e1bbcd3”.
> +
> +The tree for meta-commits is always the empty tree, but future versions of git
> +may attach other trees here. For forward-compatibility fsck should ignore such
> +trees if found on future repository versions. This will allow future versions of
> +git to add metadata to the meta-commit tree without breaking forwards
> +compatibility.
> +
> +The commit comment for a meta-commit is an auto-generated user-readable string
> +describing the command that produced the meta commit. These strings are shown
> +to the user when they view the obslog.
> +
> +Parent-type
> +-----------
> +The “parent-type” field in the commit header identifies a commit as a
> +meta-commit and indicates the meaning for each of its parents. It is never
> +present for normal commits. It contains a space-deliminated list of enum values
> +whose order matches the order of the parents. Possible parent types are:
> +
> +- c: (content) the content parent identifies the commit that this meta-commit is
> +  describing.
> +- r: (replaced) indicates that this parent is made obsolete by the content
> +  parent.
> +- o: (origin) indicates that the content parent was generated by cherry-picking
> +  this parent.
> +- a: (abandoned) used in place of a content parent for abandoned changes. Points
> +  to the final content commit for the change at the time it was abandoned.
> +
> +There must be exactly one content or abandoned parent for each meta-commit and
> +it is always the first parent. The content commit will always be a normal commit
> +and not a meta-commit. However, future versions of git may create meta-commits
> +for other meta-commits and the fsck tool must be aware of this for forwards
> +compatibility.
> +
> +A meta-commit can have zero or more replaced parents. An amend operation creates
> +a single replaced parent. A merge used to resolve divergence (see divergence,
> +below) will create multiple replaced parents. A meta-commit may have no
> +replaced parents if it describes a cherry-pick or squash merge that copies one
> +or more commits but does not replace them.
> +
> +A meta-commit can have zero or more origin parents. A cherry-pick creates a
> +single origin parent. Certain types of squash merge will create multiple origin
> +parents. Origin parents don't directly cause their origin to become obsolete,
> +but are used when computing blame or locating a merge base. The section
> +on obsolescence over cherry-picks describes how the evolve command uses
> +origin parents.
> +
> +A replaced parent or origin parent may be either a normal commit (indicating
> +the oldest-known version of a change) or another meta-commit (for a change that
> +has already been modified one or more times).
> +
> +The parent-type field needs to go after the committer field since git's rules
> +for forwards-compatibility require that new fields to be at the end of the
> +header. Putting a new field in the middle of the header would break fsck.
> +
> +The presence of an abandoned parent indicates that the change should be pruned
> +by the evolve command, and removed from the repository's history. Any follow-up
> +changes should rebased onto the parent of the pruned commit. The abandoned
> +parent points to the version of the change that should be restored if the user
> +attempts to restore the change.
> +
> +Changes
> +-------
> +A branch of meta-commits describes how a commit was produced and what previous
> +commits it is based on. It is also an identifier for a thing the user is
> +currently working on. We refer to such a meta-branch as a change.
> +
> +Local changes are stored in the new refs/metas namespace. Remote changes are
> +stored in the refs/remote/<remotename>/metas namespace.
> +
> +The list of changes in refs/metas is more than just a mechanism for the evolve
> +command to locate obsolete commits. It is also a convenient list of all of a
> +user’s work in progress and their current state - a list of things they’re
> +likely to want to come back to.
> +
> +Strictly speaking, it is the presence of the branch in the refs/metas namespace
> +that marks a branch as being a change, not the fact that it points to a
> +metacommit. Metacommits are only created when a commit is amended or rebased, so
> +in the case where a change points to a commit that has never been modified, the
> +change points to that initial commit rather than a metacommit.
> +
> +Changes are also stored in the refs/hiddenmetas namespace. Hiddenmetas holds
> +metadata for historical changes that are not currently in progress by the user.
> +Commands like filter-branch and other bulk import commands create metadata in
> +this namespace.
> +
> +Note that the changes in hiddenmetas get special treatment in several ways:
> +
> +- They are not cleaned up automatically once merged, since it is expected that
> +  they refer to historical changes.
> +- User commands that modify changes don't append to these changes as they would
> +  to a change in refs/metas.
> +- They are not displayed when the user lists their local changes.
> +
> +Obsolescence
> +------------
> +A commit is considered obsolete if it is reachable from the “replaces” edges
> +anywhere in the history of a change and it isn’t the head of that change.
> +Commits may be the content for 0 or more meta-commits. If the same commit
> +appears in multiple changes, it is not obsolete if it is the head of any of
> +those changes.
> +
> +Note that there is an exception to this rule. The metas namespace takes
> +precedence over the hiddenmetas namespace for the purpose of obsolescence. That
> +is, if a change appears in a replaces edge of a change in the metas namespace,
> +it is obsolete even if it also appears as the head of a change in the
> +hiddenmetas namespace.
> +
> +This special case prevents the hiddenmetas namespace from creating divergence
> +with the user's work in progress, and allows the user to resolve historical
> +divergence by creating new changes in the metas namespace.
> +
> +Divergence
> +----------
> +From the user’s perspective, two changes are divergent if they both ask for
> +different replacements to the same commit. More precisely, a target commit is
> +considered divergent if there is more than one commit at the head of a change in
> +refs/metas that leads to the target commit via an unbroken chain of “replaces”
> +parents.
> +
> +Much like a merge conflict, divergence is a situation that requires user
> +intervention to resolve. The evolve command will stop when it encounters
> +divergence and prompt the user to resolve the problem. Users can solve the
> +problem in several ways:
> +
> +- Discard one of the changes (by deleting its change branch).
> +- Merge the two changes (producing a single change branch).
> +- Copy one of the changes (keep both commits, but one of them gets a new
> +  metacommit appended to its history that is connected to its predecessor via an
> +  origin edge rather than a replaces edge. That new change no longer obsoletes
> +  the original.)
> +
> +Obsolescence across cherry-picks
> +--------------------------------
> +By default the evolve command will treat cherry-picks and squash merges as being
> +completely separate from the original. Further amendments to the original commit
> +will have no effect on the cherry-picked copy. However, this behavior may not be
> +desirable in all circumstances.
> +
> +The evolve command may at some point support an option to look for cases where
> +the source of a cherry-pick or squash merge has itself been amended, and
> +automatically apply that same change to the cherry-picked copy. In such cases,
> +it would traverse origin edges rather than ignoring them, and would treat a
> +commit with origin edges as being obsolete if any of its origins were obsolete.
> +
> +Garbage collection
> +------------------
> +For GC purposes, meta-commits are normal commits. Just as a commit causes its
> +parents and tree to be retained, a meta-commit also causes its parents to be
> +retained.
> +
> +Change creation
> +---------------
> +Changes are created automatically whenever the user runs a command like “commit”
> +that has the semantics of creating a new change. They also move forward
> +automatically even if they’re not checked out. For example, whenever the user
> +runs a command like “commit --amend” that modifies a commit, all branches in
> +refs/metas that pointed to the old commit move forward to point to its
> +replacement instead. This also happens when the user is working from a detached
> +head.
> +
> +This does not mean that every commit has a corresponding change. By default,
> +changes only exist for recent locally-created commits. Users may explicitly pull
> +changes from other users or keep their changes around for a long time, but
> +either behavior requires a user to opt-in. Code review systems like gerrit may
> +also choose to keep changes around forever.
> +
> +Note that the changes in refs/metas serve a dual function as both a way to
> +identify obsolete changes and as a way for the user to keep track of their work
> +in progress. If we were only concerned with identifying obsolete changes, it
> +would be sufficient to create the change branch lazily the first time a commit
> +is obsoleted. Addressing the second use - of refs/metas as a mechanism for
> +keeping track of work in progress - is the reason for eagerly creating the
> +change on first commit.
> +
> +Change naming
> +-------------
> +When a change is first created, the only requirement for its name is that it
> +must be unique. Good names would also serve as useful mnemonics and be easy to
> +type. For example, a short word from the commit message containing no numbers or
> +special characters and that shows up with low frequency in other commit messages
> +would make a good choice.
> +
> +Different users may prefer different heuristics for their change names. For this
> +reason a new hook will be introduced to compute change names. Git will invoke
> +the hook for all newly-created changes and will append a numeric suffix if the
> +name isn’t unique. The default heuristics are not specified by this proposal and
> +may change during implementation.
> +
> +Change deletion
> +---------------
> +Changes are normally only interesting to a user while a commit is still in
> +development and under review. Once the commit has submitted wherever it is
> +going, its change can be discarded.
> +
> +The normal way of deleting changes makes this easy to do - changes are deleted
> +by the evolve command when it detects that the change is present in an upstream
> +branch. It does this in two ways: if the latest commit in a change either shows
> +up in the branch history or the change becomes empty after a rebase, it is
> +considered merged and the change is discarded. In this context, an “upstream
> +branch” is any branch passed in as the upstream argument of the evolve command.
> +
> +In case this sometimes deletes a useful change, such automatic deletions are
> +recorded in the reflog allowing them to be easily recovered.
> +
> +Sharing changes
> +---------------
> +Change histories are shared by pushing or fetching meta-commits and change
> +branches. This provides users with a lot of control of what to share and
> +repository implementations with control over what to retain.
> +
> +Users that only want to share the content of a commit can do so by pushing the
> +commit itself as they currently would. Users that want to share an edit history
> +for the commit can push its change, which would point to a meta-commit rather
> +than the commit itself if there is any history to share. Note that multiple
> +changes can refer to the same commits, so it’s possible to construct and push a
> +different history for the same commit in order to remove sensitive or irrelevant
> +intermediate states.
> +
> +Imagine the user is working on a change “mychange” that is currently the latest
> +commit on master. They have two ways to share it:
> +
> +# User shares just a commit without its history
> +> git push origin master
> +
> +# User shares the full history of the commit to a review system
> +> git push origin metas/mychange:refs/for/master
> +
> +# User fetches a collaborator’s modifications to their change
> +> git fetch remotename metas/mychange
> +# Which updates the ref remote/remotename/metas/mychange
> +
> +This will cause more intermediate states to be shared with the server than would
> +have been shared previously. A review system like gerrit would need to keep
> +track of which states had been explicitly pushed versus other intermediate
> +states in order to de-emphasize (or hide) the extra intermediate states from the
> +user interface.
> +
> +Merge-base
> +----------
> +Merge-base will be changed to search the meta-commit graph for common ancestors
> +as well as the commit graph, and will generally prefer results from the
> +meta-commit graph over the commit graph. Merge-base will consider meta-commits
> +from all changes, and will traverse both origin and obsolete edges.
> +
> +The reason for this is that - when merging two versions of the same commit
> +together - an earlier version of that same commit will usually be much more
> +similar than their common parent. This should make the workflow of collaborating
> +on unsubmitted patches as convenient as the workflow for collaborating in a
> +topic branch by eliminating repeated merges.
> +
> +Configuration
> +-------------
> +The core.enableChanges configuration variable enables the creation and update
> +of change branches. This is enabled by default.
> +
> +User interface
> +--------------
> +All git porcelain commands that create commits are classified as having one of
> +four behaviors: modify, create, copy, or import. These behaviors are discussed
> +in more detail below.
> +
> +Modify commands
> +---------------
> +Modification commands (commit --amend, rebase) will mark the old commit as
> +obsolete by creating a new meta-commit that references the old one as a
> +replaced parent. In the event that multiple changes point to the same commit,
> +this is done independently for every such change.
> +
> +More specifically, modifications work like this:
> +
> +1. Locate all existing changes for which the old commit is the content for the
> +   head of the change branch. If no such branch exists, create one that points
> +   to the old commit. Changes that include this commit in their history but not
> +   at their head are explicitly not included.
> +2. For every such change, create a new meta-commit that references the new
> +   commit as its content and references the old head of the change as a
> +   replaced parent.
> +3. Move the change branch forward to point to the new meta-commit.
> +
> +Copy commands
> +-------------
> +Copy commands (cherry-pick, merge --squash) create a new meta-commit that
> +references the old commits as origin parents. Besides the fact that the new
> +parents are tagged differently, copy commands work the same way as modify
> +commands.
> +
> +Create commands
> +---------------
> +Creation commands (commit, merge) create a new commit and a new change that
> +points to that commit. The do not create any meta-commits.
> +
> +Import commands
> +---------------
> +Import commands (fetch, pull) do not create any new meta-commits or changes
> +unless that is specifically what they are importing. For example, the fetch
> +command would update remote/origin/metas/change35 and fetch all referenced
> +meta-commits if asked to do so directly, but it wouldn’t create any changes or
> +meta-commits for commits discovered on the master branch when running “git fetch
> +origin master”.
> +
> +Other commands
> +--------------
> +Some commands don’t fit cleanly into one of the above categories.
> +
> +Semantically, filter-branch should be treated as a modify command, but doing so
> +is likely to create a lot of irrelevant clutter in the changes namespace and the
> +large number of extra change refs may introduce performance problems. We
> +recommend treating filter-branch as an import command initially, but making it
> +behave more like a modify command in future follow-up work. One possible
> +solution may be to treat commits that are part of existing changes as being
> +modified but to avoid creating changes for other rewritten changes. Another
> +solution may be to record the modifications as changes in the hiddenmetas
> +namespace.
> +
> +Once the evolve command can handle obsolescence across cherry-picks, such
> +cherry-picks will result in a hybrid move-and-copy operation. It will create
> +cherry-picks that replace other cherry-picks, which will have both origin edges
> +(pointing to the new source commit being picked) and replacement edges (pointing
> +to the previous cherry-pick being replaced).
> +
> +Evolve
> +------
> +The evolve command performs the correct sequence of rebases such that no change
> +has an obsolete parent. The syntax looks like this:
> +
> +git evolve [upstream…]
> +
> +It takes an optional list of upstream branches. All changes whose parent shows
> +up in the history of one of the upstream branches will be rebased onto the
> +upstream branch before resolving obsolete parents.
> +
> +Any change whose latest state is found in an upstream branch (or that ends up
> +empty after rebase) will be deleted. This is the normal mechanism for deleting
> +changes. Changes are created automatically on the first commit, and are deleted
> +automatically when evolve determines that they’ve been merged upstream.
> +
> +Orphan commits are commits with obsolete parents. The evolve command then
> +repeatedly rebases orphan commits with non-orphan parents until there are either
> +no orphan commits left, or a merge conflict is discovered. It will also
> +terminate if it detects a divergent parent or a cycle that can't be resolved
> +using any of the enabled transformations.
> +
> +When evolve discovers divergence, it will first check if it can resolve the
> +divergence automatically using one of its enabled transformations. Supported
> +transformations are:
> +
> +- Check if the user has already merged the divergent changes in a follow-up
> +  change. That is, look for an existing merge in a follow-up change where all
> +  the parents are divergent versions of the same change. Squash that merge with
> +  its parents and use the result as the resolution for the divergence.
> +
> +- Attempt to auto-merge all the divergent changes (disabled by default).
> +
> +Each of the transformations can be enabled or disabled by command line options.
> +
> +Cycles can occur when two changes reference one another as parents. This can
> +happen when both changes use an obsolete version of the other change as their
> +parent. Although there are never cycles in the commit graph, users can create
> +cycles in the change graph by rebasing changes onto obsolete commits. The evolve
> +command has a transformation that will detect and break cycles by arbitrarily
> +picking one of the changes to go first. If this generates a merge conflict,
> +it tries each of the other changes in sequence to see if any ordering merges
> +cleanly. If no possible ordering merges cleanly, it picks one and terminates
> +to let the user resolve the merge conflict.
> +
> +If the working tree is dirty, evolve will attempt to stash the user's changes
> +before applying the evolve and then reapply those changes afterward, in much
> +the same way as rebase --autostash does.
> +
> +Checkout
> +--------
> +Running checkout on a change by name has the same effect as checking out a
> +detached head pointing to the latest commit on that change-branch. There is no
> +need to ever have HEAD point to a change since changes always move forward when
> +necessary, no matter what branch the user has checked out
> +
> +Meta-commits themselves cannot be checked out by their hash.
> +
> +Reset
> +-----
> +Resetting a branch to a change by name is the same as resetting to the content
> +(or abandoned) commit at that change’s head.
> +
> +Commit
> +------
> +Commit --amend gets modify semantics and will move existing changes forward. The
> +normal form of commit gets create semantics and will create a new change.
> +
> +$ touch foo && git add . && git commit -m "foo" && git tag A
> +$ touch bar && git add . && git commit -m "bar" && git tag B
> +$ touch baz && git add . && git commit -m "baz" && git tag C
> +
> +This produces the following commits:
> +A(tree=[foo])
> +B(tree=[foo, bar], parent=A)
> +C(tree=[foo, bar, baz], parent=B)
> +
> +...along with three changes:
> +metas/foo = A
> +metas/bar = B
> +metas/baz = C
> +
> +Running commit --amend does the following:
> +$ git checkout B
> +$ touch zoom && git add . && git commit --amend -m "baz and zoom"
> +$ git tag D
> +
> +Commits:
> +A(tree=[foo])
> +B(tree=[foo, bar], parent=A)
> +C(tree=[foo, bar, baz], parent=B)
> +D(tree=[foo, bar, zoom], parent=A)
> +Dmeta(content=D, obsolete=B)
> +
> +Changes:
> +metas/foo = A
> +metas/bar = Dmeta
> +metas/baz = C
> +
> +Merge
> +-----
> +Merge gets create, modify, or copy semantics based on what is being merged and
> +the options being used.
> +
> +The --squash version of merge gets copy semantics (it produces a new change that
> +is marked as a copy of all the original changes that were squashed into it).
> +
> +The “modify” version of merge replaces both of the original commits with the
> +resulting merge commit. This is one of the standard mechanisms for resolving
> +divergence. The parents of the merge commit are the parents of the two commits
> +being merged. The resulting commit will not be a merge commit if both of the
> +original commits had the same parent or if one was the parent of the other.
> +
> +The “create” version of merge creates a new change pointing to a merge commit
> +that has both original commits as parents. The result is what merge produces now
> +- a new merge commit. However, this version of merge doesn’t directly resolve
> +divergence.
> +
> +To select between these two behaviors, merge gets new “--amend” and “--noamend”
> +options which select between the “create” and “modify” behaviors respectively,
> +with noamend being the default.
> +
> +For example, imagine we created two divergent changes like this:
> +
> +$ touch foo && git add . && git commit -m "foo" && git tag A
> +$ touch bar && git add . && git commit -m "bar" && git tag B
> +$ touch baz && git add . && git commit --amend -m "bar and baz"
> +$ git tag C
> +$ git checkout B
> +$ touch bam && git add . && git commit --amend -m "bar and bam"
> +$ git tag D
> +
> +At this point the commit graph looks like this:
> +
> +A(tree=[foo])
> +B(tree=[bar], parent=A)
> +C(tree=[bar, baz], parent=A)
> +D(tree=[bar, bam], parent=A)
> +Cmeta(content=C, obsoletes=B)
> +Dmeta(content=D, obsoletes=B)
> +
> +There would be three active changes with heads pointing as follows:
> +
> +metas/changeA=A
> +metas/changeB=Cmeta
> +metas/changeB2=Dmeta
> +
> +ChangeB and changeB2 are divergent at this point. Lets consider what happens if
> +perform each type of merge between changeB and changeB2.
> +
> +Merge example: Amend merge
> +One way to resolve divergent changes is to use an amend merge. Recall that HEAD
> +is currently pointing to D at this point.
> +
> +$ git merge --amend metas/changeB
> +
> +Here we’ve asked for an amend merge since we’re trying to resolve divergence
> +between two versions of the same change. There are no conflicts so we end up
> +with this:
> +
> +E(tree=[bar, baz, bam], parent=A)
> +Emeta(content=E, obsoletes=[Cmeta, Dmeta])
> +
> +With the following branches:
> +
> +metas/changeA=A
> +metas/changeB=Emeta
> +metas/changeB2=Emeta
> +
> +Notice that the result of the “amend merge” is a replacement for C and D rather
> +than a new commit with C and D as parents (as a normal merge would have
> +produced). The parents of the amend merge are the parents of C and D which - in
> +this case - is just A, so the result is not a merge commit. Also notice that
> +changeB and changeB2 are now aliases for the same change.
> +
> +Merge example: Noamend merge
> +Consider what would have happened if we’d used a noamend merge instead. Recall
> +that HEAD was at D and our branches looked like this:
> +
> +metas/changeA=A
> +metas/changeB=Cmeta
> +metas/changeB2=Dmeta
> +
> +$ git merge --noamend metas/changeB
> +
> +That would produce the sort of merge we’d normally expect today:
> +
> +F(tree=[bar, baz, bam], parent=[C, D])
> +
> +And our changes would look like this:
> +metas/changeA=A
> +metas/changeB=Cmeta
> +metas/changeB2=Dmeta
> +metas/changeF=F
> +
> +In this case, changeB and changeB2 are still divergent and we’ve created a new
> +change for our merge commit. However, this is just a temporary state. The next
> +time we run the “evolve” command, it will discover the divergence but also
> +discover the merge commit F that resolves it. Evolve will suggest converting F
> +into an amend merge in order to resolve the divergence and will display the
> +command for doing so.
> +
> +Rebase
> +------
> +In general the rebase command is treated as a modify command. When a change is
> +rebased, the new commit replaces the original.
> +
> +Rebase --abort is special. Its intent is to restore git to the state it had
> +prior to running rebase. It should move back any changes to point to the refs
> +they had prior to running rebase and delete any new changes that were created as
> +part of the rebase. To achieve this, rebase will save the state of all changes
> +in refs/metas prior to running rebase and will restore the entire namespace
> +after rebase completes (deleting any newly-created changes). Newly-created
> +metacommits are left in place, but will have no effect until garbage collected
> +since metacommits are only used if they are reachable from refs/metas.
> +
> +Change
> +------
> +The “change” command can be used to list, rename, reset or delete change. It has
> +a number of subcommands.
> +
> +The "list" subcommand lists local changes. If given the -r argument, it lists
> +remote changes.
> +
> +The "rename" subcommand renames a change, given its old and new name. If the old
> +name is omitted and there is exactly one change pointing to the current HEAD,
> +that change is renamed. If there are no changes pointing to the current HEAD,
> +one is created with the given name.
> +
> +The "forget" subcommand deletes a change by deleting its ref from the metas/
> +namespace. This is the normal way to delete extra aliases for a change if the
> +change has more than one name. By default, this will refuse to delete the last
> +alias for a change if there are any other changes that reference this change as
> +a parent.
> +
> +The "update" subcommand adds a new state to a change. It uses the default
> +algorithm for assigning change names. If the content commit is omitted, HEAD is
> +used. If given the optional --force argument, it will overwrite any existing
> +change of the same name. This latter form of "update" can be used to effectively
> +reset changes.
> +
> +The "update" command can accept any number of --origin and --replace arguments.
> +If any are present, the resulting change branch will point to a metacommit
> +containing the given origin and replacement edges.
> +
> +The "abandon" command deletes a change using obsolescence markers. It marks the
> +change as being obsolete and having been replaced by its parent. If given no
> +arguments, it applies to the current commit. Running evolve will cause any
> +abandoned changes to be removed from the branch. Any child changes will be
> +reparented on top of the parent of the abandoned change. If the current change
> +is abandoned, HEAD will move to point to its parent.
> +
> +The "restore" command restores a previously-abandoned change.
> +
> +The "prune" command deletes all obsolete changes and all changes that are
> +present in the given branch. Note that such changes can be recovered from the
> +reflog.
> +
> +Combined with the GC protection that is offered, this is intended to facilitate
> +a workflow that relies on changes instead of branches. Users could choose to
> +work with no local branches and use changes instead - both for mailing list and
> +gerrit workflows.
> +
> +Log
> +---
> +When a commit is shown in git log that is part of a change, it is decorated with
> +extra change information. If it is the head of a change, the name of the change
> +is shown next to the list of branches. If it is obsolete, it is decorated with
> +the text “obsolete, <n> commits behind <changename>”.
> +
> +Log gets a new --obslog argument indicating that the obsolescence graph should
> +be followed instead of the commit graph. This also changes the default
> +formatting options to make them more appropriate for viewing different
> +iterations of the same commit.
> +
> +Pull
> +----
> +
> +Pull gets an --evolve argument that will automatically attempt to run "evolve"
> +on any affected branches after pulling.
> +
> +We also introduce an "evolve" enum value for the branch.<name>.rebase config
> +value. When set, the evolve behavior will happen automatically for that branch
> +after every pull even if the --evolve argument is not used.
> +
> +Next
> +----
> +
> +The "next" command will reset HEAD to a non-obsolete commit that refers to this
> +change as its parent. If there is more than one such change, the user will be
> +prompted. If given the --evolve argument, the next commit will be evolved if
> +necessary first.
> +
> +The "next" command can be thought of as the opposite of
> +"git reset --hard HEAD^" in that it navigates to a child commit rather than a
> +parent.
> +
> +Prev
> +----
> +
> +The "prev" command will reset HEAD to the latest version of the parent change.
> +If the parent change isn't obsolete, this is equivalent to
> +"git reset --hard HEAD^". If the parent commit is obsolete, it resets to the
> +latest replacement for the parent commit.
> +
> +Other options considered
> +========================
> +We considered several other options for storing the obsolescence graph. This
> +section describes the other options and why they were rejected.
> +
> +Commit header
> +-------------
> +Add an “obsoletes” field to the commit header that points backwards from a
> +commit to the previous commits it obsoletes.
> +
> +Pros:
> +- Very simple
> +- Easy to traverse from a commit to the previous commits it obsoletes.
> +Cons:
> +- Adds a cost to the storage format, even for commits where the change history
> +  is uninteresting.
> +- Unconditionally prevents the change history from being garbage collected.
> +- Always causes the change history to be shared when pushing or pulling changes.
> +
> +Git notes
> +---------
> +Instead of storing obsolescence information in metacommits, the metacommit
> +content could go in a new notes namespace - say refs/notes/metacommit. Each note
> +would contain the list of obsolete and origin parents. An automerger could
> +be supplied to make it easy to merge the metacommit notes from different remotes.
> +
> +Pros:
> +- Easy to locate all commits obsoleted by a given commit (since there would only
> +  be one metacommit for any given commit).
> +Cons:
> +- Wrong GC behavior (obsolete commits wouldn’t automatically be retained by GC)
> +  unless we introduced a special case for these kinds of notes.
> +- No way to selectively share or pull the metacommits for one specific change.
> +  It would be all-or-nothing, which would be expensive. This could be addressed
> +  by changes to the protocol, but this would be invasive.
> +- Requires custom auto-merging behavior on fetch.
> +
> +Tags
> +----
> +Put the content of the metacommit in a message attached to tag on the
> +replacement commit. This is very similar to the git notes approach and has the
> +same pros and cons.
> +
> +Simple forward references
> +-------------------------
> +Record an edge from an obsolete commit to its replacement in this form:
> +
> +refs/obsoletes/<A>
> +
> +pointing to commit <B> as an indication that B is the replacement for the
> +obsolete commit A.
> +
> +Pros:
> +- Protects <B> from being garbage collected.
> +- Fast lookup for the evolve operation, without additional search structures
> +  (“what is the replacement for <A>?” is very fast).
> +
> +Cons:
> +- Can’t represent divergence (which is a P0 requirement).
> +- Creates lots of refs (which can be inefficient)
> +- Doesn’t provide a way to fetch only refs for a specific change.
> +- The obslog command requires a search of all refs.
> +
> +Complex forward references
> +--------------------------
> +Record an edge from an obsolete commit to its replacement in this form:
> +
> +refs/obsoletes/<change_id>/obs<A>_<B>
> +
> +Pointing to commit <B> as an indication that B is the replacement for obsolete
> +commit A.
> +
> +Pros:
> +- Permits sharing and fetching refs for only a specific change.
> +- Supports divergence
> +- Protects <B> from being garbage collected.
> +
> +Cons:
> +- Creates lots of refs, which is inefficient.
> +- Doesn’t provide a good lookup structure for lookups in either direction.
> +
> +Backward references
> +-------------------
> +Record an edge from a replacement commit to the obsolete one in this form:
> +
> +refs/obsolescences/<B>
> +
> +Cons:
> +- Doesn’t provide a way to resolve divergence (which is a P0 requirement).
> +- Doesn’t protect <B> from being garbage collected (which could be fixed by
> +  combining this with a refs/metas namespace, as in the metacommit variant).
> +
> +Obsolescences file
> +------------------
> +Create a custom file (or files) in .git recording obsolescences.
> +
> +Pros:
> +- Can store exactly the information we want with exactly the performance we want
> +  for all operations. For example, there could be a disk-based hashtable
> +  permitting constant time lookups in either direction.
> +
> +Cons:
> +- Handling GC, pushing, and pulling would all require custom solutions. GC
> +  issues could be addressed with a repository format extension.
> +
> +Squash points
> +-------------
> +We treat changes like topic branches, and use special squash points to mark
> +places in the commit graph that separate changes.
> +
> +We create and update change branches in refs/metas at the same time we
> +would have in the metacommit proposal. However, rather than pointing to a
> +metacommit branch they point to normal commits and are treated as “squash
> +points” - markers for sequences of commits intended to be squashed together on
> +submission.
> +
> +Amends and rebases work differently than they do now. Rather than actually
> +containing the desired state of a commit, they contain a delta from the previous
> +version along with a squash point indicating that the preceding changes are
> +intended to be squashed on submission. Specifically, amends would become new
> +changes and rebases would become merge commits with the old commit and new
> +parent as parents.
> +
> +When the changes are finally submitted, the squashes are executed, producing the
> +final version of the commit.
> +
> +In addition to the squash points, git would maintain a set of “nosquash” tags
> +for commits that were used as ancestors of a change that are not meant to be
> +included in the squash.
> +
> +For example, if we have this commit graph:
> +
> +A(...)
> +B(parent=A)
> +C(parent=B)
> +
> +...and we amend B to produce D, we’d get:
> +
> +A(...)
> +B(parent=A)
> +C(parent=B)
> +D(parent=B)
> +
> +...along with a new change branch indicating D should be squashed with its
> +parents when submitted:
> +
> +metas/changeB = D
> +metas/changeC = C
> +
> +We’d also create a nosquash tag for A indicating that A shouldn’t be included
> +when changeB is squashed.
> +
> +If a user amends the change again, they’d get:
> +
> +A(...)
> +B(parent=A)
> +C(parent=B)
> +D(parent=B)
> +E(parent=D)
> +
> +metas/changeB = E
> +metas/changeC = C
> +
> +Pros:
> +- Good GC behavior.
> +- Provides a natural way to share changes (they’re just normal branches).
> +- Merge-base works automatically without special cases.
> +- Rewriting the obslog would be easy using existing git commands.
> +- No new data types needed.
> +Cons:
> +- No way to connect the squashed version of a change to the original, so no way
> +  to automatically clean up old changes. This also means users lose all benefits
> +  of the evolve command if they prematurely squash their commits. This may occur
> +  if a user thinks a change is ready for submission, squashes it, and then later
> +  discovers an additional change to make.
> +- Histories would look very cluttered (users would see all previous edits to
> +  their commit in the commit log, and all previous rebases would show up as
> +  merges). Could be quite hard for users to tell what is going on. (Possible
> +  fix: also implement a new smart log feature that displays the log as though
> +  the squashes had occurred).
> +- Need to change the current behavior of current commands (like amend and
> +  rebase) in ways that will be unexpected to many users.
> --
> gitgitgadget
>

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the Git mailing list, Glen Choo wrote (reply to this):

Hi Chris!

Chris Poucet <poucet@google.com> writes:

> One thing that is not clear to me is whether this is the desired
> direction. I took at look at the git review notes but it was hard to
> get a sense of where people are at.

I'm really sorry, I meant to get back to this sooner with the takeaways
from Review Club. Hopefully this will still be useful.

You can find the Review Club notes here:

  https://docs.google.com/document/d/14L8BAumGTpsXpjDY8VzZ4rRtpAjuGrFSRqn3stCuS_w/edit?pli=1

> Would love input on the design.

Others have given a lot of input on the design, so instead, I'll focus
mostly on how to make the doc better on the mailing list.

>
> On Wed, Oct 5, 2022 at 4:59 PM Stefan Xenos via GitGitGadget
> <gitgitgadget@gmail.com> wrote:
>>
>> From: Stefan Xenos <sxenos@google.com>
>>
>> This document describes what a change graph for
>> git would look like, the behavior of the evolve command,
>> and the changes planned for other commands.
>>
>> It was originally proposed in 2018, see
>> https://public-inbox.org/git/20181115005546.212538-1-sxenos@google.com/

This doc is quite well-thought-out and surprisingly readable despite its
length. That said, it is a lot to review in one sitting, and a reviewer
might get easily fatigued. I suspect that reviewers will find it hard to
keep up with the discussion if they have to review the entire doc on
every iteration.

As Victoria suggested in Review Club, it might be helpful to split up
the design over multiple patches to make feedback more focused. I think
this will make it easier for you (and others) to get a sense of how we
feel about each part of the design. e.g. here's one way to split up the
doc:

- Motivation, Background, High level idea of how a user would use this. 

  (Roughly corresponding to the sections "Objective", "Status",
  "Background", "Goals", "Similar technologies", "Semi-related work")

- Local change tracking, Changes to existing commands, Meta-commits

  (The parts about the data format and their implications for GC,
  negotiation, etc. Maybe include the `change` subcommand if it helps
  reviewers visualize the impact.)

- How evolve works, e.g. convergence, divergence, merge base finding.
  CLI

- Sharing changes

Besides the design, here other sections that I would find useful:

- Glossary. I thought that terms like "change", "change branch" and
  "change graph" were underdefined. This would also be a useful
  reference during the implementation phase.

- Implementation Plan (you can find examples in
  Documentation/technical/bundle-uri.txt and
  Documentation/technical/sparse-index.txt). Making the concrete next
  steps visible has numerous benefits:
  - Reviewers of future patches know what problem is being tackled and
    value is being delivered.
  - The list gains confidence that the author can deliver the work being
    promised.
  - The shared direction makes it easier for others to contribute
    patches.

- Open questions (e.g. "Implementation questions" in [1]). It would be
  useful to know what questions can be answered later instead of right
  now. Also, since you are not the original author, perhaps you also
  have questions about the design that you want answered by reviewers.
  I also wouldn't mind this being in the cover letter or "---" section.

[1] https://lore.kernel.org/git/pull.1367.git.1664064588846.gitgitgadget@gmail.com

As mentioned earlier, I'll comment only very lightly on the design.

>> +Similar technologies
>> +--------------------

I'd personally love to see "git evolve". If it helps to consider some
other tools, I use the following tools that implement similar workflows:

- git-branchless [2] features anonymous heads, obsolescence tracking, 
  history manipulations and "git evolve". Having used this for a while,
  I'm of the opnion that having any of these features without the
  others is still very useful, and implementing them in phases 
  will still deliver value without having to complete all of the work
  (granted, each of these features is incrementally dependent on the
  others).

  Case in point: I don't use the "evolve" equivalent of git-branchless
  (IIRC "restack); being able to see obsolescence and manually
  manipulating history is good enough for me.

- Jujutsu [3] also features anonymous heads, obsolescence tracking and
  advanced history manipulations. Instead of "evolve", descendents of an
  obsolete commit are automatically rebased on the obsoleting commit.

[2] https://github.com/arxanas/git-branchless
[3] https://github.com/martinvonz/jj

>> +Changes
>> +-------
>> +A branch of meta-commits describes how a commit was produced and what previous
>> +commits it is based on. It is also an identifier for a thing the user is
>> +currently working on. We refer to such a meta-branch as a change.
>> +
>> +Local changes are stored in the new refs/metas namespace. Remote changes are
>> +stored in the refs/remote/<remotename>/metas namespace.

I find this terminology of "changes" and "metas" more confusing than
necessary. A glossary would help, but it might be even better to also
use an appropriate ref namespace. "refs/changes/" is an obvious
candidate, though I assume this wasn't mentioned because Gerrit uses
that namespace extensively.

Maybe `refs/changelists`, `refs/change-requests`, `refs/proposals`? Idk.

>> +Sharing changes
>> +---------------
>> +Change histories are shared by pushing or fetching meta-commits and change
>> +branches. This provides users with a lot of control of what to share and
>> +repository implementations with control over what to retain.
>> +
>> +Users that only want to share the content of a commit can do so by pushing the
>> +commit itself as they currently would. Users that want to share an edit history
>> +for the commit can push its change, which would point to a meta-commit rather
>> +than the commit itself if there is any history to share. Note that multiple
>> +changes can refer to the same commits, so it’s possible to construct and push a
>> +different history for the same commit in order to remove sensitive or irrelevant
>> +intermediate states.

I would not like to see the ability to share all intermediate states
with the server because this increases the risk of unintentional
disclosure by a lot.

How exactly we could tweak this can be an open discussion for later.
Some examples I can think of:
  - Asking the user to go through the obsolescence log and manually
    prune revisions (sounds too onerous for users IMO).
  - Push a truncated history consisting of only the latest version and
    commits that the server already knows (somewhat similar to Gerrit).

>> +Evolve
>> +------
>> +The evolve command performs the correct sequence of rebases such that no change
>> +has an obsolete parent. The syntax looks like this:
>> +
>> +git evolve [upstream…]
>> +
>> +It takes an optional list of upstream branches. All changes whose parent shows
>> +up in the history of one of the upstream branches will be rebased onto the
>> +upstream branch before resolving obsolete parents.
>> +

This CLI is an example of something that can be reviewed largely
independently of the implementing data structures.

>> +Merge
>> +-----
>> +
>> +To select between these two behaviors, merge gets new “--amend” and “--noamend”
>> +options which select between the “create” and “modify” behaviors respectively,
>> +with noamend being the default.

Ditto.

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 6, 2022

User Glen Choo <chooglen@google.com> has been added to the cc: list.

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 10, 2022

On the Git mailing list, Phillip Wood wrote (reply to this):

Hi Chris

On 05/10/2022 15:59, Christophe Poucet via GitGitGadget wrote:
> I'm reviving the original git evolve work that was started by
> sxenos@google.com
> (https://public-inbox.org/git/20190215043105.163688-1-sxenos@google.com/)
> > This work is intended to make it easier to deal with stacked changes.
> > The following set of patches introduces the design doc on the evolve command
> as well as the basics of the git change command.

Thanks for the new version. When you post a new version of a patch series it is helpful to give a brief outline of what you have changed since the last version. The overview should also explain the reasons for reordering or squashing patches. In this case the old patches 7 & 8 have been squashed together. I think it would have been better to leave them as separate patches and add the tests at the same time as the commands (that's why I provided separate fixups). The style is now closer to our normal style but there are still some deviations.

* Comments:

Single line comments should look like
	/* single line */

Multi-line comments should look like
	/*
	 * Multi-line
	 * comment.
	 */
Not
+	/* If to_add is not a metacommit then the content is to_add itself,
+	 * otherwise it will have been set by the call to
+	 * get_metacommit_content.
+	 */

API comments may be formatted as
	/**
	 * API docs
	 */

but then you should not mix styles. For example in patch 5 you have
+	/**
+	 * Memory pool for the objects allocated by the change table.
+	 */
+	struct mem_pool memory_pool;
+	/* Map object_id to commit_change_list_entry structs. */
+	struct oidmap oid_to_metadata_index;

* Functions

Wrap function arguments at 80 columns and indent the continuation lines to align with the opening parenthesis unless the function name is exceptionally long. There may be more than one function argument per line. For example

static void resolve_metacommit(struct repository* repo,
                               struct change_table* active_changes,
                               const struct metacommit_data *to_resolve,
                               struct metacommit_data *resolved_output,
                               struct string_list *to_advance, int allow_append)

Not

static void resolve_metacommit(
	struct repository* repo,
	struct change_table* active_changes,
	const struct metacommit_data *to_resolve,
	struct metacommit_data *resolved_output,
	struct string_list *to_advance,
	int allow_append)

You can use git-clang-format to get a fairly close approximation to the required style.

For variables and function arguments we generally prefer names to be nouns rather than verbs.

Commit messages are expected to explain the motivation the changes not just list the functions that are added.

Overall the changes are moving in the right direction, though it's a shame the fixup for sorting the output of "git change list" isn't included here.

As well as aligning the code style, I think we need to pin down the details in patch 1 as there seems to be some on-going discussion about the design.

Best Wishes

Phillip

> Chris Poucet (5):
>    sha1-array: implement oid_array_readonly_contains
>    ref-filter: add the metas namespace to ref-filter
>    evolve: add delete command
>    evolve: add documentation for `git change`
>    evolve: add tests for the git-change command
> > Stefan Xenos (5):
>    technical doc: add a design doc for the evolve command
>    evolve: add support for parsing metacommits
>    evolve: add the change-table structure
>    evolve: add support for writing metacommits
>    evolve: implement the git change command
> >   .gitignore                         |    1 +
>   Documentation/git-change.txt       |   55 ++
>   Documentation/technical/evolve.txt | 1070 ++++++++++++++++++++++++++++
>   Makefile                           |    4 +
>   builtin.h                          |    1 +
>   builtin/change.c                   |  330 +++++++++
>   change-table.c                     |  164 +++++
>   change-table.h                     |  122 ++++
>   commit.c                           |   13 +
>   commit.h                           |    5 +
>   git.c                              |    1 +
>   metacommit-parser.c                |   97 +++
>   metacommit-parser.h                |   19 +
>   metacommit.c                       |  410 +++++++++++
>   metacommit.h                       |   75 ++
>   oid-array.c                        |   12 +
>   oid-array.h                        |    7 +
>   ref-filter.c                       |   10 +-
>   ref-filter.h                       |   10 +-
>   t/helper/test-oid-array.c          |    6 +
>   t/t0064-oid-array.sh               |   22 +
>   t/t9990-changes.sh                 |  148 ++++
>   22 files changed, 2577 insertions(+), 5 deletions(-)
>   create mode 100644 Documentation/git-change.txt
>   create mode 100644 Documentation/technical/evolve.txt
>   create mode 100644 builtin/change.c
>   create mode 100644 change-table.c
>   create mode 100644 change-table.h
>   create mode 100644 metacommit-parser.c
>   create mode 100644 metacommit-parser.h
>   create mode 100644 metacommit.c
>   create mode 100644 metacommit.h
>   create mode 100755 t/t9990-changes.sh
> > > base-commit: 3dcec76d9df911ed8321007b1d197c1a206dc164
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1356%2Fpoucet%2Fevolve-v2
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1356/poucet/evolve-v2
> Pull-Request: https://github.com/gitgitgadget/git/pull/1356
> > Range-diff vs v1:
> >    1:  a0cf68f8ba2 !  1:  a5eb9325419 technical doc: add a design doc for the evolve command
>       @@ Documentation/technical/evolve.txt (new)
>        +rebase. You can think of rebase -i as a top-down approach and the evolve command
>        +as the bottom-up approach to the same problem.
>        +
>       ++Revup amend (https://github.com/Skydio/revup/blob/main/docs/amend.md)
>       ++allows insertion of cached changes into any commit in
>       ++the current history, and then reapplies the rest of history on top of
>       ++those changes. It uses a "git apply --cached" engine under the hood so
>       ++doesn't touch the working directory (although it will soon use the new
>       ++git merge-tree). When paired with "revup upload" which creates and
>       ++pushes multiple branches in the background for you, its possible to
>       ++work on a "graph" of changes on a single branch linearly, then have
>       ++the true graph structure created at upload time.
>       ++
>       ++git-revise (https://github.com/mystor/git-revise) does some very
>       ++similar things except it uses "git merge-file" combined with manually
>       ++merging the resulting trees. git branchstack
>       ++(https://github.com/krobelus/git-branchstack) can also create branches
>       ++in the background with the same mechanism.
>       ++
>       ++These tools don't store any external state, but as such also don't
>       ++provide any specific collaboration mechanism for individual changes.
>       ++
>        +Several patch queue managers have been built on top of git (such as topgit,
>        +stgit, and quilt). They address the same user need. However they also rely on
>        +state managed outside git that needs to be kept in sync. Such state can be
>    2:  84588312c1d =  2:  ed5106d6080 sha1-array: implement oid_array_readonly_contains
>    3:  54e559967df !  3:  c59066ebc10 ref-filter: add the metas namespace to ref-filter
>       @@ ref-filter.c: int filter_refs(struct ref_array *array, struct ref_filter *filter
>        >         ## ref-filter.h ##
>        @@
>       + #define FILTER_REFS_TAGS           0x0002
>         #define FILTER_REFS_BRANCHES       0x0004
>         #define FILTER_REFS_REMOTES        0x0008
>       - #define FILTER_REFS_OTHERS         0x0010
>       -+#define FILTER_REFS_CHANGES        0x0040
>       +-#define FILTER_REFS_OTHERS         0x0010
>       ++#define FILTER_REFS_CHANGES        0x0010
>       ++#define FILTER_REFS_OTHERS         0x0040
>         #define FILTER_REFS_ALL            (FILTER_REFS_TAGS | FILTER_REFS_BRANCHES | \
>        -				    FILTER_REFS_REMOTES | FILTER_REFS_OTHERS)
>        +				    FILTER_REFS_REMOTES | FILTER_REFS_OTHERS | \

This looks good

>    4:  2e9a4a9bd81 !  4:  408941e7400 evolve: add support for parsing metacommits
>       @@ Makefile: LIB_OBJS += merge-ort.o
>         LIB_OBJS += name-hash.o
>         LIB_OBJS += negotiator/default.o
>        >       + ## commit.c ##
>       +@@ commit.c: struct commit_list *reverse_commit_list(struct commit_list *list)
>       + 	return next;
>       + }
>       +
>       ++struct commit *get_commit_by_index(struct commit_list *to_search, int index)
>       ++{
>       ++	while (to_search && index) {
>       ++		to_search = to_search->next;
>       ++		index--;
>       ++	}
>       ++
>       ++	if (!to_search)
>       ++		return NULL;
>       ++
>       ++	return to_search->item;
>       ++}
>       ++
>       + void free_commit_list(struct commit_list *list)
>       + {
>       + 	while (list)
>       +
>       + ## commit.h ##
>       +@@ commit.h: struct commit_list *copy_commit_list(struct commit_list *list);
>       + /* Modify list in-place to reverse it, returning new head; list will be tail */
>       + struct commit_list *reverse_commit_list(struct commit_list *list);
>       +
>       ++/* Returns the commit at `index` or NULL if the index exceeds the `to_search`
>       ++ * list */
>       ++struct commit *get_commit_by_index(struct commit_list *to_search, int index);
>       ++
>       + void free_commit_list(struct commit_list *list);
>       +
>       ++
>       + struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
>       +
>       + int has_non_ascii(const char *text);
>       +
>         ## metacommit-parser.c (new) ##
>        @@
>        +#include "cache.h"
>       @@ metacommit-parser.c (new)
>        +	return NULL;
>        +}
>        +
>       -+static struct commit *get_commit_by_index(struct commit_list *to_search, int index)
>       -+{
>       -+	while (to_search && index) {
>       -+		to_search = to_search->next;
>       -+		index--;
>       -+	}
>       -+
>       -+	if (!to_search)
>       -+		return NULL;
>       -+
>       -+	return to_search->item;
>       -+}
>       -+
>        +/*
>        + * Writes the index of the content parent to "result". Returns the metacommit
>        + * type. See the METACOMMIT_TYPE_* constants.
>        + */
>       -+static int index_of_content_commit(const char *buffer, int *result)
>       ++static enum metacommit_type index_of_content_commit(const char *buffer, int *result)
>        +{
>        +	int index = 0;
>        +	int ret = METACOMMIT_TYPE_NONE;
>       @@ metacommit-parser.c (new)
>        +		char next = *parent_types;
>        +		if (next == ' ' || parent_types >= end) {
>        +			if (enum_length == 1) {
>       -+				char first_char_in_enum = *enum_start;
>       -+				if (first_char_in_enum == 'c') {
>       ++				char type = *enum_start;
>       ++				if (type == 'c') {
>        +					ret = METACOMMIT_TYPE_NORMAL;
>        +					break;
>        +				}
>       -+				if (first_char_in_enum == 'a') {
>       ++				if (type == 'a') {
>        +					ret = METACOMMIT_TYPE_ABANDONED;
>        +					break;
>        +				}
>       @@ metacommit-parser.c (new)
>        + * Writes the content parent's object id to "content".
>        + * Returns the metacommit type. See the METACOMMIT_TYPE_* constants.
>        + */
>       -+int get_metacommit_content(struct commit *commit, struct object_id *content)
>       ++enum metacommit_type get_metacommit_content(struct commit *commit, struct object_id *content)
>        +{
>        +	const char *buffer = get_commit_buffer(commit, NULL);
>        +	int index = 0;
>       -+	int ret = index_of_content_commit(buffer, &index);
>       ++	enum metacommit_type ret = index_of_content_commit(buffer, &index);
>        +	struct commit *content_parent;
>        +
>        +	if (ret == METACOMMIT_TYPE_NONE)
>       @@ metacommit-parser.h (new)
>        +#include "commit.h"
>        +#include "hash.h"
>        +
>       -+/* Indicates a normal commit (non-metacommit) */
>       -+#define METACOMMIT_TYPE_NONE 0
>       -+/* Indicates a metacommit with normal content (non-abandoned) */
>       -+#define METACOMMIT_TYPE_NORMAL 1
>       -+/* Indicates a metacommit with abandoned content */
>       -+#define METACOMMIT_TYPE_ABANDONED 2
>       -+
>       -+struct commit;
>       ++enum metacommit_type {
>       ++	/* Indicates a normal commit (non-metacommit) */
>       ++	METACOMMIT_TYPE_NONE = 0,
>       ++	/* Indicates a metacommit with normal content (non-abandoned) */
>       ++	METACOMMIT_TYPE_NORMAL = 1,
>       ++	/* Indicates a metacommit with abandoned content */
>       ++	METACOMMIT_TYPE_ABANDONED = 2,
>       ++};
>        +
>       -+extern int get_metacommit_content(
>       ++enum metacommit_type get_metacommit_content(
>        +	struct commit *commit, struct object_id *content);
>        +
>        +#endif
>    5:  2b3a00a6702 !  5:  48cd92d35ef evolve: add the change-table structure
>       @@ change-table.c (new)
>        +#include "ref-filter.h"
>        +#include "metacommit-parser.h"
>        +
>       -+void change_table_init(struct change_table *to_initialize)
>       ++void change_table_init(struct change_table *table)
>        +{
>       -+	memset(to_initialize, 0, sizeof(*to_initialize));
>       -+	mem_pool_init(&to_initialize->memory_pool, 0);
>       -+	to_initialize->memory_pool.block_alloc = 4*1024 - sizeof(struct mp_block);
>       -+	oidmap_init(&to_initialize->oid_to_metadata_index, 0);
>       -+	string_list_init_dup(&to_initialize->refname_to_change_head);
>       ++	memset(table, 0, sizeof(*table));
>       ++	mem_pool_init(&table->memory_pool, 0);
>       ++	oidmap_init(&table->oid_to_metadata_index, 0);
>       ++	strmap_init(&table->refname_to_change_head);
>        +}
>        +
>       -+static void change_list_clear(struct change_list *to_clear) {
>       -+	string_list_clear(&to_clear->additional_refnames, 0);
>       ++static void change_list_clear(struct change_list *change_list) {
>       ++	strset_clear(&change_list->refnames);
>        +}
>        +
>        +static void commit_change_list_entry_clear(
>       -+	struct commit_change_list_entry *to_clear) {
>       -+	change_list_clear(&to_clear->changes);
>       ++	struct commit_change_list_entry *entry) {
>       ++	change_list_clear(&entry->changes);
>        +}
>        +
>       -+void change_table_clear(struct change_table *to_clear)
>       ++void change_table_clear(struct change_table *table)
>        +{
>        +	struct oidmap_iter iter;
>        +	struct commit_change_list_entry *next;
>       -+	for (next = oidmap_iter_first(&to_clear->oid_to_metadata_index, &iter);
>       ++	for (next = oidmap_iter_first(&table->oid_to_metadata_index, &iter);
>        +		next;
>        +		next = oidmap_iter_next(&iter)) {
>        +
>        +		commit_change_list_entry_clear(next);
>        +	}
>        +
>       -+	oidmap_free(&to_clear->oid_to_metadata_index, 0);
>       -+	string_list_clear(&to_clear->refname_to_change_head, 0);
>       -+	mem_pool_discard(&to_clear->memory_pool, 0);
>       ++	oidmap_free(&table->oid_to_metadata_index, 0);
>       ++	strmap_clear(&table->refname_to_change_head, 0);
>       ++	mem_pool_discard(&table->memory_pool, 0);
>        +}
>        +
>       -+static void add_head_to_commit(struct change_table *to_modify,
>       -+	const struct object_id *to_add, const char *refname)
>       ++static void add_head_to_commit(struct change_table *table,
>       ++			       const struct object_id *to_add,
>       ++			       const char *refname)
>        +{
>        +	struct commit_change_list_entry *entry;
>        +
>       -+	/**
>       -+	 * Note: the indices in the map are 1-based. 0 is used to indicate a missing
>       -+	 * element.
>       -+	 */
>       -+	entry = oidmap_get(&to_modify->oid_to_metadata_index, to_add);
>       ++	entry = oidmap_get(&table->oid_to_metadata_index, to_add);
>        +	if (!entry) {
>       -+		entry = mem_pool_calloc(&to_modify->memory_pool, 1,
>       -+			sizeof(*entry));
>       ++		entry = mem_pool_calloc(&table->memory_pool, 1, sizeof(*entry));
>        +		oidcpy(&entry->entry.oid, to_add);
>       -+		oidmap_put(&to_modify->oid_to_metadata_index, entry);
>       -+		string_list_init_nodup(&entry->changes.additional_refnames);
>       ++		strset_init(&entry->changes.refnames);
>       ++		oidmap_put(&table->oid_to_metadata_index, entry);
>        +	}
>       -+
>       -+	if (!entry->changes.first_refname)
>       -+		entry->changes.first_refname = refname;
>       -+	else
>       -+		string_list_insert(&entry->changes.additional_refnames, refname);
>       ++	strset_add(&entry->changes.refnames, refname);
>        +}
>        +
>       -+void change_table_add(struct change_table *to_modify, const char *refname,
>       -+	struct commit *to_add)
>       ++void change_table_add(struct change_table *table,
>       ++		      const char *refname,
>       ++		      struct commit *to_add)
>        +{
>        +	struct change_head *new_head;
>       -+	struct string_list_item *new_item;
>        +	int metacommit_type;
>        +
>       -+	new_head = mem_pool_calloc(&to_modify->memory_pool, 1,
>       -+		sizeof(*new_head));
>       ++	new_head = mem_pool_calloc(&table->memory_pool, 1, sizeof(*new_head));
>        +
>        +	oidcpy(&new_head->head, &to_add->object.oid);
>        +
>        +	metacommit_type = get_metacommit_content(to_add, &new_head->content);
>       ++	/* If to_add is not a metacommit then the content is to_add itself,
>       ++	 * otherwise it will have been set by the call to
>       ++	 * get_metacommit_content.
>       ++	 */
>        +	if (metacommit_type == METACOMMIT_TYPE_NONE)
>        +		oidcpy(&new_head->content, &to_add->object.oid);
>        +	new_head->abandoned = (metacommit_type == METACOMMIT_TYPE_ABANDONED);
>        +	new_head->remote = starts_with(refname, "refs/remote/");
>        +	new_head->hidden = starts_with(refname, "refs/hiddenmetas/");
>        +
>       -+	new_item = string_list_insert(&to_modify->refname_to_change_head, refname);
>       -+	new_item->util = new_head;
>       -+	/* Use pointers to the copy of the string we're retaining locally */
>       -+	refname = new_item->string;
>       -+
>       -+	if (!oideq(&new_head->content, &new_head->head))
>       -+		add_head_to_commit(to_modify, &new_head->content, refname);
>       -+	add_head_to_commit(to_modify, &new_head->head, refname);
>       -+}
>       -+
>       -+void change_table_add_all_visible(struct change_table *to_modify,
>       -+	struct repository* repo)
>       -+{
>       -+	struct ref_filter filter;
>       -+	const char *name_patterns[] = {NULL};
>       -+	memset(&filter, 0, sizeof(filter));
>       -+	filter.kind = FILTER_REFS_CHANGES;
>       -+	filter.name_patterns = name_patterns;
>       ++	strmap_put(&table->refname_to_change_head, refname, new_head);
>        +
>       -+	change_table_add_matching_filter(to_modify, repo, &filter);
>       ++	if (!oideq(&new_head->content, &new_head->head)) {
>       ++		/* We also remember to link between refname and the content oid */
>       ++		add_head_to_commit(table, &new_head->content, refname);
>       ++	}
>       ++	add_head_to_commit(table, &new_head->head, refname);
>        +}
>        +
>       -+void change_table_add_matching_filter(struct change_table *to_modify,
>       -+	struct repository* repo, struct ref_filter *filter)
>       ++static void change_table_add_matching_filter(struct change_table *table,
>       ++					     struct repository* repo,
>       ++					     struct ref_filter *filter)
>        +{
>       -+	struct ref_array matching_refs;
>        +	int i;
>       ++	struct ref_array matching_refs = { 0 };
>        +
>       -+	memset(&matching_refs, 0, sizeof(matching_refs));
>        +	filter_refs(&matching_refs, filter, filter->kind);
>        +
>       -+	/**
>       ++	/*
>        +	 * Determine the object id for the latest content commit for each change.
>        +	 * Fetch the commit at the head of each change ref. If it's a normal commit,
>        +	 * that's the commit we want. If it's a metacommit, locate its content parent
>       @@ change-table.c (new)
>        +
>        +	for (i = 0; i < matching_refs.nr; i++) {
>        +		struct ref_array_item *item = matching_refs.items[i];
>       -+		struct commit *commit = item->commit;
>       ++		struct commit *commit;
>        +
>       -+		commit = lookup_commit_reference_gently(repo, &item->objectname, 1);
>       -+
>       -+		if (commit)
>       -+			change_table_add(to_modify, item->refname, commit);
>       ++		commit = lookup_commit_reference(repo, &item->objectname);
>       ++		if (!commit) {
>       ++			BUG("Invalid commit for refs/meta: %s", item->refname);
>       ++		}
>       ++		change_table_add(table, item->refname, commit);
>        +	}
>        +
>        +	ref_array_clear(&matching_refs);
>        +}
>        +
>       ++void change_table_add_all_visible(struct change_table *table,
>       ++	struct repository* repo)
>       ++{
>       ++	struct ref_filter filter = { 0 };
>       ++	const char *name_patterns[] = {NULL};
>       ++	filter.kind = FILTER_REFS_CHANGES;
>       ++	filter.name_patterns = name_patterns;
>       ++
>       ++	change_table_add_matching_filter(table, repo, &filter);
>       ++}
>       ++
>        +static int return_true_callback(const char *refname, void *cb_data)
>        +{
>        +	return 1;
>        +}
>        +
>       -+int change_table_has_change_referencing(struct change_table *changes,
>       ++int change_table_has_change_referencing(struct change_table *table,
>        +	const struct object_id *referenced_commit_id)
>        +{
>       -+	return for_each_change_referencing(changes, referenced_commit_id,
>       ++	return for_each_change_referencing(table, referenced_commit_id,
>        +		return_true_callback, NULL);
>        +}
>        +
>        +int for_each_change_referencing(struct change_table *table,
>        +	const struct object_id *referenced_commit_id, each_change_fn fn, void *cb_data)
>        +{
>       -+	const struct change_list *changes;
>       -+	int i;
>       -+	int retvalue;
>       -+	struct commit_change_list_entry *entry;
>       ++	int ret;
>       ++	struct commit_change_list_entry *ccl_entry;
>       ++	struct hashmap_iter iter;
>       ++	struct strmap_entry *entry;
>        +
>       -+	entry = oidmap_get(&table->oid_to_metadata_index,
>       -+		referenced_commit_id);
>       ++	ccl_entry = oidmap_get(&table->oid_to_metadata_index,
>       ++			       referenced_commit_id);
>        +	/* If this commit isn't referenced by any changes, it won't be in the map */
>       -+	if (!entry)
>       ++	if (!ccl_entry)
>        +		return 0;
>       -+	changes = &entry->changes;
>       -+	if (!changes->first_refname)
>       -+		return 0;
>       -+	retvalue = fn(changes->first_refname, cb_data);
>       -+	for (i = 0; retvalue == 0 && i < changes->additional_refnames.nr; i++)
>       -+		retvalue = fn(changes->additional_refnames.items[i].string, cb_data);
>       -+	return retvalue;
>       ++	strset_for_each_entry(&ccl_entry->changes.refnames, &iter, entry) {
>       ++		ret = fn(entry->key, cb_data);
>       ++		if (ret != 0) break;
>       ++	}
>       ++	return ret;
>        +}
>        +
>       -+struct change_head* get_change_head(struct change_table *heads,
>       ++struct change_head* get_change_head(struct change_table *table,
>        +	const char* refname)
>        +{
>       -+	struct string_list_item *item = string_list_lookup(
>       -+		&heads->refname_to_change_head, refname);
>       -+
>       -+	if (!item)
>       -+		return NULL;
>       -+
>       -+	return (struct change_head *)item->util;
>       ++	return strmap_get(&table->refname_to_change_head, refname);
>        +}
>        >         ## change-table.h (new) ##
>       @@ change-table.h (new)
>        +#define CHANGE_TABLE_H
>        +
>        +#include "oidmap.h"
>       ++#include "strmap.h"
>        +
>        +struct commit;
>        +struct ref_filter;
>        +
>        +/**
>       -+ * This struct holds a list of change refs. The first element is stored inline,
>       -+ * to optimize for small lists.
>       ++ * This struct holds a set of change refs.
>        + */
>        +struct change_list {
>        +	/**
>       -+	 * Ref name for the first change in the list, or null if none.
>       -+	 *
>       ++	 * The refnames in this set.
>        +	 * This field is private. Use for_each_change_in to read.
>        +	 */
>       -+	const char* first_refname;
>       -+	/**
>       -+	 * List of additional change refs. Note that this is empty if the list
>       -+	 * contains 0 or 1 elements.
>       -+	 *
>       -+	 * This field is private. Use for_each_change_in to read.
>       -+	 */
>       -+	struct string_list additional_refnames;
>       ++	struct strset refnames;
>        +};
>        +
>        +/**
>       @@ change-table.h (new)
>        +};
>        +
>        +/**
>       -+ * Holds information about the heads of each change, and permits effecient
>       ++ * Holds information about the heads of each change, and permits efficient
>        + * lookup from a commit to the changes that reference it directly.
>        + *
>        + * All fields should be considered private. Use the change_table functions
>       @@ change-table.h (new)
>        +	/* Map object_id to commit_change_list_entry structs. */
>        +	struct oidmap oid_to_metadata_index;
>        +	/**
>       -+	 * List of ref names. The util value points to a change_head structure
>       -+	 * allocated from memory_pool.
>       ++	 * Map of refnames to change_head structure which are allocated from
>       ++	 * memory_pool.
>        +	 */
>       -+	struct string_list refname_to_change_head;
>       ++	struct strmap refname_to_change_head;
>        +};
>        +
>       -+extern void change_table_init(struct change_table *to_initialize);
>       -+extern void change_table_clear(struct change_table *to_clear);
>       ++extern void change_table_init(struct change_table *table);
>       ++extern void change_table_clear(struct change_table *table);
>        +
>        +/* Adds the given change head to the change_table struct */
>       -+extern void change_table_add(struct change_table *to_modify,
>       -+	const char *refname, struct commit *target);
>       ++extern void change_table_add(struct change_table *table,
>       ++			     const char *refname,
>       ++			     struct commit *target);
>        +
>        +/**
>        + * Adds the non-hidden local changes to the given change_table struct.
>        + */
>       -+extern void change_table_add_all_visible(struct change_table *to_modify,
>       -+	struct repository *repo);
>       -+
>       -+/*
>       -+ * Adds all changes matching the given ref filter to the given change_table
>       -+ * struct.
>       -+ */
>       -+extern void change_table_add_matching_filter(struct change_table *to_modify,
>       -+	struct repository* repo, struct ref_filter *filter);
>       ++extern void change_table_add_all_visible(struct change_table *table,
>       ++					 struct repository *repo);
>        +
>        +typedef int each_change_fn(const char *refname, void *cb_data);
>        +
>       -+extern int change_table_has_change_referencing(struct change_table *changes,
>       ++extern int change_table_has_change_referencing(
>       ++	struct change_table *table,
>        +	const struct object_id *referenced_commit_id);
>        +
>        +/**
>       @@ change-table.h (new)
>        + * For normal commits, this is the list of changes that have this commit as
>        + * their latest content.
>        + */
>       -+extern int for_each_change_referencing(struct change_table *heads,
>       -+	const struct object_id *referenced_commit_id, each_change_fn fn, void *cb_data);
>       ++extern int for_each_change_referencing(
>       ++	struct change_table *table,
>       ++	const struct object_id *referenced_commit_id,
>       ++	each_change_fn fn,
>       ++	void *cb_data);
>        +
>        +/**
>        + * Returns the change head for the given refname. Returns NULL if no such change
>        + * exists.
>        + */
>       -+extern struct change_head* get_change_head(struct change_table *heads,
>       ++extern struct change_head* get_change_head(struct change_table *table,
>        +	const char* refname);
>        +
>        +#endif
>    6:  56c6770997b !  6:  353d97d0f38 evolve: add support for writing metacommits
>       @@ metacommit.c (new)
>        +#include "change-table.h"
>        +#include "refs.h"
>        +
>       -+void init_metacommit_data(struct metacommit_data *state)
>       -+{
>       -+	memset(state, 0, sizeof(*state));
>       -+}
>       -+
>        +void clear_metacommit_data(struct metacommit_data *state)
>        +{
>       ++	oidcpy(&state->content, null_oid());
>        +	oid_array_clear(&state->replace);
>        +	oid_array_clear(&state->origin);
>       ++	state->abandoned = 0;
>        +}
>        +
>        +static void compute_default_change_name(struct commit *initial_commit,
>       -+	struct strbuf* result)
>       ++					struct strbuf* result)
>        +{
>       -+	struct strbuf default_name;
>       ++	struct strbuf default_name = STRBUF_INIT;
>        +	const char *buffer;
>        +	const char *subject;
>        +	const char *eol;
>       -+	int len;
>       -+	strbuf_init(&default_name, 0);
>       ++	size_t len;
>        +	buffer = get_commit_buffer(initial_commit, NULL);
>        +	find_commit_subject(buffer, &subject);
>        +	eol = strchrnul(subject, '\n');
>       -+	for (len = 0;subject < eol && len < 10; ++subject, ++len) {
>       ++	for (len = 0; subject < eol && len < 10; subject++, len++) {
>        +		char next = *subject;
>        +		if (isspace(next))
>        +			continue;
>       @@ metacommit.c (new)
>        +		strbuf_addch(&default_name, next);
>        +	}
>        +	sanitize_refname_component(default_name.buf, result);
>       ++	unuse_commit_buffer(initial_commit, buffer);
>        +}
>        +
>       -+/**
>       ++/*
>        + * Computes a change name for a change rooted at the given initial commit. Good
>        + * change names should be memorable, unique, and easy to type. They are not
>        + * required to match the commit comment.
>        + */
>        +static void compute_change_name(struct commit *initial_commit, struct strbuf* result)
>        +{
>       -+	struct strbuf default_name;
>       ++	struct strbuf default_name = STRBUF_INIT;
>        +	struct object_id unused;
>        +
>       -+	strbuf_init(&default_name, 0);
>        +	if (initial_commit)
>        +		compute_default_change_name(initial_commit, &default_name);
>        +	else
>       -+		strbuf_addstr(&default_name, "change");
>       ++		BUG("initial commit is NULL");
>        +	strbuf_addstr(result, "refs/metas/");
>        +	strbuf_addbuf(result, &default_name);
>        +
>        +	/* If there is already a change of this name, append a suffix */
>        +	if (!read_ref(result->buf, &unused)) {
>        +		int suffix = 2;
>       -+		int original_length = result->len;
>       ++		size_t original_length = result->len;
>        +
>        +		while (1) {
>        +			strbuf_addf(result, "%d", suffix);
>        +			if (read_ref(result->buf, &unused))
>        +				break;
>       -+			strbuf_remove(result, original_length, result->len - original_length);
>       ++			strbuf_remove(result, original_length,
>       ++				      result->len - original_length);
>        +			++suffix;
>        +		}
>        +	}
>       @@ metacommit.c (new)
>        +	strbuf_release(&default_name);
>        +}
>        +
>       -+struct resolve_metacommit_callback_data
>       ++struct resolve_metacommit_context
>        +{
>        +	struct change_table* active_changes;
>        +	struct string_list *changes;
>       @@ metacommit.c (new)
>        +
>        +static int resolve_metacommit_callback(const char *refname, void *cb_data)
>        +{
>       -+	struct resolve_metacommit_callback_data *data = (struct resolve_metacommit_callback_data *)cb_data;
>       ++	struct resolve_metacommit_context *data = cb_data;
>        +	struct change_head *chhead;
>        +
>        +	chhead = get_change_head(data->active_changes, refname);
>        +
>        +	if (data->changes)
>       -+		string_list_append(data->changes, refname)->util = &(chhead->head);
>       ++		string_list_append(data->changes, refname)->util = &chhead->head;
>        +	if (data->heads)
>        +		oid_array_append(data->heads, &(chhead->head));
>        +
>        +	return 0;
>        +}
>        +
>       -+/**
>       ++/*
>        + * Produces the final form of a metacommit based on the current change refs.
>        + */
>        +static void resolve_metacommit(
>       @@ metacommit.c (new)
>        +	struct string_list *to_advance,
>        +	int allow_append)
>        +{
>       -+	int i;
>       -+	int len = to_resolve->replace.nr;
>       -+	struct resolve_metacommit_callback_data cbdata;
>       ++	size_t i;
>       ++	size_t len = to_resolve->replace.nr;
>       ++	struct resolve_metacommit_context ctx = {
>       ++		.active_changes = active_changes,
>       ++		.changes = to_advance,
>       ++		.heads = &resolved_output->replace
>       ++	};
>        +	int old_change_list_length = to_advance->nr;
>        +	struct commit* content;
>        +
>        +	oidcpy(&resolved_output->content, &to_resolve->content);
>        +
>       -+	/* First look for changes that point to any of the replacement edges in the
>       ++	/*
>       ++	 * First look for changes that point to any of the replacement edges in the
>        +	 * metacommit. These will be the changes that get advanced by this
>       -+	 * metacommit. */
>       ++	 * metacommit.
>       ++	 */
>        +	resolved_output->abandoned = to_resolve->abandoned;
>       -+	cbdata.active_changes = active_changes;
>       -+	cbdata.changes = to_advance;
>       -+	cbdata.heads = &(resolved_output->replace);
>        +
>        +	if (allow_append) {
>        +		for (i = 0; i < len; i++) {
>        +			int old_number = resolved_output->replace.nr;
>       -+			for_each_change_referencing(active_changes, &(to_resolve->replace.oid[i]),
>       -+				resolve_metacommit_callback, &cbdata);
>       ++			for_each_change_referencing(
>       ++				active_changes,
>       ++				&(to_resolve->replace.oid[i]),
>       ++				resolve_metacommit_callback,
>       ++				&ctx);
>        +			/* If no changes were found, use the unresolved value. */
>        +			if (old_number == resolved_output->replace.nr)
>       -+				oid_array_append(&(resolved_output->replace), &(to_resolve->replace.oid[i]));
>       ++				oid_array_append(&(resolved_output->replace),
>       ++						 &(to_resolve->replace.oid[i]));
>        +		}
>        +	}
>        +
>       -+	cbdata.changes = NULL;
>       -+	cbdata.heads = &(resolved_output->origin);
>       ++	ctx.changes = NULL;
>       ++	ctx.heads = &(resolved_output->origin);
>        +
>        +	len = to_resolve->origin.nr;
>        +	for (i = 0; i < len; i++) {
>        +		int old_number = resolved_output->origin.nr;
>       -+		for_each_change_referencing(active_changes, &(to_resolve->origin.oid[i]),
>       -+			resolve_metacommit_callback, &cbdata);
>       ++		for_each_change_referencing(
>       ++			active_changes,
>       ++			&(to_resolve->origin.oid[i]),
>       ++			resolve_metacommit_callback,
>       ++			&ctx);
>        +		if (old_number == resolved_output->origin.nr)
>       -+			oid_array_append(&(resolved_output->origin), &(to_resolve->origin.oid[i]));
>       ++			oid_array_append(&(resolved_output->origin),
>       ++					 &(to_resolve->origin.oid[i]));
>        +	}
>        +
>       -+	/* If no changes were advanced by this metacommit, we'll need to create a new
>       -+	 * one. */
>       ++	/*
>       ++	 * If no changes were advanced by this metacommit, we'll need to create
>       ++	 * a new one. */
>        +	if (to_advance->nr == old_change_list_length) {
>        +		struct strbuf change_name;
>        +
>        +		strbuf_init(&change_name, 80);
>       -+		content = lookup_commit_reference_gently(repo, &(to_resolve->content), 1);
>       ++
>       ++		content = lookup_commit_reference_gently(
>       ++			repo, &(to_resolve->content), 1);
>        +
>        +		compute_change_name(content, &change_name);
>        +		string_list_append(to_advance, change_name.buf);
>       @@ metacommit.c (new)
>        +
>        +	while (--i >= 0) {
>        +		struct object_id *next = &(to_lookup->oid[i]);
>       -+		struct commit *commit = lookup_commit_reference_gently(repo, next, 1);
>       ++		struct commit *commit =
>       ++			lookup_commit_reference_gently(repo, next, 1);
>        +		commit_list_insert(commit, result);
>        +	}
>        +}
>        +
>        +#define PARENT_TYPE_PREFIX "parent-type "
>        +
>       -+/**
>       -+ * Creates a new metacommit object with the given content. Writes the object
>       -+ * id of the newly-created commit to result.
>       -+ */
>        +int write_metacommit(struct repository *repo, struct metacommit_data *state,
>        +	struct object_id *result)
>        +{
>        +	struct commit_list *parents = NULL;
>        +	struct strbuf comment;
>       -+	int i;
>       ++	size_t i;
>        +	struct commit *content;
>        +
>        +	strbuf_init(&comment, strlen(PARENT_TYPE_PREFIX)
>       @@ metacommit.c (new)
>        +		strbuf_addstr(&comment, " o");
>        +
>        +	/* The parents list will be freed by this call. */
>       -+	commit_tree(comment.buf, comment.len, repo->hash_algo->empty_tree, parents,
>       -+		result, NULL, NULL);
>       ++	commit_tree(
>       ++		comment.buf,
>       ++		comment.len,
>       ++		repo->hash_algo->empty_tree,
>       ++		parents,
>       ++		result,
>       ++		NULL,
>       ++		NULL);
>        +
>        +	strbuf_release(&comment);
>        +	return 0;
>        +}
>        +
>       -+/**
>       ++/*
>        + * Returns true iff the given metacommit is abandoned, has one or more origin
>        + * parents, or has one or more replacement parents.
>        + */
>       @@ metacommit.c (new)
>        + * to append to existing changes wherever possible instead of creating new ones.
>        + * If override_change is non-null, only the given change ref will be updated.
>        + *
>       -+ * options is a bitwise combination of the UPDATE_OPTION_* flags.
>       -+ */
>       -+int record_metacommit(
>       -+	struct repository *repo,
>       -+	const struct metacommit_data *metacommit, const char *override_change,
>       -+	int options, struct strbuf *err)
>       -+{
>       -+		struct change_table chtable;
>       -+		struct string_list changes;
>       -+		int result;
>       -+
>       -+		change_table_init(&chtable);
>       -+		change_table_add_all_visible(&chtable, repo);
>       -+		string_list_init_dup(&changes);
>       -+
>       -+		result = record_metacommit_withresult(repo, &chtable, metacommit,
>       -+			override_change, options, err, &changes);
>       -+
>       -+		string_list_clear(&changes, 0);
>       -+		change_table_clear(&chtable);
>       -+		return result;
>       -+}
>       -+
>       -+/*
>       -+ * Records the relationships described by the given metacommit in the
>       -+ * repository.
>       -+ *
>       -+ * If override_change is NULL (the default), an attempt will be made
>       -+ * to append to existing changes wherever possible instead of creating new ones.
>       -+ * If override_change is non-null, only the given change ref will be updated.
>       -+ *
>        + * The changes list is filled in with the list of change refs that were updated,
>        + * with the util pointers pointing to the old object IDS for those changes.
>        + * The object ID pointers all point to objects owned by the change_table and
>       @@ metacommit.c (new)
>        + *
>        + * options is a bitwise combination of the UPDATE_OPTION_* flags.
>        + */
>       -+int record_metacommit_withresult(
>       ++static int record_metacommit_withresult(
>        +	struct repository *repo,
>        +	struct change_table *chtable,
>        +	const struct metacommit_data *metacommit,
>        +	const char *override_change,
>       -+	int options, struct strbuf *err,
>       ++	int options,
>       ++	struct strbuf *err,
>        +	struct string_list *changes)
>        +{
>        +	static const char *msg = "updating change";
>       -+	struct metacommit_data resolved_metacommit;
>       ++	struct metacommit_data resolved_metacommit = METACOMMIT_DATA_INIT;
>        +	struct object_id commit_target;
>        +	struct ref_transaction *transaction = NULL;
>        +	struct change_head *overridden_head;
>        +	const struct object_id *old_head;
>        +
>       -+	int i;
>       ++	size_t i;
>        +	int ret = 0;
>        +	int force = (options & UPDATE_OPTION_FORCE);
>        +
>       -+	init_metacommit_data(&resolved_metacommit);
>       -+
>        +	resolve_metacommit(repo, chtable, metacommit, &resolved_metacommit, changes,
>        +		(options & UPDATE_OPTION_NOAPPEND) == 0);
>        +
>        +	if (override_change) {
>        +		string_list_clear(changes, 0);
>        +		overridden_head = get_change_head(chtable, override_change);
>       -+		if (!overridden_head) {
>       ++		if (overridden_head) {
>        +			/* This is an existing change */
>        +			old_head = &overridden_head->head;
>        +			if (!force) {
>       @@ metacommit.c (new)
>        +			/* ...then this is a newly-created change */
>        +			old_head = null_oid();
>        +
>       -+		/* The expected "current" head of the change is stored in the util
>       -+		 * pointer. */
>       -+		string_list_append(changes, override_change)->util = (void*)old_head;
>       ++		/*
>       ++		 * The expected "current" head of the change is stored in the
>       ++		 * util pointer. Cast required because old_head is const*
>       ++		 */
>       ++		string_list_append(changes, override_change)->util = (void *)old_head;
>        +	}
>        +
>        +	if (is_nontrivial_metacommit(&resolved_metacommit)) {
>       @@ metacommit.c (new)
>        +			ret = -1;
>        +			goto cleanup;
>        +		}
>       -+	} else
>       -+		/**
>       ++	} else {
>       ++		/*
>        +		 * If the metacommit would only contain a content commit, point to the
>        +		 * commit itself rather than creating a trivial metacommit.
>        +		 */
>        +		oidcpy(&commit_target, &(resolved_metacommit.content));
>       ++	}
>        +
>       -+	/**
>       ++	/*
>        +	 * If a change already exists with this target and we're not forcing an
>        +	 * update to some specific override_change && change, there's nothing to do.
>        +	 */
>       @@ metacommit.c (new)
>        +		for (i = 0; i < changes->nr; i++) {
>        +			struct string_list_item *it = &changes->items[i];
>        +
>       -+			/**
>       ++			/*
>        +			 * The expected current head of the change is stored in the util pointer.
>        +			 * It is null if the change should be newly-created.
>        +			 */
>       @@ metacommit.c (new)
>        +	return ret;
>        +}
>        +
>       -+/**
>       -+ * Should be invoked after a command that has "modify" semantics - commands that
>       -+ * create a new commit based on an old commit and treat the new one as a
>       -+ * replacement for the old one. This method records the replacement in the
>       -+ * change graph, such that a future evolve operation will rebase children of
>       -+ * the old commit onto the new commit.
>       -+ */
>       ++int record_metacommit(
>       ++	struct repository *repo,
>       ++	const struct metacommit_data *metacommit,
>       ++	const char *override_change,
>       ++	int options,
>       ++	struct strbuf *err,
>       ++	struct string_list *changes)
>       ++{
>       ++		struct change_table chtable;
>       ++		int result;
>       ++
>       ++		change_table_init(&chtable);
>       ++		change_table_add_all_visible(&chtable, repo);
>       ++
>       ++		result = record_metacommit_withresult(
>       ++			repo,
>       ++			&chtable,
>       ++			metacommit,
>       ++			override_change,
>       ++			options,
>       ++			err,
>       ++			changes);
>       ++
>       ++		change_table_clear(&chtable);
>       ++		return result;
>       ++}
>       ++
>        +void modify_change(
>        +	struct repository *repo,
>        +	const struct object_id *old_commit,
>        +	const struct object_id *new_commit,
>        +	struct strbuf *err)
>        +{
>       -+	struct metacommit_data metacommit;
>       ++	struct string_list changes = STRING_LIST_INIT_DUP;
>       ++	struct metacommit_data metacommit = METACOMMIT_DATA_INIT;
>        +
>       -+	init_metacommit_data(&metacommit);
>        +	oidcpy(&(metacommit.content), new_commit);
>        +	oid_array_append(&(metacommit.replace), old_commit);
>        +
>       -+	record_metacommit(repo, &metacommit, NULL, 0, err);
>       ++	record_metacommit(repo, &metacommit, NULL, 0, err, &changes);
>        +
>        +	clear_metacommit_data(&metacommit);
>       ++	string_list_clear(&changes, 0);
>        +}
>        >         ## metacommit.h (new) ##
>       @@ metacommit.h (new)
>        +#include "repository.h"
>        +#include "string-list.h"
>        +
>       -+
>       -+struct change_table;
>       -+
>        +/* If specified, non-fast-forward changes are permitted. */
>        +#define UPDATE_OPTION_FORCE     0x0001
>        +/**
>       @@ metacommit.h (new)
>        +	int abandoned;
>        +};
>        +
>       -+extern void init_metacommit_data(struct metacommit_data *state);
>       ++#define METACOMMIT_DATA_INIT { 0 }
>        +
>        +extern void clear_metacommit_data(struct metacommit_data *state);
>        +
>       -+extern int record_metacommit(struct repository *repo,
>       -+	const struct metacommit_data *metacommit,
>       -+	const char* override_change, int options, struct strbuf *err);
>       -+
>       -+extern int record_metacommit_withresult(
>       ++/**
>       ++ * Records the relationships described by the given metacommit in the
>       ++ * repository.
>       ++ *
>       ++ * If override_change is NULL (the default), an attempt will be made
>       ++ * to append to existing changes wherever possible instead of creating new ones.
>       ++ * If override_change is non-null, only the given change ref will be updated.
>       ++ *
>       ++ * options is a bitwise combination of the UPDATE_OPTION_* flags.
>       ++ */
>       ++int record_metacommit(
>        +	struct repository *repo,
>       -+	struct change_table *chtable,
>        +	const struct metacommit_data *metacommit,
>       -+	const char *override_change,
>       ++	const char* override_change,
>        +	int options,
>        +	struct strbuf *err,
>        +	struct string_list *changes);
>        +
>       -+extern void modify_change(struct repository *repo,
>       -+	const struct object_id *old_commit, const struct object_id *new_commit,
>       ++/**
>       ++ * Should be invoked after a command that has "modify" semantics - commands that
>       ++ * create a new commit based on an old commit and treat the new one as a
>       ++ * replacement for the old one. This method records the replacement in the
>       ++ * change graph, such that a future evolve operation will rebase children of
>       ++ * the old commit onto the new commit.
>       ++ */
>       ++void modify_change(
>       ++	struct repository *repo,
>       ++	const struct object_id *old_commit,
>       ++	const struct object_id *new_commit,
>        +	struct strbuf *err);
>        +
>       -+extern int write_metacommit(struct repository *repo, struct metacommit_data *state,
>       ++/**
>       ++ * Creates a new metacommit object with the given content. Writes the object
>       ++ * id of the newly-created commit to result.
>       ++ */
>       ++int write_metacommit(
>       ++	struct repository *repo,
>       ++	struct metacommit_data *state,
>        +	struct object_id *result);
>        +
>        +#endif
>    7:  91402834184 !  7:  f7a90700e0e evolve: implement the git change command
>       @@ builtin/change.c (new)
>        +#include "ref-filter.h"
>        +#include "parse-options.h"
>        +#include "metacommit.h"
>       -+#include "change-table.h"
>        +#include "config.h"
>        +
>        +static const char * const builtin_change_usage[] = {
>       -+	N_("git change update [--force] [--replace <treeish>...] [--origin <treesih>...] [--content <newtreeish>]"),
>       ++	N_("git change list [<pattern>...]"),
>       ++	N_("git change update [--force] [--replace <treeish>...] "
>       ++	   "[--origin <treeish>...] [--content <newtreeish>]"),
>       ++	NULL
>       ++};
>       ++
>       ++static const char * const builtin_list_usage[] = {
>       ++	N_("git change list [<pattern>...]"),
>        +	NULL
>        +};
>        +
>        +static const char * const builtin_update_usage[] = {
>       -+	N_("git change update [--force] [--replace <treeish>...] [--origin <treesih>...] [--content <newtreeish>]"),
>       ++	N_("git change update [--force] [--replace <treeish>...] "
>       ++	"[--origin <treeish>...] [--content <newtreeish>]"),
>        +	NULL
>        +};
>        +
>       ++static int change_list(int argc, const char **argv, const char* prefix)
>       ++{
>       ++	struct option options[] = {
>       ++		OPT_END()
>       ++	};
>       ++	struct ref_filter filter = { 0 };
>       ++	struct ref_sorting *sorting;
>       ++	struct string_list sorting_options = STRING_LIST_INIT_DUP;
>       ++	struct ref_format format = REF_FORMAT_INIT;
>       ++	struct ref_array array = { 0 };
>       ++	size_t i;
>       ++
>       ++	argc = parse_options(argc, argv, prefix, options, builtin_list_usage, 0);
>       ++
>       ++	setup_ref_filter_porcelain_msg();
>       ++
>       ++	filter.kind = FILTER_REFS_CHANGES;
>       ++	filter.name_patterns = argv;
>       ++
>       ++	filter_refs(&array, &filter, FILTER_REFS_CHANGES);
>       ++
>       ++	/* TODO: This causes a crash. It sets one of the atom_value handlers to
>       ++	 * something invalid, which causes a crash later when we call
>       ++	 * show_ref_array_item. Figure out why this happens and put back the sorting.
>       ++	 *
>       ++	 * sorting = ref_sorting_options(&sorting_options);
>       ++	 * ref_array_sort(sorting, &array); */
>       ++
>       ++	if (!format.format)
>       ++		format.format = "%(refname:lstrip=1)";
>       ++
>       ++	if (verify_ref_format(&format))
>       ++		die(_("unable to parse format string"));
>       ++
>       ++	sorting = ref_sorting_options(&sorting_options);
>       ++	ref_array_sort(sorting, &array);
>       ++
>       ++
>       ++	for (i = 0; i < array.nr; i++) {
>       ++		struct strbuf output = STRBUF_INIT;
>       ++		struct strbuf err = STRBUF_INIT;
>       ++		if (format_ref_array_item(array.items[i], &format, &output, &err))
>       ++			die("%s", err.buf);
>       ++		fwrite(output.buf, 1, output.len, stdout);
>       ++		putchar('\n');
>       ++
>       ++		strbuf_release(&err);
>       ++		strbuf_release(&output);
>       ++	}
>       ++
>       ++	ref_array_clear(&array);
>       ++	ref_sorting_release(sorting);
>       ++
>       ++	return 0;
>       ++}
>       ++
>        +struct update_state {
>        +	int options;
>        +	const char* change;
>       @@ builtin/change.c (new)
>        +	struct string_list origin;
>        +};
>        +
>       -+static void init_update_state(struct update_state *state)
>       -+{
>       -+	memset(state, 0, sizeof(*state));
>       -+	state->content = "HEAD";
>       -+	string_list_init_nodup(&state->replace);
>       -+	string_list_init_nodup(&state->origin);
>       ++#define UPDATE_STATE_INIT { \
>       ++	.content = "HEAD", \
>       ++	.replace = STRING_LIST_INIT_NODUP, \
>       ++	.origin = STRING_LIST_INIT_NODUP \
>        +}
>        +
>        +static void clear_update_state(struct update_state *state)
>       @@ builtin/change.c (new)
>        +{
>        +	struct commit *commit;
>        +	if (get_oid_committish(committish, result))
>       -+		die(_("Failed to resolve '%s' as a valid revision."), committish);
>       ++		die(_("failed to resolve '%s' as a valid revision."), committish);
>        +	commit = lookup_commit_reference(the_repository, result);
>        +	if (!commit)
>       -+		die(_("Could not parse object '%s'."), committish);
>       ++		die(_("could not parse object '%s'."), committish);
>        +	oidcpy(result, &commit->object.oid);
>        +	return 0;
>        +}
>       @@ builtin/change.c (new)
>        +static void resolve_commit_list(const struct string_list *commitsish_list,
>        +	struct oid_array* result)
>        +{
>       -+	int i;
>       -+	for (i = 0; i < commitsish_list->nr; i++) {
>       -+		struct string_list_item *item = &commitsish_list->items[i];
>       ++	struct string_list_item *item;
>       ++
>       ++	for_each_string_list_item(item, commitsish_list) {
>        +		struct object_id next;
>        +		resolve_commit(item->string, &next);
>        +		oid_array_append(result, &next);
>       @@ builtin/change.c (new)
>        +	const struct update_state *state,
>        +	struct strbuf *err)
>        +{
>       -+	struct metacommit_data metacommit;
>       -+	struct change_table chtable;
>       -+	struct string_list changes;
>       ++	struct metacommit_data metacommit = METACOMMIT_DATA_INIT;
>       ++	struct string_list changes = STRING_LIST_INIT_DUP;
>        +	int ret;
>       -+	int i;
>       -+
>       -+	change_table_init(&chtable);
>       -+	change_table_add_all_visible(&chtable, repo);
>       -+	string_list_init_dup(&changes);
>       -+
>       -+	init_metacommit_data(&metacommit);
>       ++	struct string_list_item *item;
>        +
>        +	get_metacommit_from_command_line(state, &metacommit);
>        +
>       -+	ret = record_metacommit_withresult(repo, &chtable, &metacommit,
>       -+		state->change, state->options, err, &changes);
>       ++	ret = record_metacommit(
>       ++		repo,
>       ++		&metacommit,
>       ++		state->change,
>       ++		state->options,
>       ++		err,
>       ++		&changes);
>        +
>       -+	for (i = 0; i < changes.nr; i++) {
>       -+		struct string_list_item *it = &changes.items[i];
>       ++	for_each_string_list_item(item, &changes) {
>        +
>       -+		const char* name = lstrip_ref_components(it->string, 1);
>       ++		const char* name = lstrip_ref_components(item->string, 1);
>        +		if (!name)
>       -+			die(_("Failed to remove `refs/` from %s"), it->string);
>       ++			die(_("failed to remove `refs/` from %s"), item->string);
>        +
>       -+		if (it->util)
>       -+			fprintf(stdout, N_("Updated change %s\n"), name);
>       ++		if (item->util)
>       ++			fprintf(stdout, _("Updated change %s"), name);
>        +		else
>       -+			fprintf(stdout, N_("Created change %s\n"), name);
>       ++			fprintf(stdout, _("Created change %s"), name);
>       ++		putchar('\n');
>        +	}
>        +
>        +	string_list_clear(&changes, 0);
>       -+	change_table_clear(&chtable);
>        +	clear_metacommit_data(&metacommit);
>        +
>        +	return ret;
>       @@ builtin/change.c (new)
>        +static int change_update(int argc, const char **argv, const char* prefix)
>        +{
>        +	int result;
>       -+	int force = 0;
>       -+	int newchange = 0;
>        +	struct strbuf err = STRBUF_INIT;
>       -+	struct update_state state;
>       ++	struct update_state state = UPDATE_STATE_INIT;
>        +	struct option options[] = {
>        +		{ OPTION_CALLBACK, 'r', "replace", &state, N_("commit"),
>        +			N_("marks the given commit as being obsolete"),
>       @@ builtin/change.c (new)
>        +		{ OPTION_CALLBACK, 'o', "origin", &state, N_("commit"),
>        +			N_("marks the given commit as being the origin of this commit"),
>        +			0, update_option_parse_origin },
>       -+		OPT_BOOL('F', "force", &force,
>       -+			N_("overwrite an existing change of the same name")),
>       ++
>        +		OPT_STRING('c', "content", &state.content, N_("commit"),
>        +				 N_("identifies the new content commit for the change")),
>        +		OPT_STRING('g', "change", &state.change, N_("commit"),
>        +				 N_("name of the change to update")),
>       -+		OPT_BOOL('n', "new", &newchange,
>       -+			N_("create a new change - do not append to any existing change")),
>       ++		OPT_SET_INT_F('n', "new", &state.options,
>       ++			      N_("create a new change - do not append to any existing change"),
>       ++			      UPDATE_OPTION_NOAPPEND, 0),
>       ++		OPT_SET_INT_F('F', "force", &state.options,
>       ++			      N_("overwrite an existing change of the same name"),
>       ++			      UPDATE_OPTION_FORCE, 0),
>        +		OPT_END()
>        +	};
>        +
>       -+	init_update_state(&state);
>       -+
>        +	argc = parse_options(argc, argv, prefix, options, builtin_update_usage, 0);
>       -+
>       -+	if (force) state.options |= UPDATE_OPTION_FORCE;
>       -+	if (newchange) state.options |= UPDATE_OPTION_NOAPPEND;
>       -+
>        +	result = perform_update(the_repository, &state, &err);
>        +
>        +	if (result < 0) {
>       @@ builtin/change.c (new)
>        +
>        +int cmd_change(int argc, const char **argv, const char *prefix)
>        +{
>       ++	parse_opt_subcommand_fn *fn = NULL;
>        +	/* No options permitted before subcommand currently */
>        +	struct option options[] = {
>       ++		OPT_SUBCOMMAND("list", &fn, change_list),
>       ++		OPT_SUBCOMMAND("update", &fn, change_update),
>        +		OPT_END()
>        +	};
>       -+	int result = 1;
>        +
>        +	argc = parse_options(argc, argv, prefix, options, builtin_change_usage,
>       -+		PARSE_OPT_STOP_AT_NON_OPTION);
>       -+
>       -+	if (argc < 1)
>       -+		usage_with_options(builtin_change_usage, options);
>       -+	else if (!strcmp(argv[0], "update"))
>       -+		result = change_update(argc, argv, prefix);
>       -+	else {
>       -+		error(_("Unknown subcommand: %s"), argv[0]);
>       -+		usage_with_options(builtin_change_usage, options);
>       ++		PARSE_OPT_SUBCOMMAND_OPTIONAL);
>       ++
>       ++	if (!fn) {
>       ++		if (argc) {
>       ++			error(_("unknown subcommand: `%s'"), argv[0]);
>       ++			usage_with_options(builtin_change_usage, options);
>       ++		}
>       ++		fn = change_list;
>        +	}
>        +
>       -+	return result ? 1 : 0;
>       ++	return !!fn(argc, argv, prefix);
>        +}
>        >         ## git.c ##
>    9:  d087d467e3f !  8:  a0669fa63a1 evolve: add delete command
>       @@ Commit message
>        >         ## builtin/change.c ##
>        @@
>       + #include "parse-options.h"
>         #include "metacommit.h"
>       - #include "change-table.h"
>         #include "config.h"
>        +#include "refs.h"
>         >         static const char * const builtin_change_usage[] = {
>         	N_("git change list [<pattern>...]"),
>       --	N_("git change update [--force] [--replace <treeish>...] [--origin <treesih>...] [--content <newtreeish>]"),
>       -+	N_("git change update [--force] [--replace <treeish>...] [--origin <treeish>...] [--content <newtreeish>]"),
>       + 	N_("git change update [--force] [--replace <treeish>...] "
>       + 	   "[--origin <treeish>...] [--content <newtreeish>]"),
>        +	N_("git change delete <change-name>..."),
>         	NULL
>         };
>         >       -@@ builtin/change.c: static const char * const builtin_list_usage[] = {
>       +@@ builtin/change.c: static const char * const builtin_update_usage[] = {
>       + 	NULL
>         };
>         >       - static const char * const builtin_update_usage[] = {
>       --	N_("git change update [--force] [--replace <treeish>...] [--origin <treesih>...] [--content <newtreeish>]"),
>       -+	N_("git change update [--force] [--replace <treeish>...] [--origin <treeish>...] [--content <newtreeish>]"),
>       ++static const char * const builtin_delete_usage[] = {
>       ++	N_("git change delete <change-name>..."),
>        +	NULL
>        +};
>        +
>       -+static const char * const builtin_delete_usage[] = {
>       -+	N_("git change delete <change-name>..."),
>       - 	NULL
>       - };
>       -
>       + static int change_list(int argc, const char **argv, const char* prefix)
>       + {
>       + 	struct option options[] = {
>        @@ builtin/change.c: static int change_update(int argc, const char **argv, const char* prefix)
>         	return result;
>         }
>       @@ builtin/change.c: static int change_update(int argc, const char **argv, const ch
>        +
>         int cmd_change(int argc, const char **argv, const char *prefix)
>         {
>       - 	/* No options permitted before subcommand currently */
>       + 	parse_opt_subcommand_fn *fn = NULL;
>        @@ builtin/change.c: int cmd_change(int argc, const char **argv, const char *prefix)
>       - 		result = change_list(argc, argv, prefix);
>       - 	else if (!strcmp(argv[0], "update"))
>       - 		result = change_update(argc, argv, prefix);
>       -+	else if (!strcmp(argv[0], "delete"))
>       -+		result = change_delete(argc, argv, prefix);
>       - 	else {
>       - 		error(_("Unknown subcommand: %s"), argv[0]);
>       - 		usage_with_options(builtin_change_usage, options);
>       + 	struct option options[] = {
>       + 		OPT_SUBCOMMAND("list", &fn, change_list),
>       + 		OPT_SUBCOMMAND("update", &fn, change_update),
>       ++		OPT_SUBCOMMAND("delete", &fn, change_delete),
>       + 		OPT_END()
>       + 	};
>       +
>   10:  811d516e5d2 =  9:  e67ff668fff evolve: add documentation for `git change`
>    8:  b83a79beeb4 ! 10:  37042b58cda evolve: add the git change list command
>       @@
>         ## Metadata ##
>       -Author: Stefan Xenos <sxenos@google.com>
>       +Author: Chris Poucet <poucet@google.com>
>        >         ## Commit message ##
>       -    evolve: add the git change list command
>       +    evolve: add tests for the git-change command
>        >       -    This command lists the ongoing changes from the refs/metas
>       -    namespace.
>       -
>       -    Signed-off-by: Stefan Xenos <sxenos@google.com>
>       +    Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
>            Signed-off-by: Chris Poucet <poucet@google.com>
>        >       - ## builtin/change.c ##
>       + ## t/t9990-changes.sh (new) ##
>        @@
>       - #include "config.h"
>       -
>       - static const char * const builtin_change_usage[] = {
>       -+	N_("git change list [<pattern>...]"),
>       - 	N_("git change update [--force] [--replace <treeish>...] [--origin <treesih>...] [--content <newtreeish>]"),
>       - 	NULL
>       - };
>       -
>       -+static const char * const builtin_list_usage[] = {
>       -+	N_("git change list [<pattern>...]"),
>       -+	NULL
>       -+};
>       ++#!/bin/sh
>        +
>       - static const char * const builtin_update_usage[] = {
>       - 	N_("git change update [--force] [--replace <treeish>...] [--origin <treesih>...] [--content <newtreeish>]"),
>       - 	NULL
>       - };
>       -
>       -+static int change_list(int argc, const char **argv, const char* prefix)
>       -+{
>       -+	struct option options[] = {
>       -+		OPT_END()
>       -+	};
>       -+	struct ref_filter filter;
>       -+	/* TODO: See below
>       -+	struct ref_sorting *sorting;
>       -+	struct string_list sorting_options = STRING_LIST_INIT_DUP; */
>       -+	struct ref_format format = REF_FORMAT_INIT;
>       -+	struct ref_array array;
>       -+	int i;
>       ++test_description='git change - low level meta-commit management'
>        +
>       -+	argc = parse_options(argc, argv, prefix, options, builtin_list_usage, 0);
>       ++. ./test-lib.sh
>        +
>       -+	setup_ref_filter_porcelain_msg();
>       ++. "$TEST_DIRECTORY"/lib-rebase.sh
>        +
>       -+	memset(&filter, 0, sizeof(filter));
>       -+	memset(&array, 0, sizeof(array));
>       ++test_expect_success 'setup commits and meta-commits' '
>       ++       for c in one two three
>       ++       do
>       ++               test_commit $c &&
>       ++               git change update --content $c >actual 2>err &&
>       ++               echo "Created change metas/$c" >expect &&
>       ++               test_cmp expect actual &&
>       ++               test_must_be_empty err &&
>       ++               test_cmp_rev refs/metas/$c $c || return 1
>       ++       done
>       ++'
>        +
>       -+	filter.kind = FILTER_REFS_CHANGES;
>       -+	filter.name_patterns = argv;
>       ++# Check a meta-commit has the correct parents Call with the object
>       ++# name of the meta-commit followed by pairs of type and parent
>       ++check_meta_commit () {
>       ++       name=$1
>       ++       shift
>       ++       while test $# -gt 0
>       ++       do
>       ++               printf '%s %s\n' $1 $(git rev-parse --verify $2)
>       ++               shift
>       ++               shift
>       ++       done | sort >expect
>       ++       git cat-file commit $name >metacommit &&
>       ++       # commit body should consist of parent-type
>       ++           types="$(sed -n '/^$/ {
>       ++                       :loop
>       ++                       n
>       ++                       s/^parent-type //
>       ++                       p
>       ++                       b loop
>       ++                   }' metacommit)" &&
>       ++       while read key value
>       ++       do
>       ++               # TODO: don't sort the first parent
>       ++               if test "$key" = "parent"
>       ++               then
>       ++                       type="${types%% *}"
>       ++                       test -n "$type" || return 1
>       ++                       printf '%s %s\n' $type $value
>       ++                       types="${types#?}"
>       ++                       types="${types# }"
>       ++               elif test "$key" = "tree"
>       ++               then
>       ++                       test_cmp_rev "$value" $EMPTY_TREE || return 1
>       ++               elif test -z "$key"
>       ++               then
>       ++                       # only parse commit headers
>       ++                       break
>       ++               fi
>       ++       done <metacommit >actual-unsorted &&
>       ++       test -z "$types" &&
>       ++       sort >actual <actual-unsorted &&
>       ++       test_cmp expect actual
>       ++}
>        +
>       -+	filter_refs(&array, &filter, FILTER_REFS_CHANGES);
>       ++test_expect_success 'update meta-commits after rebase' '
>       ++       (
>       ++               set_fake_editor &&
>       ++               FAKE_AMEND=edited &&
>       ++               FAKE_LINES="reword 1 pick 2 fixup 3" &&
>       ++               export FAKE_AMEND FAKE_LINES &&
>       ++               git rebase -i --root
>       ++       ) &&
>        +
>       -+	/* TODO: This causes a crash. It sets one of the atom_value handlers to
>       -+	 * something invalid, which causes a crash later when we call
>       -+	 * show_ref_array_item. Figure out why this happens and put back the sorting.
>       -+	 *
>       -+	 * sorting = ref_sorting_options(&sorting_options);
>       -+	 * ref_array_sort(sorting, &array); */
>       ++       # update meta-commits
>       ++       git change update --replace tags/one --content HEAD~1 >out 2>err &&
>       ++       echo "Updated change metas/one" >expect &&
>       ++       test_cmp expect out &&
>       ++       test_must_be_empty err &&
>       ++       git change update --replace tags/two --content HEAD@{2} &&
>       ++       oid=$(git rev-parse --verify metas/two) &&
>       ++       git change update --replace HEAD@{2} --replace tags/three \
>       ++               --content HEAD &&
>        +
>       -+	if (!format.format)
>       -+		format.format = "%(refname:lstrip=1)";
>       ++       # check meta-commits
>       ++       check_meta_commit metas/one c HEAD~1 r tags/one &&
>       ++       check_meta_commit $oid c HEAD@{2} r tags/two &&
>       ++       # NB this checks that "git change update" uses the meta-commit ($oid)
>       ++       #    corresponding to the replaces commit (HEAD@2 above) given on the
>       ++       #    commandline.
>       ++       check_meta_commit metas/two c HEAD r $oid r tags/three &&
>       ++       check_meta_commit metas/three c HEAD r $oid r tags/three
>       ++'
>        +
>       -+	if (verify_ref_format(&format))
>       -+		die(_("unable to parse format string"));
>       ++reset_meta_commits () {
>       ++    for c in one two three
>       ++    do
>       ++       echo "update refs/metas/$c refs/tags/$c^0"
>       ++    done | git update-ref --stdin
>       ++}
>        +
>       -+	for (i = 0; i < array.nr; i++) {
>       -+		struct strbuf output = STRBUF_INIT;
>       -+		struct strbuf err = STRBUF_INIT;
>       -+		if (format_ref_array_item(array.items[i], &format, &output, &err))
>       -+			die("%s", err.buf);
>       -+		fwrite(output.buf, 1, output.len, stdout);
>       -+		putchar('\n');
>       ++test_expect_success 'override change name' '
>       ++       # TODO: builtin/change.c expects --change to be the full refname,
>       ++       #       ideally it would prepend refs/metas to the string given by the
>       ++       #       user.
>       ++       git change update --change refs/metas/another-one --content one &&
>       ++       test_cmp_rev metas/another-one one
>       ++'
>        +
>       -+		strbuf_release(&err);
>       -+		strbuf_release(&output);
>       -+	}
>       ++test_expect_success 'non-fast forward meta-commit update refused' '
>       ++       test_must_fail git change update --change refs/metas/one --content two \
>       ++               >out 2>err &&
>       ++       echo "error: non-fast-forward update to ${SQ}refs/metas/one${SQ}" \
>       ++               >expect &&
>       ++       test_cmp expect err &&
>       ++       test_must_be_empty out
>       ++'
>        +
>       -+	ref_array_clear(&array);
>       -+	/* TODO: see above
>       -+	ref_sorting_release(sorting); */
>       ++test_expect_success 'forced non-fast forward update succeeds' '
>       ++       git change update --change refs/metas/one --content two --force \
>       ++               >out 2>err &&
>       ++       echo "Updated change metas/one" >expect &&
>       ++       test_cmp expect out &&
>       ++       test_must_be_empty err
>       ++'
>        +
>       -+	return 0;
>       -+}
>       ++test_expect_success 'list changes' '
>       ++       cat >expect <<-\EOF &&
>       ++metas/another-one
>       ++metas/one
>       ++metas/three
>       ++metas/two
>       ++EOF
>       ++       git change list >actual &&
>       ++       test_cmp expect actual
>       ++'
>       ++
>       ++test_expect_success 'delete change' '
>       ++       git change delete metas/one &&
>       ++       cat >expect <<-\EOF &&
>       ++metas/another-one
>       ++metas/three
>       ++metas/two
>       ++EOF
>       ++       git change list >actual &&
>       ++       test_cmp expect actual
>       ++'
>        +
>       - struct update_state {
>       - 	int options;
>       - 	const char* change;
>       -@@ builtin/change.c: int cmd_change(int argc, const char **argv, const char *prefix)
>       -
>       - 	if (argc < 1)
>       - 		usage_with_options(builtin_change_usage, options);
>       -+	else if (!strcmp(argv[0], "list"))
>       -+		result = change_list(argc, argv, prefix);
>       - 	else if (!strcmp(argv[0], "update"))
>       - 		result = change_update(argc, argv, prefix);
>       - 	else {
>       ++test_done
> 

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 10, 2022

There are issues in commit bfef56e:
technical doc: Add motivation for the evolve command
Commit checks stopped - the message is too short
Commit not signed off

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 10, 2022

There are issues in commit 7b9118c:
technical doc: Introduce an overview of evolve usage
Commit checks stopped - the message is too short
Commit not signed off

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 10, 2022

There are issues in commit eefd04a:
technical doc: Add detailed design of evolve.
Commit checks stopped - the message is too short
Commit not signed off

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 10, 2022

There are issues in commit 5ba4e42:
Technical doc: Add other options considered for evolve
Commit checks stopped - the message is too short
Commit not signed off

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 10, 2022

There are issues in commit 74d9392:
technical doc: evolve: explain changes to git commands
Commit checks stopped - the message is too short
Commit not signed off

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 10, 2022

There are issues in commit ff773b3:
technical doc: Add motivation for the evolve command
Commit checks stopped - the message is too short
Commit not signed off

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 10, 2022

There are issues in commit 0d67e6f:
technical doc: Introduce an overview of evolve usage
Commit checks stopped - the message is too short
Commit not signed off

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 10, 2022

There are issues in commit 88d7ffa:
technical doc: Add detailed design of evolve.
Commit checks stopped - the message is too short
Commit not signed off

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 10, 2022

There are issues in commit a4c1261:
Technical doc: Add other options considered for evolve
Commit checks stopped - the message is too short
Commit not signed off

@gitgitgadget
Copy link

gitgitgadget bot commented Oct 10, 2022

There are issues in commit 5f204dc:
technical doc: evolve: explain changes to git commands
Commit checks stopped - the message is too short
Commit not signed off

poucet and others added 13 commits October 10, 2022 14:56
Signed-off-by: Stefan Xenos <sxenos@google.com>
Signed-off-by: Chris Poucet <poucet@google.com>
Signed-off-by: Stefan Xenos <sxenos@google.com>
Signed-off-by: Chris Poucet <poucet@google.com>
Signed-off-by: Stefan Xenos <sxenos@google.com>
Signed-off-by: Chris Poucet <poucet@google.com>
Signed-off-by: Stefan Xenos <sxenos@google.com>
Signed-off-by: Chris Poucet <poucet@google.com>
Signed-off-by: Stefan Xenos <sxenos@google.com>
Signed-off-by: Chris Poucet <poucet@google.com>
Implement a "readonly_contains" function for oid_array that won't
sort the array if it is unsorted. This can be used to test containment in
the rare situations where the array order matters.

The function has intentionally been given a name that is more cumbersome
than the "lookup" function, which is what most callers will will want
in most situations.

Signed-off-by: Chris Poucet <poucet@google.com>
The metas namespace will contain refs for changes in progress. Add
support for searching this namespace.

Signed-off-by: Chris Poucet <poucet@google.com>
This patch adds the get_metacommit_content method, which can classify
commits as either metacommits or normal commits, determine whether they
are abandoned, and extract the content commit's object id from the
metacommit.

Signed-off-by: Stefan Xenos <sxenos@google.com>
Signed-off-by: Chris Poucet <poucet@google.com>
A change table stores a list of changes, and supports efficient lookup
from a commit hash to the list of changes that reference that commit
directly.

It can be used to look up content commits or metacommits at the head
of a change, but does not support lookup of commits referenced as part
of the commit history.

Signed-off-by: Stefan Xenos <sxenos@google.com>
Signed-off-by: Chris Poucet <poucet@google.com>
metacommit.c supports the creation of metacommits and
adds the API needed to create and update changes.

Create the "modify_change" function that can be called from modification
commands like "rebase" and "git amend" to record obsolescences in the
change graph.

Create the "record_metacommit" function for recording more complicated
commit relationships in the commit graph.

Create the "write_metacommit" function for low-level creation of
metacommits.

Signed-off-by: Stefan Xenos <sxenos@google.com>
Signed-off-by: Chris Poucet <poucet@google.com>
Implement the git change update command, which
are sufficient for constructing change graphs.

For example, to create a new change (a stable name) that refers to HEAD:

git change update -c HEAD

To record a rebase or amend in the change graph:

git change update -c <new_commit> -r <old_commit>

To record a cherry-pick in the change graph:

git change update -c <new_commit> -o <original_commit>

Signed-off-by: Stefan Xenos <sxenos@google.com>
Signed-off-by: Chris Poucet <poucet@google.com>
Signed-off-by: Chris Poucet <poucet@google.com>
Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Signed-off-by: Chris Poucet <poucet@google.com>
@poucet poucet closed this by deleting the head repository Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants