From: ZheNing Hu <adlternative@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Taylor Blau <me@ttaylorr.com>,
Christian Couder <christian.couder@gmail.com>,
Git List <git@vger.kernel.org>
Subject: Re: [QUESTION] how to diff one blob with nothing
Date: Sat, 5 Aug 2023 16:27:06 +0800 [thread overview]
Message-ID: <CAOLTT8SBAb8bAV3uCPJ-q2btNeatMjmtRzDkRASffN5xTS1M0g@mail.gmail.com> (raw)
In-Reply-To: <xmqqmsz6ljk4.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> 于2023年8月5日周六 03:00写道:
>
> Taylor Blau <me@ttaylorr.com> writes:
>
> > On Fri, Aug 04, 2023 at 10:28:53AM +0200, Christian Couder wrote:
> >> On Fri, Aug 4, 2023 at 6:42 AM ZheNing Hu <adlternative@gmail.com> wrote:
> >>
> >> > Actually, there is no need to support a default empty blob.
> >> > For example, with the command "git diff --no-index <file> /dev/null",
> >> > it can compare a file with /dev/null, but it can only compare <file>
> >> > and not <oid>.
> >> > Therefore, using commands like "git diff <oid> /dev/null",
> >> > "git diff --no-index <oid> /dev/null", or even "git diff <oid> --stdin"
> >> > could potentially solve this issue.
> >>
> >> Maybe it would be clearer to have a new option, called for example
> >> "--blob-vs-file", for that then. It could support both:
> >>
> >> $ git diff --blob-vs-file <blob> <file>
> >>
> >> and:
> >>
> >> $ git diff --blob-vs-file <file> <blob>
> >
> > Hmm. This feels like a case of trying to teach 'git diff' to do too
> > much.
>
> Worse yet, I do not quite get the original use case in the first
> place. What is the series of diff output that result in comparing a
> random pair of blob object names going to be used for?
>
> The reply to <ZMKtcaN7xYaTtkcI@nand.local> says that the original
> use case was to express the evolution of a single path since its
> creation until its removal, but the thing is, a diff with an empty
> blob and a creation or a deletion event are expressed differently in
> the patch output, exactly because the patch has to be able to
> express "before this change, a file with zero byte content was
> there" and "before this change, there was nothing at this path"
> (vice versa for contents-removal vs deletion).
>
> For that reason, I have a hard time to find any merit in the earlier
> complaint that said "can be achieved by manually adding them, but it
> is not very compatible with the original logic", whatever the
> "original logic" refers to. If creation needs to be recorded as
> creation and not as a change from an empty and existing blob, there
> has to be something that needs to be manually done to turn the
> latter (which is the only thing "diff" between two blobs or even a
> blob and a file can give) into the former *anyway*. Whatever the
> thing that is looping over the history/evoluation of a single path
> needs to have a three-arm switch for each iteration to deal with
> creation, modification, and removal, and iterating over the contents
> of the files and prefixing "+" or "-" on each and every line would
> be the _easiest_ part of such a necessary tweak to turn "diff
> between an empty contents and something else" into "creation or
> deletion of a file."
>
Okay, let me clarify the background for using an empty blob diff.
Essentially, it is a git web diff interface that requires real-time calculation
of the diff between files across multiple versions and rendering them.
Due to some reasons, the higher-level component did not provide multiple
versions of commits but instead provided blob OIDs (Object IDs).
Therefore, I expected to generate the diff results directly using the
"git diff <oid> <oid>" command. (I only care about the patch part
in the diff and don't really care about the related information of OIDs
in the diff output.) Everything went smoothly except when a blob
is created or deleted, as there is no direct way to obtain
the diff for a blob using the "git diff <oid> <oid>" interface. Initially,
I intended to generate a patch by diffing an empty blob
(e69de29bb2d1d6434b8b29ae775ad8c2e48c5391) with the blob ID.
However, unlike the empty tree (4b825dc642cb6eb9a060e54bf8d69288fbee4904),
the empty blob does not exist in the git repository by default.
I had to create an additional empty blob for the purpose of performing
the diff, but this goes against the design of the web-based diff interface,
which is intended to be read-only.
So, I might explore methods like "git diff <oid> /dev/null" or
"git diff <oid> --stdin", they are read only, but it does not
currently exist...
Regardless, I hope that the empty blob diff can simulate the effect of
an empty tree diff:
git diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904
diff --git a/.cirrus.yml b/.cirrus.yml
new file mode 100644
index 0000000000..4860bebd32
--- /dev/null
+++ b/.cirrus.yml
@@ -0,0 +1,22 @@
+env:
+ CIRRUS_CLONE_DEPTH: 1
+
+freebsd_12_task:
+ env:
+ GIT_PROVE_OPTS: "--timer --jobs 10"
+ GIT_TEST_OPTS: "--no-chain-lint --no-bin-wrappers"
+ MAKEFLAGS: "-j4"
+ DEFAULT_TEST_TARGET: prove
+ DEVELOPER: 1
+ freebsd_instance:
+ image_family: freebsd-12-3
+ memory: 2G
+ install_script:
+ pkg install -y gettext gmake perl5
+ create_user_script:
+ - pw useradd git
+ - chown -R git:git .
+ build_script:
+ - su git -c gmake
+ test_script:
+ - su git -c 'gmake test'
Thanks,
ZheNing Hu
next prev parent reply other threads:[~2023-08-05 8:27 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-19 9:59 [QUESTION] how to diff one blob with nothing ZheNing Hu
2023-07-19 16:15 ` Junio C Hamano
2023-07-26 18:00 ` ZheNing Hu
2023-07-26 18:23 ` Junio C Hamano
2023-07-27 17:46 ` Taylor Blau
2023-07-28 3:40 ` ZheNing Hu
2023-08-03 5:16 ` ZheNing Hu
2023-08-03 15:24 ` Taylor Blau
2023-08-04 2:28 ` ZheNing Hu
2023-08-04 8:28 ` Christian Couder
2023-08-04 18:34 ` Taylor Blau
2023-08-04 19:00 ` Junio C Hamano
2023-08-05 8:27 ` ZheNing Hu [this message]
2023-07-27 17:13 ` Konstantin Khomoutov
2023-07-28 3:35 ` ZheNing Hu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAOLTT8SBAb8bAV3uCPJ-q2btNeatMjmtRzDkRASffN5xTS1M0g@mail.gmail.com \
--to=adlternative@gmail.com \
--cc=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=me@ttaylorr.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).