Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stg push (Rust version) fails #192

Closed
ctmarinas opened this issue Jun 27, 2022 · 1 comment
Closed

stg push (Rust version) fails #192

ctmarinas opened this issue Jun 27, 2022 · 1 comment
Labels
rust Issues affecting the rust branch

Comments

@ctmarinas
Copy link
Member

For some reason, if I do this (on a Linux kernel repository):

$ stg new test1
$ vi Makefile --> some editing
$ stg refresh
$ stg new test2
$ vi Makefile --> some more editing, potentially on the same line
$ stg refresh
$ stg pop -n2
$ stg push test2
error: git diff-tree:

The changes don't need to conflict. I think if it requires a three-way merge it fails to push but doesn't say anything more about how git diff-tree failed.

Additional info:

$ stg --version
Stacked Git 2.0.0-alpha.1
Copyright (C) 2005-2022 StGit authors
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
SPDX-License-Identifier: GPL-2.0-only
git version 2.30.2
@ctmarinas ctmarinas added the rust Issues affecting the rust branch label Jun 27, 2022
@jpgrayson
Copy link
Collaborator

The root of this problem is that StGit is using the --allow-empty option to git apply, which was introduced in git 2.35 (Jan 2022) and thus fails for all git versions <2.35.0.

Using git apply --allow-empty is nice because it allows us to take diffs from external origins (i.e. for import, fold, etc.) and simply apply them. Without --allow-empty, we have to use other means to figure out whether a diff is empty. The trivial approach is the only one currently in our quiver: test whether the diff stream is empty of bytes. The problem with this approach is that a diff stream may reasonably have header/context without any diff hunks. Such a diff stream counts as "empty" to git apply, but has non-zero bytes and thus escapes the trivial emptiness test. Determining whether some non-empty stream of bytes contains valid diff hunks requires a full-fledged diff parser, which is why it is really nice to let git apply do that job.

BUT, I don't think it's reasonable for StGit to drop support for git versions that are less than a year old, so the plan is to stop using git apply --allow-empty.

I need to audit the various code paths that end up using git apply and ensure that empty (no bytes) diffs are accounted for upstream of git apply. For cases where diffs are generated internally, we can test tree ids to determine whether a diff will be empty or not before applying it. For cases where the diff comes from an external source, empty-ish patches will behave more similarly to the Python implementation.

I have also figured out why the error is misapplied to git diff-tree instead of git apply and have a repair for that.

jpgrayson added a commit that referenced this issue Jul 6, 2022
The --allow-empty option to `git apply` is relatively new, first appearing
in git 2.35.0. Although its behavior is pretty ideal for many StGit
applications, it needs to be avoided to maintain compatibility with (only
slightly) older git versions.

Also repair the related issue where the failure of the `git apply` command
was misattributed to `git diff-tree`. This could occur in cases where the
output of a diff-tree process was routed to the stdin of an apply process.
The solution is to explicitly test the return status of the downstream
apply process before testing the status of the upstream diff-tree process.

Repairs #192
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rust Issues affecting the rust branch
Projects
None yet
Development

No branches or pull requests

2 participants