mbox series

[v2,0/4] Importing and exporting stashes to refs

Message ID 20220329214941.2018609-1-sandals@crustytoothpaste.net (mailing list archive)
Headers show
Series Importing and exporting stashes to refs | expand

Message

brian m. carlson March 29, 2022, 9:49 p.m. UTC
Stashes are currently stored using the reflog in a given repository.
This is an interesting and novel way to handle them, but there is no way
to easily move a stash across machines.  For example, stashes cannot be
bundled, pushed, or fetched.

Let's solve this problem by allowing users to import and export stashes
to a chain of commits.  The commits used in a stash export contain two
parents: one which is the pointer to the next exported stash (or to an
empty commit with no parents if there are no more) and the second is the
stash commit that would normally be stored in the reflog.

We now produce completely reproducible exports by creating the base
commit with predictable author and committer names and timestamps.
The timestamp is arbitrary but picked to be the same as the one used by
format-patch.

We also now avoid size_t.  Because of the constraints of portability, we
can't have nice things like %zu, so now we use int.  Parties wanting to
import or export more than 2 billion stashes are welcome to send a patch
improving the situation.  While I have many stashes, I'm at least a
billion or so away from that point, so I'm going to punt that to a
future series.

Changes from v1:
* Change storage format as suggested by Junio.
* Rename to GIT_OID_GENTLY.
* Remove unnecessary initializations.
* Use ALLOC_GROW_BY.
* Ensure completely reproducible exports.
* Avoid size_t.
* Various other code cleanups.

brian m. carlson (4):
  object-name: make get_oid quietly return an error
  builtin/stash: factor out revision parsing into a function
  builtin/stash: provide a way to export stashes to a ref
  builtin/stash: provide a way to import stashes from a ref

 Documentation/git-stash.txt |  29 +++-
 builtin/stash.c             | 324 ++++++++++++++++++++++++++++++++++--
 cache.h                     |   1 +
 object-name.c               |   6 +-
 t/t3903-stash.sh            |  52 ++++++
 5 files changed, 397 insertions(+), 15 deletions(-)

Comments

Junio C Hamano March 31, 2022, 1:48 a.m. UTC | #1
"brian m. carlson" <sandals@crustytoothpaste.net> writes:

> brian m. carlson (4):
>   object-name: make get_oid quietly return an error
>   builtin/stash: factor out revision parsing into a function
>   builtin/stash: provide a way to export stashes to a ref
>   builtin/stash: provide a way to import stashes from a ref
>
>  Documentation/git-stash.txt |  29 +++-
>  builtin/stash.c             | 324 ++++++++++++++++++++++++++++++++++--
>  cache.h                     |   1 +
>  object-name.c               |   6 +-
>  t/t3903-stash.sh            |  52 ++++++
>  5 files changed, 397 insertions(+), 15 deletions(-)

Merged to 'seen', t3903 seems to have a handful of breakages.
e.g. https://github.com/git/git/runs/5763421702?check_suite_focus=true

Thanks.
Ævar Arnfjörð Bjarmason March 31, 2022, 2:18 a.m. UTC | #2
On Wed, Mar 30 2022, Junio C Hamano wrote:

> "brian m. carlson" <sandals@crustytoothpaste.net> writes:
>
>> brian m. carlson (4):
>>   object-name: make get_oid quietly return an error
>>   builtin/stash: factor out revision parsing into a function
>>   builtin/stash: provide a way to export stashes to a ref
>>   builtin/stash: provide a way to import stashes from a ref
>>
>>  Documentation/git-stash.txt |  29 +++-
>>  builtin/stash.c             | 324 ++++++++++++++++++++++++++++++++++--
>>  cache.h                     |   1 +
>>  object-name.c               |   6 +-
>>  t/t3903-stash.sh            |  52 ++++++
>>  5 files changed, 397 insertions(+), 15 deletions(-)
>
> Merged to 'seen', t3903 seems to have a handful of breakages.
> e.g. https://github.com/git/git/runs/5763421702?check_suite_focus=true

One is a segfault because of a missing STRBUF_INIT:
	
	diff --git a/builtin/stash.c b/builtin/stash.c
	index 7cab57bbe4b..92a1682941c 100644
	--- a/builtin/stash.c
	+++ b/builtin/stash.c
	@@ -1931,7 +1931,7 @@ static int do_export_stash(const char *ref, size_t argc, const char **argv)
	 	struct object_id *items = NULL;
	 	int nitems = 0, nalloc = 0;
	 	int res = 0;
	-	struct strbuf revision;
	+	struct strbuf revision = STRBUF_INIT;
	 	const char *author, *committer;
	 
	 	/*