* git-note -C changes commit type?
@ 2014-02-11 17:23 Joachim Breitner
2014-02-11 23:52 ` Johan Herland
0 siblings, 1 reply; 11+ messages in thread
From: Joachim Breitner @ 2014-02-11 17:23 UTC (permalink / raw)
To: git
[-- Attachment #1: Type: text/plain, Size: 1321 bytes --]
Hi,
judging from the documentation I got the impression that I can pass any
git object has to "git note -C <hash>" and it would stored as-is. But it
seems the objects gets mangled somehow...
(I want to attach a commit object as a note, to reference the history of
a feature before the final cleanup rebase. For that I turn the reflog
into a series of commits, and the final commit is the one I want to
store there.)
$ mkdir foo
$ cd foo/
$ echo foo > a
$ git init
Initialisierte leeres Git-Repository in /tmp/foo/.git/
$ git add a
$ git commit -m 'A commit'
[master (Basis-Commit) 3d7de37] A commit
1 file changed, 1 insertion(+)
create mode 100644 a
$ echo foo2 > a
$ git commit -m 'A commit 2' -a
[master e1bfac4] A commit 2
1 file changed, 1 insertion(+), 1 deletion(-)
$ git notes --ref history add -C 3d7de37 e1bfac4
$ git ls-tree notes/history
100644 blob 5b73d5152e6207e3a2b67e57ca3a2cb94d12061e e1bfac434ebd3135a3784f6fc802f235098eebd0
I was expecting 3d7de37 to be referenced here.
Is that a bug, or is storing commits as notes not supported?
Thanks,
Joachim
--
Joachim “nomeata” Breitner
mail@joachim-breitner.de • http://www.joachim-breitner.de/
Jabber: nomeata@joachim-breitner.de • GPG-Key: 0x4743206C
Debian Developer: nomeata@debian.org
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: git-note -C changes commit type?
2014-02-11 17:23 git-note -C changes commit type? Joachim Breitner
@ 2014-02-11 23:52 ` Johan Herland
2014-02-12 0:06 ` Junio C Hamano
2014-02-12 8:53 ` git-note -C changes commit type? Joachim Breitner
0 siblings, 2 replies; 11+ messages in thread
From: Johan Herland @ 2014-02-11 23:52 UTC (permalink / raw)
To: Joachim Breitner; +Cc: Git mailing list
On Tue, Feb 11, 2014 at 6:23 PM, Joachim Breitner
<mail@joachim-breitner.de> wrote:
> Hi,
>
> judging from the documentation I got the impression that I can pass any
> git object has to "git note -C <hash>" and it would stored as-is. But it
> seems the objects gets mangled somehow...
...well... the documentation does not say "any object", it actually
explicitly says "blob object"... ;)
> (I want to attach a commit object as a note, to reference the history of
> a feature before the final cleanup rebase. For that I turn the reflog
> into a series of commits, and the final commit is the one I want to
> store there.)
>
> $ mkdir foo
> $ cd foo/
> $ echo foo > a
> $ git init
> Initialisierte leeres Git-Repository in /tmp/foo/.git/
> $ git add a
> $ git commit -m 'A commit'
> [master (Basis-Commit) 3d7de37] A commit
> 1 file changed, 1 insertion(+)
> create mode 100644 a
> $ echo foo2 > a
> $ git commit -m 'A commit 2' -a
> [master e1bfac4] A commit 2
> 1 file changed, 1 insertion(+), 1 deletion(-)
> $ git notes --ref history add -C 3d7de37 e1bfac4
> $ git ls-tree notes/history
> 100644 blob 5b73d5152e6207e3a2b67e57ca3a2cb94d12061e e1bfac434ebd3135a3784f6fc802f235098eebd0
>
> I was expecting 3d7de37 to be referenced here.
>
> Is that a bug, or is storing commits as notes not supported?
I guess it depends on your POV... The current documentation says "blob
object", and what actually happens (in builtin/notes.c) is that the
given object (3d7de37 in your example) is read into a strbuf (in
parse_reuse_arg()) and stored back into a note object (in
create_note()), without preserving the object type ("blob" type is
hardcoded). This means an incoming blob object (as documented) will be
preserved (i.e. reuse the same SHA-1), but for any other object type,
the object bits will be read, and stored back into a blob object. This
is why your commit (or any other non-blob) ends up with a different
SHA-1 when stored as a note: It is the same bytes, but in a blob
object instead of a commit object.
There is currently no way the "git notes" commands will allow you to
store the 3d7de37 commit object directly as a note. There is also
(AFAICS) no easy workaround (git fast-import could've been a
workaround if it did not already require the first N/notemodify
argument to be a blob object). The best alternative, off the top of my
head, would be to write your own program using the notes.h API to
manipulate the notes tree directly (or - suboptimally - use other
low-level Git operations to do the same).
However before you go there, let's take a step back, and look at what
the result would look like (if you were allowed to store a commit
object directly as a note):
You would have a notes ref "refs/notes/history" whose tree would
contain an entry named e1bfac434ebd3135a3784f6fc802f235098eebd0
pointing to a _commit_ (3d7de37...). Obviously, it would not make
sense to use refs/notes/history while displaying the commit log ("git
log --notes=history"), as the raw commit object would be shown in the
log. However, more fundamentally: a tree referring to a _commit_ is
usually how Git stores _submodule_ links (i.e. which revision of the
named submodule is to be used by this super-repo tree), and I'm (off
the top of my head) not at all sure that such a submodule link in a
notes tree is handled "sanely" by Git - or even that it makes sense at
all. For one, I'm not sure that Git requires (or even expects) the
commit object referenced by a tree to be present in the same object
DB. So if you share your notes, I don't know whether or not the
fetch/push machinery will include the commit object in the shared
notes... These are questions that should be answered before we decide
whether using commits directly as notes makes sense.
If we do figure out that storing commits as note objects is desirable
(and does not have too nasty side-effects), then I am not opposed to
fixing builtin/notes.c to preserve type of the object passed in -C.
Certainly, the current behavior for non-blobs (i.e. copy the object
bytes, but not the object type) is probably not useful to anyone...
That said, there may be other ways to solve your immediate problem:
Instead of storing the commit object directly as a note, you could
store the commit SHA-1 into a blob, and use that as the blob object.
That would also allow you to store multiple commits in the note for
e1bfac4 (in case you had several cleanup rebases leading to the final
commit), or you could store other kinds of metadata in the same note.
Or do you have a requirement that the reflog history (presumably
reachable from 3d7de37) need to be shared (or otherwise kept
reachable)? In that case, you might be better off using an explicit
ref to keep that history alive; e.g. you could create
refs/history/e1bfac4 to point to 3d7de37 ("git update-ref
refs/history/e1bfac4 3d7de37"), and keep everything
alive/reachable/shareable that way...
Hope this helps,
...Johan
--
Johan Herland, <johan@herland.net>
www.herland.net
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: git-note -C changes commit type?
2014-02-11 23:52 ` Johan Herland
@ 2014-02-12 0:06 ` Junio C Hamano
2014-02-12 5:16 ` Kyle J. McKay
2014-02-12 9:50 ` Johan Herland
2014-02-12 8:53 ` git-note -C changes commit type? Joachim Breitner
1 sibling, 2 replies; 11+ messages in thread
From: Junio C Hamano @ 2014-02-12 0:06 UTC (permalink / raw)
To: Johan Herland; +Cc: Joachim Breitner, Git mailing list
Johan Herland <johan@herland.net> writes:
> There is currently no way the "git notes" commands will allow you to
> store the 3d7de37 commit object directly as a note. There is also
> (AFAICS) no easy workaround (git fast-import could've been a
> workaround if it did not already require the first N/notemodify
> argument to be a blob object). The best alternative, off the top of my
> head, would be to write your own program using the notes.h API to
> manipulate the notes tree directly (or - suboptimally - use other
> low-level Git operations to do the same).
Even worse. I do not think such a non-blob object in the notes tree
does not participate in the reachability at all, so you won't be
able to fetch "refs/notes/whatever" and expect to get a useful
result. I do not think storing the raw bits of commit object as a
blob in the notes tree is useful behaviour, either. The command
probably should refuse to get anything non-blob via that option.
Perhaps the notes entry should just note the object name of whatever
commit it wants to refer to in a *blob*?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: git-note -C changes commit type?
2014-02-12 0:06 ` Junio C Hamano
@ 2014-02-12 5:16 ` Kyle J. McKay
2014-02-12 9:50 ` Johan Herland
1 sibling, 0 replies; 11+ messages in thread
From: Kyle J. McKay @ 2014-02-12 5:16 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Johan Herland, Joachim Breitner, Git mailing list
On Feb 11, 2014, at 16:06, Junio C Hamano wrote:
> Johan Herland <johan@herland.net> writes:
>
>> There is currently no way the "git notes" commands will allow you to
>> store the 3d7de37 commit object directly as a note. There is also
>> (AFAICS) no easy workaround (git fast-import could've been a
>> workaround if it did not already require the first N/notemodify
>> argument to be a blob object). The best alternative, off the top of
>> my
>> head, would be to write your own program using the notes.h API to
>> manipulate the notes tree directly (or - suboptimally - use other
>> low-level Git operations to do the same).
>
> Even worse. I do not think such a non-blob object in the notes tree
> does not participate in the reachability at all, so you won't be
> able to fetch "refs/notes/whatever" and expect to get a useful
> result. I do not think storing the raw bits of commit object as a
> blob in the notes tree is useful behaviour, either. The command
> probably should refuse to get anything non-blob via that option.
It would be nice if it let you store a tree or a blob, but I agree
that it should complain about anything non-blob by default and if tree
were to be allowed, that should require a special option.
If you do manually construct a notes tree that has a 'tree' entry
instead of a blob, as soon as you add a new note, that 'tree' gets
turned back into a blob again. I was trying to attach a 'tree' as my
note a while back and decided not to pursue it further after I found
it got transformed into a 'blob' on the next notes modification.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: git-note -C changes commit type?
2014-02-11 23:52 ` Johan Herland
2014-02-12 0:06 ` Junio C Hamano
@ 2014-02-12 8:53 ` Joachim Breitner
2014-02-12 10:26 ` Johan Herland
1 sibling, 1 reply; 11+ messages in thread
From: Joachim Breitner @ 2014-02-12 8:53 UTC (permalink / raw)
To: Johan Herland; +Cc: Git mailing list
[-- Attachment #1: Type: text/plain, Size: 3046 bytes --]
Dear Johan,
Am Mittwoch, den 12.02.2014, 00:52 +0100 schrieb Johan Herland:
> On Tue, Feb 11, 2014 at 6:23 PM, Joachim Breitner
> <mail@joachim-breitner.de> wrote:
> > judging from the documentation I got the impression that I can pass any
> > git object has to "git note -C <hash>" and it would stored as-is. But it
> > seems the objects gets mangled somehow...
>
> ...well... the documentation does not say "any object", it actually
> explicitly says "blob object"... ;)
ok, my bad; guess I’m not fully versed with gits terminology.
> You would have a notes ref "refs/notes/history" whose tree would
> contain an entry named e1bfac434ebd3135a3784f6fc802f235098eebd0
> pointing to a _commit_ (3d7de37...). Obviously, it would not make
> sense to use refs/notes/history while displaying the commit log ("git
> log --notes=history"), as the raw commit object would be shown in the
> log. However, more fundamentally: a tree referring to a _commit_ is
> usually how Git stores _submodule_ links (i.e. which revision of the
> named submodule is to be used by this super-repo tree), and I'm (off
> the top of my head) not at all sure that such a submodule link in a
> notes tree is handled "sanely" by Git - or even that it makes sense at
> all. For one, I'm not sure that Git requires (or even expects) the
> commit object referenced by a tree to be present in the same object
> DB. So if you share your notes, I don't know whether or not the
> fetch/push machinery will include the commit object in the shared
> notes... These are questions that should be answered before we decide
> whether using commits directly as notes makes sense.
If that is the case, then my approach is indeed flawed. The main point
of the exercise is to have a tree that follows another commit (or, as a
next-best approximation, a note attached to that commit) around.
> In that case, you might be better off using an explicit
> ref to keep that history alive; e.g. you could create
> refs/history/e1bfac4 to point to 3d7de37 ("git update-ref
> refs/history/e1bfac4 3d7de37"), and keep everything
> alive/reachable/shareable that way...
That’s an interesting idea; instead of relying on the notes feature
putting the hash in the ref name. But I wonder how that scales – imagine
every second feature merged into Linux¹ also having such a history ref?
I guess having a way for a tree to reference commits in a way that is
followed by git gc, i.e. separate from submodules, would allow a less
noisy implementation, and possibly create the opportunity for many other
strange uses of git :-)
Greetings,
Joachim
¹ I’m not proposing for anyone else but me to use this, at the moment,
don’t worry :-). But I am considering to use it in the context of GHC,
which isn’t a small project either.
--
Joachim “nomeata” Breitner
mail@joachim-breitner.de • http://www.joachim-breitner.de/
Jabber: nomeata@joachim-breitner.de • GPG-Key: 0x4743206C
Debian Developer: nomeata@debian.org
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: git-note -C changes commit type?
2014-02-12 0:06 ` Junio C Hamano
2014-02-12 5:16 ` Kyle J. McKay
@ 2014-02-12 9:50 ` Johan Herland
2014-02-12 9:54 ` [PATCH] notes: Disallow reusing non-blob as a note object Johan Herland
1 sibling, 1 reply; 11+ messages in thread
From: Johan Herland @ 2014-02-12 9:50 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Joachim Breitner, Git mailing list
On Wed, Feb 12, 2014 at 1:06 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Johan Herland <johan@herland.net> writes:
>> There is currently no way the "git notes" commands will allow you to
>> store the 3d7de37 commit object directly as a note. There is also
>> (AFAICS) no easy workaround (git fast-import could've been a
>> workaround if it did not already require the first N/notemodify
>> argument to be a blob object). The best alternative, off the top of my
>> head, would be to write your own program using the notes.h API to
>> manipulate the notes tree directly (or - suboptimally - use other
>> low-level Git operations to do the same).
>
> Even worse. I do not think such a non-blob object in the notes tree
> does not participate in the reachability at all, so you won't be
> able to fetch "refs/notes/whatever" and expect to get a useful
> result.
s/non-blob/non-(blob-or-tree)/
Any object type that is deemed reachable by reference from a regular
git tree object will also be usable (as far as reachability goes) in a
notes tree.
> I do not think storing the raw bits of commit object as a
> blob in the notes tree is useful behaviour, either. The command
> probably should refuse to get anything non-blob via that option.
Patch coming up...
> Perhaps the notes entry should just note the object name of whatever
> commit it wants to refer to in a *blob*?
Agreed.
...Johan
--
Johan Herland, <johan@herland.net>
www.herland.net
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH] notes: Disallow reusing non-blob as a note object
2014-02-12 9:50 ` Johan Herland
@ 2014-02-12 9:54 ` Johan Herland
2014-02-14 15:19 ` Eric Sunshine
0 siblings, 1 reply; 11+ messages in thread
From: Johan Herland @ 2014-02-12 9:54 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Joachim Breitner, Kyle J. McKay, Johan Herland
Currently "git notes add -C $object" will read the raw bytes from $object,
and then copy those bytes into the note object, which is hardcoded to be
of type blob. This means that if the given $object is a non-blob (e.g.
tree or commit), the raw bytes from that object is copied into a blob
object. This is probably not useful, and certainly not what any sane
user would expect. So disallow it, by erroring out if the $object passed
to the -C option is not a blob.
The fix also applies to the -c option (in which the user is prompted to
edit/verify the note contents in a text editor), and also when -c/-C is
passed to "git notes append" (which appends the $object contents to an
existing note object). In both cases, passing a non-blob $object does not
make sense.
Also add a couple of tests demonstrating expected behavior.
Suggested-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Johan Herland <johan@herland.net>
---
builtin/notes.c | 6 +++++-
t/t3301-notes.sh | 27 +++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/builtin/notes.c b/builtin/notes.c
index 2b24d05..bb89930 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -269,7 +269,11 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
die(_("Failed to resolve '%s' as a valid ref."), arg);
if (!(buf = read_sha1_file(object, &type, &len)) || !len) {
free(buf);
- die(_("Failed to read object '%s'."), arg);;
+ die(_("Failed to read object '%s'."), arg);
+ }
+ if (type != OBJ_BLOB) {
+ free(buf);
+ die(_("Cannot read note data from non-blob object '%s'."), arg);
}
strbuf_add(&(msg->buf), buf, len);
free(buf);
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index 16de05a..3bb79a4 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -812,6 +812,33 @@ test_expect_success 'create note from non-existing note with "git notes add -C"
test_must_fail git notes list HEAD
'
+test_expect_success 'create note from non-blob with "git notes add -C" fails' '
+ commit=$(git rev-parse --verify HEAD) &&
+ tree=$(git rev-parse --verify HEAD:) &&
+ test_must_fail git notes add -C $commit &&
+ test_must_fail git notes add -C $tree &&
+ test_must_fail git notes list HEAD
+'
+
+cat > expect << EOF
+commit 80d796defacd5db327b7a4e50099663902fbdc5c
+Author: A U Thor <author@example.com>
+Date: Thu Apr 7 15:20:13 2005 -0700
+
+ 8th
+
+Notes (other):
+ This is a blob object
+EOF
+
+test_expect_success 'create note from blob with "git notes add -C" reuses blob id' '
+ blob=$(echo "This is a blob object" | git hash-object -w --stdin) &&
+ git notes add -C $blob &&
+ git log -1 > actual &&
+ test_cmp expect actual &&
+ test "$(git notes list HEAD)" = "$blob"
+'
+
cat > expect << EOF
commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b
Author: A U Thor <author@example.com>
--
1.8.4.653.g2df02b3
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: git-note -C changes commit type?
2014-02-12 8:53 ` git-note -C changes commit type? Joachim Breitner
@ 2014-02-12 10:26 ` Johan Herland
2014-02-12 10:33 ` Joachim Breitner
0 siblings, 1 reply; 11+ messages in thread
From: Johan Herland @ 2014-02-12 10:26 UTC (permalink / raw)
To: Joachim Breitner; +Cc: Git mailing list
On Wed, Feb 12, 2014 at 9:53 AM, Joachim Breitner
<mail@joachim-breitner.de> wrote:
> Am Mittwoch, den 12.02.2014, 00:52 +0100 schrieb Johan Herland:
>> You would have a notes ref "refs/notes/history" whose tree would
>> contain an entry named e1bfac434ebd3135a3784f6fc802f235098eebd0
>> pointing to a _commit_ (3d7de37...). Obviously, it would not make
>> sense to use refs/notes/history while displaying the commit log ("git
>> log --notes=history"), as the raw commit object would be shown in the
>> log. However, more fundamentally: a tree referring to a _commit_ is
>> usually how Git stores _submodule_ links (i.e. which revision of the
>> named submodule is to be used by this super-repo tree), and I'm (off
>> the top of my head) not at all sure that such a submodule link in a
>> notes tree is handled "sanely" by Git - or even that it makes sense at
>> all. For one, I'm not sure that Git requires (or even expects) the
>> commit object referenced by a tree to be present in the same object
>> DB. So if you share your notes, I don't know whether or not the
>> fetch/push machinery will include the commit object in the shared
>> notes... These are questions that should be answered before we decide
>> whether using commits directly as notes makes sense.
>
> If that is the case, then my approach is indeed flawed. The main point
> of the exercise is to have a tree that follows another commit (or, as a
> next-best approximation, a note attached to that commit) around.
>
>> In that case, you might be better off using an explicit
>> ref to keep that history alive; e.g. you could create
>> refs/history/e1bfac4 to point to 3d7de37 ("git update-ref
>> refs/history/e1bfac4 3d7de37"), and keep everything
>> alive/reachable/shareable that way...
>
> That’s an interesting idea; instead of relying on the notes feature
> putting the hash in the ref name. But I wonder how that scales – imagine
> every second feature merged into Linux¹ also having such a history ref?
Ah, that will probably not scale very well.
> I guess having a way for a tree to reference commits in a way that is
> followed by git gc, i.e. separate from submodules, would allow a less
> noisy implementation, and possibly create the opportunity for many other
> strange uses of git :-)
Here's another way to solve your problem, which should be fairly
transparent and performant:
Whenever you want to reference "history" of a commit (I'm using quotes
here, because we're not talking about the "regular" git sense of
history, i.e. the commit graph), you perform the following two steps:
1. Append the "historical" commit SHA-1 (3d7de37 in your example) to a
note on the "current" commit (e1bfac4). E.g.:
git notes --ref history append -m 3d7de37... e1bfac4...
2. Perform some automated merge into a "history"-tracking ref (e.g.
refs/history), to keep the "historical" commits reachable.
(You can easily wrap both steps into a script to automate things.)
Step #1 encodes the "history" of a commit in a note, but does not keep
the "history" reachable.
Step #2 keeps all "historical" commits reachable by making them part
of the history (in the git sense - without quotes) of a proper ref
(refs/history). The actual result/outcome of the merge is not
interesting. It only exists to insert the "historical" commit
(3d7de37) into the ancestry for refs/history. Since the actual merge
itself is uninteresting, you should probably use a merge strategy that
never yields conflicts, e.g. "-s ours"
You can now share the "history" by pushing/fetching the two refs
refs/notes/history and refs/history.
(In theory, you might even be able to combine the two refs, by
performing the merge directly into refs/notes/history, always taking
care to retain the notes tree contents as the result of the merge. In
other words, after you do step #1 (append the note), you manually
rewrite the just-created tip of refs/notes/history to include 3d7de37
as a second parent. This keeps 3d7de37 reachable (and it will be
shared when you share refs/notes/history), and it should not interfere
with the notes infrastructure, as they only look at the current state
of the notes tree.)
Hope this helps,
...Johan
--
Johan Herland, <johan@herland.net>
www.herland.net
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: git-note -C changes commit type?
2014-02-12 10:26 ` Johan Herland
@ 2014-02-12 10:33 ` Joachim Breitner
0 siblings, 0 replies; 11+ messages in thread
From: Joachim Breitner @ 2014-02-12 10:33 UTC (permalink / raw)
To: Johan Herland; +Cc: Git mailing list
[-- Attachment #1: Type: text/plain, Size: 2903 bytes --]
Dear Johan,
thanks for the patch!
Am Mittwoch, den 12.02.2014, 11:26 +0100 schrieb Johan Herland:
> Here's another way to solve your problem, which should be fairly
> transparent and performant:
>
> Whenever you want to reference "history" of a commit (I'm using quotes
> here, because we're not talking about the "regular" git sense of
> history, i.e. the commit graph), you perform the following two steps:
>
> 1. Append the "historical" commit SHA-1 (3d7de37 in your example) to a
> note on the "current" commit (e1bfac4). E.g.:
>
> git notes --ref history append -m 3d7de37... e1bfac4...
>
> 2. Perform some automated merge into a "history"-tracking ref (e.g.
> refs/history), to keep the "historical" commits reachable.
>
> (You can easily wrap both steps into a script to automate things.)
>
> Step #1 encodes the "history" of a commit in a note, but does not keep
> the "history" reachable.
>
> Step #2 keeps all "historical" commits reachable by making them part
> of the history (in the git sense - without quotes) of a proper ref
> (refs/history). The actual result/outcome of the merge is not
> interesting. It only exists to insert the "historical" commit
> (3d7de37) into the ancestry for refs/history. Since the actual merge
> itself is uninteresting, you should probably use a merge strategy that
> never yields conflicts, e.g. "-s ours"
>
> You can now share the "history" by pushing/fetching the two refs
> refs/notes/history and refs/history.
>
> (In theory, you might even be able to combine the two refs, by
> performing the merge directly into refs/notes/history, always taking
> care to retain the notes tree contents as the result of the merge. In
> other words, after you do step #1 (append the note), you manually
> rewrite the just-created tip of refs/notes/history to include 3d7de37
> as a second parent. This keeps 3d7de37 reachable (and it will be
> shared when you share refs/notes/history), and it should not interfere
> with the notes infrastructure, as they only look at the current state
> of the notes tree.)
That is quite a good approximation. What it doesn’t do is dropping
history (in the refs/history sense) of commits that disappear, but the
same problem exists with notes. Thanks!
I guess there are no plans to make the commit object format itself
extensible, are they? Extensible in the sense that I can add a custom
field to it (e.g. history:). Git would not have to know anything about
the field besides its type, i.e. that it contains refs that it has to
follow. Very much like "parent:", just without the semantics of it wrt.
"git log" and the like.
Greetings,
Joachim
--
Joachim “nomeata” Breitner
mail@joachim-breitner.de • http://www.joachim-breitner.de/
Jabber: nomeata@joachim-breitner.de • GPG-Key: 0x4743206C
Debian Developer: nomeata@debian.org
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] notes: Disallow reusing non-blob as a note object
2014-02-12 9:54 ` [PATCH] notes: Disallow reusing non-blob as a note object Johan Herland
@ 2014-02-14 15:19 ` Eric Sunshine
2014-02-14 16:19 ` Junio C Hamano
0 siblings, 1 reply; 11+ messages in thread
From: Eric Sunshine @ 2014-02-14 15:19 UTC (permalink / raw)
To: Johan Herland; +Cc: Junio C Hamano, Git List, Joachim Breitner, Kyle J. McKay
On Wed, Feb 12, 2014 at 4:54 AM, Johan Herland <johan@herland.net> wrote:
> Currently "git notes add -C $object" will read the raw bytes from $object,
> and then copy those bytes into the note object, which is hardcoded to be
> of type blob. This means that if the given $object is a non-blob (e.g.
> tree or commit), the raw bytes from that object is copied into a blob
> object. This is probably not useful, and certainly not what any sane
> user would expect. So disallow it, by erroring out if the $object passed
> to the -C option is not a blob.
>
> The fix also applies to the -c option (in which the user is prompted to
> edit/verify the note contents in a text editor), and also when -c/-C is
> passed to "git notes append" (which appends the $object contents to an
> existing note object). In both cases, passing a non-blob $object does not
> make sense.
>
> Also add a couple of tests demonstrating expected behavior.
>
> Suggested-by: Junio C Hamano <gitster@pobox.com>
> Signed-off-by: Johan Herland <johan@herland.net>
> ---
> builtin/notes.c | 6 +++++-
> t/t3301-notes.sh | 27 +++++++++++++++++++++++++++
> 2 files changed, 32 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/notes.c b/builtin/notes.c
> index 2b24d05..bb89930 100644
> --- a/builtin/notes.c
> +++ b/builtin/notes.c
> @@ -269,7 +269,11 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
> die(_("Failed to resolve '%s' as a valid ref."), arg);
> if (!(buf = read_sha1_file(object, &type, &len)) || !len) {
> free(buf);
> - die(_("Failed to read object '%s'."), arg);;
> + die(_("Failed to read object '%s'."), arg);
> + }
> + if (type != OBJ_BLOB) {
> + free(buf);
> + die(_("Cannot read note data from non-blob object '%s'."), arg);
The way this diagnostic is worded, it sound as if the 'read' failed
rather than that the user specified an incorrect object type. Perhaps
"Object is not a blob '%s'" or "Expected blob but '%s' has type '%s'"
or something along those lines?
> }
> strbuf_add(&(msg->buf), buf, len);
> free(buf);
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] notes: Disallow reusing non-blob as a note object
2014-02-14 15:19 ` Eric Sunshine
@ 2014-02-14 16:19 ` Junio C Hamano
0 siblings, 0 replies; 11+ messages in thread
From: Junio C Hamano @ 2014-02-14 16:19 UTC (permalink / raw)
To: Eric Sunshine; +Cc: Johan Herland, Git List, Joachim Breitner, Kyle J. McKay
Eric Sunshine <sunshine@sunshineco.com> writes:
>> + if (type != OBJ_BLOB) {
>> + free(buf);
>> + die(_("Cannot read note data from non-blob object '%s'."), arg);
>
> The way this diagnostic is worded, it sound as if the 'read' failed
> rather than that the user specified an incorrect object type. Perhaps
> "Object is not a blob '%s'" or "Expected blob but '%s' has type '%s'"
> or something along those lines?
Yeah, sounds good. You also need to say what expects a blob, too.
Perhaps something like this?
builtin/notes.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/builtin/notes.c b/builtin/notes.c
index c11d6e6..a16bc00 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -272,8 +272,10 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
die(_("Failed to read object '%s'."), arg);
}
if (type != OBJ_BLOB) {
+ struct msg_arg *msg = opt->value;
free(buf);
- die(_("Cannot read note data from non-blob object '%s'."), arg);
+ die(_("The -%c option takes a blob, which '%s' is not.",
+ msg->use_editor ? 'c' : 'C', arg));
}
strbuf_add(&(msg->buf), buf, len);
free(buf);
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2014-02-14 16:19 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-11 17:23 git-note -C changes commit type? Joachim Breitner
2014-02-11 23:52 ` Johan Herland
2014-02-12 0:06 ` Junio C Hamano
2014-02-12 5:16 ` Kyle J. McKay
2014-02-12 9:50 ` Johan Herland
2014-02-12 9:54 ` [PATCH] notes: Disallow reusing non-blob as a note object Johan Herland
2014-02-14 15:19 ` Eric Sunshine
2014-02-14 16:19 ` Junio C Hamano
2014-02-12 8:53 ` git-note -C changes commit type? Joachim Breitner
2014-02-12 10:26 ` Johan Herland
2014-02-12 10:33 ` Joachim Breitner
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).