]> git.ipfire.org Git - thirdparty/git.git/commit
bundle: arguments can be read from stdin
authorJiang Xin <zhiyou.jx@alibaba-inc.com>
Tue, 12 Jan 2021 02:27:03 +0000 (21:27 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 12 Jan 2021 05:50:41 +0000 (21:50 -0800)
commit5bb0fd2cab5a18bc188c8154097857f51a0e9feb
treeac6801a1892609e2da0ab5d767d4af6225ba0210
parentce1d6d9f1641d87a66c3933255531ee2c15d3143
bundle: arguments can be read from stdin

In order to create an incremental bundle, we need to pass many arguments
to let git-bundle ignore some already packed commits.  It will be more
convenient to pass args via stdin.  But the current implementation does
not allow us to do this.

This is because args are parsed twice when creating bundle.  The first
time for parsing args is in `compute_and_write_prerequisites()` by
running `git-rev-list` command to write prerequisites in bundle file,
and stdin is consumed in this step if "--stdin" option is provided for
`git-bundle`.  Later nothing can be read from stdin when running
`setup_revisions()` in `create_bundle()`.

The solution is to parse args once by removing the entire function
`compute_and_write_prerequisites()` and then calling function
`setup_revisions()`.  In order to write prerequisites for bundle, will
call `prepare_revision_walk()` and `traverse_commit_list()`.  But after
calling `prepare_revision_walk()`, the object array `revs.pending` is
left empty, and the following steps could not work properly with the
empty object array (`revs.pending`).  Therefore, make a copy of `revs`
to `revs_copy` for later use right after calling `setup_revisions()`.

The copy of `revs_copy` is not a deep copy, it shares the same objects
with `revs`. The object array of `revs` has been cleared, but objects
themselves are still kept.  Flags of objects may change after calling
`prepare_revision_walk()`, we can use these changed flags without
calling the `git rev-list` command and parsing its output like the
former implementation.

Also add testcases for git bundle in t6020, which read args from stdin.

Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
bundle.c
t/t5607-clone-bundle.sh
t/t6020-bundle-misc.sh