Object ID support for git merge-file
cover Object ID support for git merge-file
This series introduces an --object-id option to git merge-file such that, instead of reading and writing from files on the system, it reads from and writes to the object store using blobs. This is in use at GitHub to produce conflict diffs when a merge fails, and it seems generally useful, so I'm sending it here.
The only tricky piece is the fact that we have to special-case the empty blob since otherwise it isn't handled correctly.
brian m. carlson (1):
merge-file: add an option to process object IDs
Documentation/git-merge-file.txt | 20 +++++++++++ builtin/merge-file.c | 58 +++++++++++++++++++++++--------- t/t6403-merge-file.sh | 58 ++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 16 deletions(-)
PATCH 1/1 merge-file: add an option to process object IDs
From: "brian m. carlson" <[email protected]>
git merge-file knows how to merge files on the file system already. It would be helpful, however, to allow it to also merge single blobs. Teach it an --object-id option which means that its arguments are object IDs and not files to allow it to do so.
Since we obviously won't be writing the data to the first argument, either write to the object store and print the object ID, or honor the -p argument and print it to standard out.
We handle the empty blob specially since read_mmblob doesn't read it directly, instead throwing an error, and otherwise users cannot specify an empty ancestor.
--- Documentation/git-merge-file.txt | 20 +++++++++++ builtin/merge-file.c | 58 +++++++++++++++++++++++--------- t/t6403-merge-file.sh | 58 ++++++++++++++++++++++++++++++++ 3 files changed, 120 insertions(+), 16 deletions(-)
Documentation/git-merge-file.txt +20 -0
@@ -12,6 +12,9 @@ SYNOPSIS 'git merge-file' [-L <current-name> [-L <base-name> [-L <other-name>]]] [--ours|--theirs|--union] [-p|--stdout] [-q|--quiet] [--marker-size=<n>] [--[no-]diff3] <current-file> <base-file> <other-file> +'git merge-file' --object-id [-L <current-name> [-L <base-name> [-L <other-name>]]] + [--ours|--theirs|--union] [-q|--quiet] [--marker-size=<n>] + [--[no-]diff3] <current-oid> <base-oid> <other-oid> DESCRIPTION
@@ -40,6 +43,10 @@ however, these conflicts are resolved favouring lines from `<current-file>`, lines from `<other-file>`, or lines from both respectively. The length of the conflict markers can be given with the `--marker-size` option. +If `--object-id` is specified, exactly the same behavior occurs, except that +instead of specifying what to merge as files, it is specified as a list of +object IDs referring to blobs. + The exit value of this program is negative on error, and the number of conflicts otherwise (truncated to 127 if there are more than that many conflicts). If the merge was clean, the exit value is 0.
@@ -52,6 +59,14 @@ linkgit:git[1]. OPTIONS ------- +--object-id:: + Specify the contents to merge as blobs in the current repository instead of + files. In this case, the operation must take place within a valid repository. ++ +If the `-p` option is specified, the merged file (including conflicts, if any) +goes to standard output as normal; otherwise, the merged file is written to the +object store and the object ID of its blob is written to standard output. + -L <label>:: This option may be given up to three times, and specifies labels to be used in place of the
@@ -93,6 +108,11 @@ EXAMPLES merges tmp/a123 and tmp/c345 with the base tmp/b234, but uses labels `a` and `c` instead of `tmp/a123` and `tmp/c345`. +`git merge-file -p --object-id abc1234 def567 890abcd`:: + + combines the changes of the blob abc1234 and 890abcd since def567, + tries to merge them and writes the result to standard output + GIT --- Part of the linkgit:git[1] suite
builtin/merge-file.c +42 -16
97 lines not on this page · raw message
t/t6403-merge-file.sh +58 -0
85 lines not on this page · raw message
Re: [PATCH 1/1] merge-file: add an option to process object IDs
Quoted 17 lines · brian m. carlson
git merge-file knows how to merge files on the file system already. It would be helpful, however, to allow it to also merge single blobs. Teach it an
--object-idoption which means that its arguments are object IDs and not files to allow it to do so.Since we obviously won't be writing the data to the first argument, either write to the object store and print the object ID, or honor the -p argument and print it to standard out.
We handle the empty blob specially since
read_mmblobdoesn't read it directly, instead throwing an error, and otherwise users cannot specify an empty ancestor.Signed-off-by brian m. carlson <[email protected]>---
builtin/merge-file.c int cmd_merge_file(int argc, const char **argv, const char *prefix) · line 120
Quoted 8 lines
builtin/merge-file.c +4
-3@@ -99,20 +116,29 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)if (ret >=0 ) { -const char *filename = argv[0 ]; -char *fpath =prefix_filename (prefix, argv[0 ]); -FILE *f = to_stdout ? stdout :fopen (fpath,"wb" ); +if (object_id && !to_stdout) { +struct object_id oid; +if (result.size) +write_object_file (result.ptr, result.size,OBJ_BLOB , &oid);
Should this be caring about errors by checking the return value of write_object_file()?
builtin/merge-file.c int cmd_merge_file(int argc, const char **argv, const char *prefix) · line 139
Quoted 13 lines
builtin/merge-file.c +13
-0+ }else { +const char *filename = argv[0 ]; +char *fpath =prefix_filename (prefix, argv[0 ]); +FILE *f = to_stdout ? stdout :fopen (fpath,"wb" ); +if (!f) + ret =error_errno ("Could not open %s for writing" , + filename); +else if (result.size && +fwrite (result.ptr, result.size,1 , f) !=1 ) + ret =error_errno ("Could not write to %s" , filename); +else if (fclose (f)) + ret =error_errno ("Could not close %s" , filename); +free (fpath);
The non-"object-id" case cares about errors.
Re: [PATCH 1/1] merge-file: add an option to process object IDs
Quoted 15 lines · Eric Sunshine
Quoted 13 lines · brian m. carlson
git merge-file knows how to merge files on the file system already. It would be helpful, however, to allow it to also merge single blobs. Teach it an
--object-idoption which means that its arguments are object IDs and not files to allow it to do so.Since we obviously won't be writing the data to the first argument, either write to the object store and print the object ID, or honor the -p argument and print it to standard out.
We handle the empty blob specially since
read_mmblobdoesn't read it directly, instead throwing an error, and otherwise users cannot specify an empty ancestor.
Quoted 15 lines
builtin/merge-file.c int cmd_merge_file(int argc, const char **argv, const char *prefix) · line 120
Quoted 12 lines
Signed-off-by brian m. carlson <[email protected]>---
builtin/merge-file.c +4
-3@@ -99,20 +116,29 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)if (ret >=0 ) { -const char *filename = argv[0 ]; -char *fpath =prefix_filename (prefix, argv[0 ]); -FILE *f = to_stdout ? stdout :fopen (fpath,"wb" ); +if (object_id && !to_stdout) { +struct object_id oid; +if (result.size) +write_object_file (result.ptr, result.size,OBJ_BLOB , &oid);Should this be caring about errors by checking the return value of
write_object_file()?
Probably so. I think I saw write_object_file_prepare returned void and misinterpreted that as write_object_file returning void.
Signature · 2 lines
brian m. carlson (he/him or they/them) Toronto, Ontario, CA
Re: [PATCH 1/1] merge-file: add an option to process object IDs
In reply to brian m. carlsonHi,
Overall, looks good. Just a couple questions...
Quoted 3 lines · brian m. carlson
From: "brian m. carlson" <[email protected]>
[...]
Documentation/git-merge-file.txt SYNOPSIS · line 17
Quoted 9 lines
Documentation/git-merge-file.txt +3
-0@@ -12,6 +12,9 @@ SYNOPSIS 'git merge-file' [-L <current-name> [-L <base-name> [-L <other-name>]]] [--ours|--theirs|--union] [-p|--stdout] [-q|--quiet] [--marker-size=<n>] [--[no-]diff3] <current-file> <base-file> <other-file> +'git merge-file' --object-id [-L <current-name> [-L <base-name> [-L <other-name>]]] + [--ours|--theirs|--union] [-q|--quiet] [--marker-size=<n>] + [--[no-]diff3] <current-oid> <base-oid> <other-oid>
Why was the [-p|--stdout] option removed in the second synopsis? Elsewhere you explicitly call it out as a possibility to be used with --object-id.
Also, why the extra synopsis instead of just adding a [--object-id] option to the previous one?
[...]
Documentation/git-merge-file.txt int cmd_merge_file(int argc, const char **argv, const char *prefix) · line 97
Quoted 12 lines
Documentation/git-merge-file.txt +7
-1@@ -80,12 +88,21 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix) fname = prefix_filename(prefix, argv[i]); - if (read_mmfile(mmf, fname)) + if (object_id) { + if (repo_get_oid(the_repository, argv[i], &oid)) + ret = -1; + else if (!oideq(&oid, the_hash_algo->empty_blob)) + read_mmblob(mmf, &oid); + else + read_mmfile(mmf, "/dev/null");
Does "/dev/null" have any portability considerations? (I really don't know; just curious.)
Re: [PATCH 1/1] merge-file: add an option to process object IDs
Hi brian
I agree with everything Elijah said, I just have one more comment
Quoted 8 lines
builtin/merge-file.c int cmd_merge_file(int argc, const char **argv, const char *prefix) · line 93
Quoted 8 lines
builtin/merge-file.c +3
-1@@ -80,12 +88,21 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix) fname =prefix_filename (prefix, argv[i]); -if (read_mmfile (mmf, fname)) +if (object_id) { +if (repo_get_oid (the_repository, argv[i], &oid)) + ret =-1 ;
It would be nice to print an error message here
ret = error("object '%s' does not exist", argv[i]);none of the existing error messages are marked for translation so I've left this untranslated as well.
Best Wishes
Phillip
Re: [PATCH 1/1] merge-file: add an option to process object IDs
Quoted 3 lines · Phillip Wood
It would be nice to print an error message here
ret = error("object '%s' does not exist", argv[i]);
Good point. I'll include that in my reroll.
Quoted 2 lines
none of the existing error messages are marked for translation so I've left this untranslated as well.
I've opted to make them translatable here because I think that's for the best.
Signature · 2 lines
brian m. carlson (he/him or they/them) Toronto, Ontario, CA
Re: [PATCH 1/1] merge-file: add an option to process object IDs
In reply to Elijah NewrenQuoted 10 lines · Elijah Newren
Hi,
Overall, looks good. Just a couple questions...
Quoted 3 lines · brian m. carlson
From: "brian m. carlson" <[email protected]>
[...]
Quoted 13 lines
Documentation/git-merge-file.txt SYNOPSIS · line 17
Quoted 9 lines
Documentation/git-merge-file.txt +3
-0@@ -12,6 +12,9 @@ SYNOPSIS 'git merge-file' [-L <current-name> [-L <base-name> [-L <other-name>]]] [--ours|--theirs|--union] [-p|--stdout] [-q|--quiet] [--marker-size=<n>] [--[no-]diff3] <current-file> <base-file> <other-file> +'git merge-file' --object-id [-L <current-name> [-L <base-name> [-L <other-name>]]] + [--ours|--theirs|--union] [-q|--quiet] [--marker-size=<n>] + [--[no-]diff3] <current-oid> <base-oid> <other-oid>Why was the
[-p|--stdout]option removed in the second synopsis? Elsewhere you explicitly call it out as a possibility to be used with --object-id.
Originally because it implied -p, but I changed that to write into the object store. I'll restore it.
Quoted 2 lines
Also, why the extra synopsis instead of just adding a
[--object-id]option to the previous one?
Because there's a relevant difference: the former has <current-file>, <base-file>, and <other-file>, and the latter has the -oid versions.
Quoted 2 lines
Does "
/dev/null" have any portability considerations? (I really don't know; just curious.)
We already use it elsewhere in the codebase, so I assume it works. We also have a test for that case and it worked in CI, so it's probably fine.
Signature · 2 lines
brian m. carlson (he/him or they/them) Toronto, Ontario, CA
Re: [PATCH 1/1] merge-file: add an option to process object IDs
Hi,
Quoted 26 lines · brian m. carlson
Quoted 10 lines · Elijah Newren
Hi,
Overall, looks good. Just a couple questions...
Quoted 3 lines · brian m. carlson
From: "brian m. carlson" <[email protected]>
[...]
Quoted 13 lines
Documentation/git-merge-file.txt SYNOPSIS · line 17
Quoted 9 lines
Documentation/git-merge-file.txt +3
-0@@ -12,6 +12,9 @@ SYNOPSIS 'git merge-file' [-L <current-name> [-L <base-name> [-L <other-name>]]] [--ours|--theirs|--union] [-p|--stdout] [-q|--quiet] [--marker-size=<n>] [--[no-]diff3] <current-file> <base-file> <other-file> +'git merge-file' --object-id [-L <current-name> [-L <base-name> [-L <other-name>]]] + [--ours|--theirs|--union] [-q|--quiet] [--marker-size=<n>] + [--[no-]diff3] <current-oid> <base-oid> <other-oid>Why was the
[-p|--stdout]option removed in the second synopsis? Elsewhere you explicitly call it out as a possibility to be used with --object-id.
Quoted 8 lines
Originally because it implied
-p, but I changed that to write into the object store. I'll restore it.Quoted 2 lines
Also, why the extra synopsis instead of just adding a
[--object-id]option to the previous one?Because there's a relevant difference: the former has <current-file>, <base-file>, and <other-file>, and the latter has the -oid versions.
Ah, I looked over it a couple times and just kept missing that difference. Thanks for pointing it out.
Quoted 7 lines
Quoted 3 lines
Does "
/dev/null" have any portability considerations? (I really don't know; just curious.)We already use it elsewhere in the codebase, so I assume it works. We also have a test for that case and it worked in CI, so it's probably fine.
Seems reasonable to me; thanks.
Quoted 4 lines · brian m. carlson
This series introduces an --object-id option to git merge-file such that, instead of reading and writing from files on the system, it reads from and writes to the object store using blobs.
This seems like a reasonable capability to want from such a plumbing command.
Quoted 3 lines
This is in use at
GitHub to produce conflict diffs when a merge fails, and it seems generally useful, so I'm sending it here.
But...wouldn't you already have the conflicts generated when doing the merge and learning that it fails? Why would you need to generate them again?
(Also, generating them again may risk getting names munged for conflict markers in edge cases involving renames.)
That said, even if I have questions about your particular usecase, I think the feature you are submitting here makes sense independently.
I left a few minor questions on the patch itself, but overall it looks good to me.
Quoted 8 lines · Elijah Newren
On Tue, Oct 24, 2023 at 12:58 PM brian m. carlson
Quoted 3 lines
This is in use at
GitHub to produce conflict diffs when a merge fails, and it seems generally useful, so I'm sending it here.But...wouldn't you already have the conflicts generated when doing the merge and learning that it fails? Why would you need to generate them again?
I was surprised by this as well, but as you say this seems like a useful addition independent of any specific use at GitHub.
Best Wishes
Phillip
Quoted 8 lines · Elijah Newren
Quoted 4 lines · brian m. carlson
This series introduces an --object-id option to git merge-file such that, instead of reading and writing from files on the system, it reads from and writes to the object store using blobs.
This seems like a reasonable capability to want from such a plumbing command.
Agreed.
Quoted 7 lines
Quoted 3 lines
This is in use at
GitHub to produce conflict diffs when a merge fails, and it seems generally useful, so I'm sending it here.But...wouldn't you already have the conflicts generated when doing the merge and learning that it fails? Why would you need to generate them again?
brian would know better than I do, but I believe the reason is because the "attempt this merge" RPC is handled separately from the "show me the merge conflict(s) at xyz path". Those probably could be combined (obviating the need for this patch), but doing so is probably rather complicated.
Since this feature is generally useful for callers that haven't already completed a tree-level merge and really just care about the result of merging a single path, I don't have any objections here.
Thanks,
Taylor
Quoted 10 lines · Taylor Blau
Quoted 3 lines · Elijah Newren
But...wouldn't you already have the conflicts generated when doing the merge and learning that it fails? Why would you need to generate them again?
brian would know better than I do, but I believe the reason is because the "attempt this merge" RPC is handled separately from the "show me the merge conflict(s) at xyz path". Those probably could be combined (obviating the need for this patch), but doing so is probably rather complicated.
That's correct. They could in theory happen at different times, which is why they're not linked.
Signature · 2 lines
brian m. carlson (he/him or they/them) Toronto, Ontario, CA
Quoted 7 lines · brian m. carlson
Quoted 5 lines · Taylor Blau
Quoted 3 lines · Elijah Newren
But...wouldn't you already have the conflicts generated when doing the merge and learning that it fails? Why would you need to generate them again?
Quoted 8 lines
Quoted 5 lines
brian would know better than I do, but I believe the reason is because the "attempt this merge" RPC is handled separately from the "show me the merge conflict(s) at xyz path". Those probably could be combined (obviating the need for this patch), but doing so is probably rather complicated.
That's correct. They could in theory happen at different times, which is why they're not linked.
Maybe this is digging a little into "historical reasons" too much, but this still seems a little funny. If they happen at different times, you still need multiple pieces of information remembered from the merge operation in order for git-merge-file to be able to regenerate the conflict correctly in general. In particular, you need the OIDs and the filenames. Trying to regenerate a conflict without remembering those from the merge step would only work for common cases, but would be problematic in the face of either renames being involved or recursive merges or both. And if you need to remember information from the merge step, then why not remember the actual conflicts (or at least the tree OID generated by the merge operation, which has the conflicts embedded within it)?
I know, I know, there's probably just historical cruft that needs cleaning up, and I don't think any of this matters to the patch at hand since it's independently useful. It just sounds like a system has been set up that has some rough edge cases caused by a poor splitting.
Quoted 3 lines
--
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA
v2 cover Object ID support for git merge-file
In reply to brian m. carlsonThis series introduces an --object-id option to git merge-file such that, instead of reading and writing from files on the system, it reads from and writes to the object store using blobs.
Changes from v1:
* Improve error handling
* Re-add -p argument for documentation
brian m. carlson (1):
merge-file: add an option to process object IDs
Documentation/git-merge-file.txt | 20 +++++++++++ builtin/merge-file.c | 62 +++++++++++++++++++++++--------- t/t6403-merge-file.sh | 58 ++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 16 deletions(-)
PATCH v2 1/1 merge-file: add an option to process object IDs
From: "brian m. carlson" <[email protected]>
git merge-file knows how to merge files on the file system already. It would be helpful, however, to allow it to also merge single blobs. Teach it an --object-id option which means that its arguments are object IDs and not files to allow it to do so.
Since we obviously won't be writing the data to the first argument, imply the -p option so we write to standard output.
We handle the empty blob specially since read_mmblob doesn't read it directly and otherwise users cannot specify an empty ancestor.
--- Documentation/git-merge-file.txt | 20 +++++++++++ builtin/merge-file.c | 62 +++++++++++++++++++++++--------- t/t6403-merge-file.sh | 58 ++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 16 deletions(-)
Documentation/git-merge-file.txt +20 -0
@@ -12,6 +12,9 @@ SYNOPSIS 'git merge-file' [-L <current-name> [-L <base-name> [-L <other-name>]]] [--ours|--theirs|--union] [-p|--stdout] [-q|--quiet] [--marker-size=<n>] [--[no-]diff3] <current-file> <base-file> <other-file> +'git merge-file' --object-id [-L <current-name> [-L <base-name> [-L <other-name>]]] + [--ours|--theirs|--union] [-p|--stdout] [-q|--quiet] [--marker-size=<n>] + [--[no-]diff3] <current-oid> <base-oid> <other-oid> DESCRIPTION
@@ -40,6 +43,10 @@ however, these conflicts are resolved favouring lines from `<current-file>`, lines from `<other-file>`, or lines from both respectively. The length of the conflict markers can be given with the `--marker-size` option. +If `--object-id` is specified, exactly the same behavior occurs, except that +instead of specifying what to merge as files, it is specified as a list of +object IDs referring to blobs. + The exit value of this program is negative on error, and the number of conflicts otherwise (truncated to 127 if there are more than that many conflicts). If the merge was clean, the exit value is 0.
@@ -52,6 +59,14 @@ linkgit:git[1]. OPTIONS ------- +--object-id:: + Specify the contents to merge as blobs in the current repository instead of + files. In this case, the operation must take place within a valid repository. ++ +If the `-p` option is specified, the merged file (including conflicts, if any) +goes to standard output as normal; otherwise, the merged file is written to the +object store and the object ID of its blob is written to standard output. + -L <label>:: This option may be given up to three times, and specifies labels to be used in place of the
@@ -93,6 +108,11 @@ EXAMPLES merges tmp/a123 and tmp/c345 with the base tmp/b234, but uses labels `a` and `c` instead of `tmp/a123` and `tmp/c345`. +`git merge-file -p --object-id abc1234 def567 890abcd`:: + + combines the changes of the blob abc1234 and 890abcd since def567, + tries to merge them and writes the result to standard output + GIT --- Part of the linkgit:git[1] suite
builtin/merge-file.c +46 -16
101 lines not on this page · raw message
t/t6403-merge-file.sh +58 -0
85 lines not on this page · raw message
Re: [PATCH v2 1/1] merge-file: add an option to process object IDs
Quoted 3 lines · brian m. carlson
Since we obviously won't be writing the data to the first argument, imply the -p option so we write to standard output.
This paragraph changed from v1, but this doesn't match the actual behavior, from what I can tell: -p is not implied.
Review
Quoted 6 lines
'git merge-file' [-L <current-name> [-L <base-name> [-L <other-name>]]]
[--ours|--theirs|--union] [-p|--stdout] [-q|--quiet] [--marker-size=<n>] [--[no-]diff3] <current-file> <base-file> <other-file>+'git merge-file' --object-id [-L <current-name> [-L <base-name> [-L <other-name>]]]
(quoted diff) +2
-0+ [--ours|--theirs|--union] [-p|--stdout] [-q|--quiet] [--marker-size=<n>] + [--[no-]diff3] <current-oid> <base-oid> <other-oid>
I see this duplicated synopsis was discussed on v1, and that the difference here is "file" vs "oid". It seems we could avoid this redundancy and risk of going out of sync with no downside that I can see by instead dropping all these "-file". See below for a patch that could go in as a preparatory step.
Review
Quoted 3 lines
(quoted diff) +3
-0+If `--object-id` is specified, exactly the same behavior occurs, except that +instead of specifying what to merge as files, it is specified as a list of +object IDs referring to blobs.
Makes sense.
Review
Quoted 3 lines
(quoted diff) +3
-0+If the `-p` option is specified, the merged file (including conflicts, if any) +goes to standard output as normal; otherwise, the merged file is written to the +object store and the object ID of its blob is written to standard output.
(Here, -p is not implied.)
Review
Quoted 6 lines
(quoted diff) +6
-0+test_expect_success 'merge without conflict with --object-id' ' + git add orig.txt new2.txt && + git merge-file --object-id :orig.txt :orig.txt :new2.txt >actual && + git rev-parse :new2.txt >expected && + test_cmp actual expected +'
(Here, -p is not implied.)
Martin
-- >8 --
Subject: [PATCH] git-merge-file doc: drop "-file" from argument placeholders
git merge-file takes three positional arguments. Each of them is documented as <foo-file>. In preparation for teaching this command to alternatively take three object IDs, make these placeholders a bit more generic by dropping the "-file" parts. Instead, clarify early that the three arguments are filenames. Even after the next commit, we can afford to present this file-centric view up front and in the general discussion, since it will remain the default one.
--- Documentation/git-merge-file.txt | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
Documentation/git-merge-file.txt +11 -10
@@ -11,19 +11,20 @@ SYNOPSIS [verse] 'git merge-file' [-L <current-name> [-L <base-name> [-L <other-name>]]] [--ours|--theirs|--union] [-p|--stdout] [-q|--quiet] [--marker-size=<n>] - [--[no-]diff3] <current-file> <base-file> <other-file> + [--[no-]diff3] <current> <base> <other> DESCRIPTION ----------- -'git merge-file' incorporates all changes that lead from the `<base-file>` -to `<other-file>` into `<current-file>`. The result ordinarily goes into -`<current-file>`. 'git merge-file' is useful for combining separate changes -to an original. Suppose `<base-file>` is the original, and both -`<current-file>` and `<other-file>` are modifications of `<base-file>`, +Given three files `<current>`, `<base>` and `<other>`, +'git merge-file' incorporates all changes that lead from `<base>` +to `<other>` into `<current>`. The result ordinarily goes into +`<current>`. 'git merge-file' is useful for combining separate changes +to an original. Suppose `<base>` is the original, and both +`<current>` and `<other>` are modifications of `<base>`, then 'git merge-file' combines both changes. -A conflict occurs if both `<current-file>` and `<other-file>` have changes +A conflict occurs if both `<current>` and `<other>` have changes in a common segment of lines. If a conflict is found, 'git merge-file' normally outputs a warning and brackets the conflict with lines containing <<<<<<< and >>>>>>> markers. A typical conflict will look like this:
@@ -36,8 +37,8 @@ normally outputs a warning and brackets the conflict with lines containing If there are conflicts, the user should edit the result and delete one of the alternatives. When `--ours`, `--theirs`, or `--union` option is in effect, -however, these conflicts are resolved favouring lines from `<current-file>`, -lines from `<other-file>`, or lines from both respectively. The length of the +however, these conflicts are resolved favouring lines from `<current>`, +lines from `<other>`, or lines from both respectively. The length of the conflict markers can be given with the `--marker-size` option. The exit value of this program is negative on error, and the number of
@@ -62,7 +63,7 @@ OPTIONS -p:: Send results to standard output instead of overwriting - `<current-file>`. + `<current>`. -q:: Quiet; do not warn about conflicts.
Signature · 1 line
2.42.0.899.gfd14d11e2b
Re: [PATCH v2 1/1] merge-file: add an option to process object IDs
Quoted 8 lines · Martin Ågren
Quoted 3 lines · brian m. carlson
Since we obviously won't be writing the data to the first argument, imply the -p option so we write to standard output.
This paragraph changed from v1, but this doesn't match the actual behavior, from what I can tell:
-pis not implied.
Yes, apparently that commit message snuck back in after it having been edited out.
Quoted 10 lines
-- >8 --
Subject: [PATCH] git-merge-file doc: drop "-file" from argument placeholders
git merge-filetakes three positional arguments. Each of them is documented as<foo-file>. In preparation for teaching this command to alternatively take three object IDs, make these placeholders a bit more generic by dropping the "-file" parts. Instead, clarify early that the three arguments are filenames. Even after the next commit, we can afford to present this file-centric view up front and in the general discussion, since it will remain the default one.
This seems reasonable. Junio, do you want to sneak this in and fix the commit message above, or do you want me to do a v3?
Signature · 2 lines
brian m. carlson (he/him or they/them) Toronto, Ontario, CA
Re: [PATCH v2 1/1] merge-file: add an option to process object IDs
Quoted 2 lines · brian m. carlson
This seems reasonable. Junio, do you want to sneak this in and fix the commit message above, or do you want me to do a v3?
As it hasn't hit 'next' on my end, I'd prefer to see a version I can blindly apply without having to care all the details of what was discussed. Thanks.
Re: [PATCH v2 1/1] merge-file: add an option to process object IDs
Quoted 8 lines · Junio C Hamano
Quoted 2 lines · brian m. carlson
This seems reasonable. Junio, do you want to sneak this in and fix the commit message above, or do you want me to do a v3?
As it hasn't hit 'next' on my end, I'd prefer to see a version I can blindly apply without having to care all the details of what was discussed. Thanks.
I'll send out a v3 shortly.
Signature · 2 lines
brian m. carlson (he/him or they/them) Toronto, Ontario, CA
Quoted 9 lines · brian m. carlson
This series introduces an --object-id option to git merge-file such that, instead of reading and writing from files on the system, it reads from and writes to the object store using blobs.
Changes from v1:
* Improve error handling
* Re-add-pargument for documentation
Quoted 7 lines
brian m. carlson (1):
merge-file: add an option to process object IDsDocumentation/git-merge-file.txt | 20 +++++++++++ builtin/merge-file.c | 62 +++++++++++++++++++++++--------- t/t6403-merge-file.sh | 58 ++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 16 deletions(-)
Thanks, this version looks good to me.
Quoted 14 lines · Elijah Newren
Quoted 12 lines · brian m. carlson
This series introduces an --object-id option to git merge-file such that, instead of reading and writing from files on the system, it reads from and writes to the object store using blobs.
Changes from v1:
* Improve error handling
* Re-add-pargument for documentationbrian m. carlson (1):
merge-file: add an option to process object IDs
Quoted 6 lines
Quoted 4 lines
Documentation/git-merge-file.txt | 20 +++++++++++ builtin/merge-file.c | 62 +++++++++++++++++++++++--------- t/t6403-merge-file.sh | 58 ++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 16 deletions(-)Thanks, this version looks good to me.
Thanks, both. Will queue.
Hi brian
Thanks for the re-roll, this version looks good to me
Phillip
Quoted 17 lines · brian m. carlson
This series introduces an --object-id option to git merge-file such that, instead of reading and writing from files on the system, it reads from and writes to the object store using blobs.
Changes from v1:
* Improve error handling
* Re-add-pargument for documentationbrian m. carlson (1):
merge-file: add an option to process object IDsDocumentation/git-merge-file.txt | 20 +++++++++++ builtin/merge-file.c | 62 +++++++++++++++++++++++--------- t/t6403-merge-file.sh | 58 ++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 16 deletions(-)
Junio C Hamano
AppliedQuoted 5 lines · Phillip Wood
Hi brian
Thanks for the re-roll, this version looks good to me
Phillip
Yup, competently done.
I briefly thought about suggesting --blob-id instead of --object-id simply because you'd never want to feed it trees and commits, but the error message from read_mmblob() the users would get mentions 'blob' to signal that non-blob objects are unwelcome, so the name of the optionwould be OK as-is.
Queued. Let's mark it for 'next'. Thanks.
v3 cover Object ID support for git merge-file
In reply to brian m. carlsonThis series introduces an --object-id option to git merge-file such that, instead of reading and writing from files on the system, it reads from and writes to the object store using blobs.
Changes from v2:
* Include a patch from Martin to pre-improve the documentation
* Remove incorrect portion of commit message
Changes from v1:
* Improve error handling
* Re-add -p argument for documentation
Martin Ågren (1):
git-merge-file doc: drop "-file" from argument placeholders
brian m. carlson (1):
merge-file: add an option to process object IDs
Documentation/git-merge-file.txt | 38 ++++++++++++++------ builtin/merge-file.c | 62 +++++++++++++++++++++++--------- t/t6403-merge-file.sh | 58 ++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 26 deletions(-)
Range-diff against v2:
-: ---------- > 1: 21a96acf42 git-merge-file doc: drop "-file" from argument placeholders 1: 9cd4220a3b ! 2: b1978a7b5c merge-file: add an option to process object IDs
@@ Commit message
Teach it an --object-id option which means that its arguments are object IDs and not files to allow it to do so.
- Since we obviously won't be writing the data to the first argument,
- imply the -p option so we write to standard output.
-
We handle the empty blob specially since read_mmblob doesn't read it directly and otherwise users cannot specify an empty ancestor.
@@ Commit message
## Documentation/git-merge-file.txt ##
@@ Documentation/git-merge-file.txt: SYNOPSIS
+ [verse]
'git merge-file' [-L <current-name> [-L <base-name> [-L <other-name>]]]
[--ours|--theirs|--union] [-p|--stdout] [-q|--quiet] [--marker-size=<n>]
- [--[no-]diff3] <current-file> <base-file> <other-file>
-+'git merge-file' --object-id [-L <current-name> [-L <base-name> [-L <other-name>]]]
-+ [--ours|--theirs|--union] [-p|--stdout] [-q|--quiet] [--marker-size=<n>]
-+ [--[no-]diff3] <current-oid> <base-oid> <other-oid>
+- [--[no-]diff3] <current> <base> <other>
++ [--[no-]diff3] [--object-id] <current> <base> <other>
DESCRIPTION
-@@ Documentation/git-merge-file.txt: however, these conflicts are resolved favouring lines from <current-file>,
- lines from <other-file>, or lines from both respectively. The length of the
+@@ Documentation/git-merge-file.txt: however, these conflicts are resolved favouring lines from <current>,
+ lines from <other>, or lines from both respectively. The length of the
conflict markers can be given with the --marker-size option.
+If --object-id is specified, exactly the same behavior occurs, except that
PATCH v3 1/2 git-merge-file doc: drop "-file" from argument placeholders
From: Martin Ågren <[email protected]>
git merge-file takes three positional arguments. Each of them is documented as <foo-file>. In preparation for teaching this command to alternatively take three object IDs, make these placeholders a bit more generic by dropping the "-file" parts. Instead, clarify early that the three arguments are filenames. Even after the next commit, we can afford to present this file-centric view up front and in the general discussion, since it will remain the default one.
--- Documentation/git-merge-file.txt | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
Documentation/git-merge-file.txt +11 -10
@@ -11,19 +11,20 @@ SYNOPSIS [verse] 'git merge-file' [-L <current-name> [-L <base-name> [-L <other-name>]]] [--ours|--theirs|--union] [-p|--stdout] [-q|--quiet] [--marker-size=<n>] - [--[no-]diff3] <current-file> <base-file> <other-file> + [--[no-]diff3] <current> <base> <other> DESCRIPTION ----------- -'git merge-file' incorporates all changes that lead from the `<base-file>` -to `<other-file>` into `<current-file>`. The result ordinarily goes into -`<current-file>`. 'git merge-file' is useful for combining separate changes -to an original. Suppose `<base-file>` is the original, and both -`<current-file>` and `<other-file>` are modifications of `<base-file>`, +Given three files `<current>`, `<base>` and `<other>`, +'git merge-file' incorporates all changes that lead from `<base>` +to `<other>` into `<current>`. The result ordinarily goes into +`<current>`. 'git merge-file' is useful for combining separate changes +to an original. Suppose `<base>` is the original, and both +`<current>` and `<other>` are modifications of `<base>`, then 'git merge-file' combines both changes. -A conflict occurs if both `<current-file>` and `<other-file>` have changes +A conflict occurs if both `<current>` and `<other>` have changes in a common segment of lines. If a conflict is found, 'git merge-file' normally outputs a warning and brackets the conflict with lines containing <<<<<<< and >>>>>>> markers. A typical conflict will look like this:
@@ -36,8 +37,8 @@ normally outputs a warning and brackets the conflict with lines containing If there are conflicts, the user should edit the result and delete one of the alternatives. When `--ours`, `--theirs`, or `--union` option is in effect, -however, these conflicts are resolved favouring lines from `<current-file>`, -lines from `<other-file>`, or lines from both respectively. The length of the +however, these conflicts are resolved favouring lines from `<current>`, +lines from `<other>`, or lines from both respectively. The length of the conflict markers can be given with the `--marker-size` option. The exit value of this program is negative on error, and the number of
@@ -62,7 +63,7 @@ OPTIONS -p:: Send results to standard output instead of overwriting - `<current-file>`. + `<current>`. -q:: Quiet; do not warn about conflicts.
Re: [PATCH v3 1/2] git-merge-file doc: drop "-file" from argument placeholders
Quoted 5 lines · brian m. carlson
From: Martin Ågren <[email protected]>
git merge-filetakes three positional arguments. Each of them is documented as<foo-file>. In preparation for teaching this command to alternatively take three object IDs, make these placeholders a bit more
Minor nit. Don't we want to say "three blob object names"? Unless we plan to grow this feature into accepting three tree object names, that is.
Re: [PATCH v3 1/2] git-merge-file doc: drop "-file" from argument placeholders
Quoted 5 lines · Junio C Hamano
Quoted 2 lines · brian m. carlson
From: Martin Ågren <[email protected]>
Quoted 7 lines
Quoted 3 lines
git merge-filetakes three positional arguments. Each of them is documented as<foo-file>. In preparation for teaching this command to alternatively take three object IDs, make these placeholders a bit moreMinor nit. Don't we want to say "three blob object names"? Unless we plan to grow this feature into accepting three tree object names, that is.
Hmm, yeah. Or just "three non-filename arguments". I do wonder: doesn't this mean that the second patch could/should possibly move away from the notion of "object ID"/--object-id? (That's not trying to shift any blame from one patch to the other, that's my honest reaction.)
Ah, yes, I thought I recognized this. Quoting your response [1] to v2:
Quoted 5 lines
I briefly thought about suggesting --blob-id instead of --object-id simply because you'd never want to feed it trees and commits, but the error message from
read_mmblob()the users would get mentions 'blob' to signal that non-blob objects are unwelcome, so the name of the optionwould be OK as-is.
Maybe you having a similar reaction a second time makes this smell a bit more?
[1] https://lore.kernel.org/git/[email protected]/
Martin
Re: [PATCH v3 1/2] git-merge-file doc: drop "-file" from argument placeholders
Quoted 10 lines · Martin Ågren
Quoted 9 lines · Junio C Hamano
Quoted 5 lines · brian m. carlson
From: Martin Ågren <[email protected]>
git merge-filetakes three positional arguments. Each of them is documented as<foo-file>. In preparation for teaching this command to alternatively take three object IDs, make these placeholders a bit more
Quoted 8 lines
Quoted 3 lines
Minor nit. Don't we want to say "three blob object names"? Unless we plan to grow this feature into accepting three tree object names, that is.
Hmm, yeah. Or just "three non-filename arguments". I do wonder: doesn't this mean that the second patch could/should possibly move away from the notion of "object ID"/
--object-id? (That's not trying to shift any blame from one patch to the other, that's my honest reaction.)
Not specifying an option would make this ambiguous. What if I have a file named "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"? Is that the empty blob, or is it that file? Normally we have ways to disambiguate this, but those don't work here because of the positional arguments.
Quoted 10 lines
Ah, yes, I thought I recognized this. Quoting your response [1] to v2:
Quoted 5 lines
I briefly thought about suggesting --blob-id instead of --object-id simply because you'd never want to feed it trees and commits, but the error message from
read_mmblob()the users would get mentions 'blob' to signal that non-blob objects are unwelcome, so the name of the optionwould be OK as-is.Maybe you having a similar reaction a second time makes this smell a bit more?
I think the name is fine. We don't typically use the phrase "blob ID" anywhere, but we do say "object ID". We'd need to say "--blob", but I'm not sure that's an improvement, and I fear it may be less understandable.
Signature · 2 lines
brian m. carlson (he/him or they/them) Toronto, Ontario, CA
Re: [PATCH v3 1/2] git-merge-file doc: drop "-file" from argument placeholders
Quoted 8 lines · brian m. carlson
Quoted 4 lines · Martin Ågren
Hmm, yeah. Or just "three non-filename arguments". I do wonder: doesn't this mean that the second patch could/should possibly move away from the notion of "object ID"/
--object-id? (That's not trying to shift any blame from one patch to the other, that's my honest reaction.)
Quoted 4 lines
Not specifying an option would make this ambiguous. What if I have a file named "
e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"? Is that the empty blob, or is it that file? Normally we have ways to disambiguate this, but those don't work here because of the positional arguments.
I didn't intend to suggest dropping the new option altogether, sorry for being unclear. I meant moving from --object-id to something else, such as --blob that you mention. Completely agreed that something explicit is needed here and that heuristics aren't possible.
Quoted 4 lines
I think the name is fine. We don't typically use the phrase "blob ID" anywhere, but we do say "object ID". We'd need to say "--blob", but I'm not sure that's an improvement, and I fear it may be less understandable.
Agreed. Thanks.
Martin
Re: [PATCH v3 1/2] git-merge-file doc: drop "-file" from argument placeholders
In reply to Martin ÅgrenQuoted 2 lines · Martin Ågren
Maybe you having a similar reaction a second time makes this smell a bit more?
Not at all. I am perfectly OK with --object-*, not --blob-*, as the end-user facing option name. I however strongly prefer to see our log messages record the thought behind the design accurately in order to help future developers when they wonder what our intention was back when the commit was created.
In this case, I want to see that we tell our future selves "even though we named the option 'object', we plan to support blobs and nothing else, at least for now".
Thanks.
PATCH v3 2/2 merge-file: add an option to process object IDs
In reply to brian m. carlsonFrom: "brian m. carlson" <[email protected]>
git merge-file knows how to merge files on the file system already. It would be helpful, however, to allow it to also merge single blobs. Teach it an --object-id option which means that its arguments are object IDs and not files to allow it to do so.
We handle the empty blob specially since read_mmblob doesn't read it directly and otherwise users cannot specify an empty ancestor.
--- Documentation/git-merge-file.txt | 19 +++++++++- builtin/merge-file.c | 62 +++++++++++++++++++++++--------- t/t6403-merge-file.sh | 58 ++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 17 deletions(-)
Documentation/git-merge-file.txt +18 -1
@@ -11,7 +11,7 @@ SYNOPSIS [verse] 'git merge-file' [-L <current-name> [-L <base-name> [-L <other-name>]]] [--ours|--theirs|--union] [-p|--stdout] [-q|--quiet] [--marker-size=<n>] - [--[no-]diff3] <current> <base> <other> + [--[no-]diff3] [--object-id] <current> <base> <other> DESCRIPTION
@@ -41,6 +41,10 @@ however, these conflicts are resolved favouring lines from `<current>`, lines from `<other>`, or lines from both respectively. The length of the conflict markers can be given with the `--marker-size` option. +If `--object-id` is specified, exactly the same behavior occurs, except that +instead of specifying what to merge as files, it is specified as a list of +object IDs referring to blobs. + The exit value of this program is negative on error, and the number of conflicts otherwise (truncated to 127 if there are more than that many conflicts). If the merge was clean, the exit value is 0.
@@ -53,6 +57,14 @@ linkgit:git[1]. OPTIONS ------- +--object-id:: + Specify the contents to merge as blobs in the current repository instead of + files. In this case, the operation must take place within a valid repository. ++ +If the `-p` option is specified, the merged file (including conflicts, if any) +goes to standard output as normal; otherwise, the merged file is written to the +object store and the object ID of its blob is written to standard output. + -L <label>:: This option may be given up to three times, and specifies labels to be used in place of the
@@ -94,6 +106,11 @@ EXAMPLES merges tmp/a123 and tmp/c345 with the base tmp/b234, but uses labels `a` and `c` instead of `tmp/a123` and `tmp/c345`. +`git merge-file -p --object-id abc1234 def567 890abcd`:: + + combines the changes of the blob abc1234 and 890abcd since def567, + tries to merge them and writes the result to standard output + GIT --- Part of the linkgit:git[1] suite
builtin/merge-file.c +46 -16
101 lines not on this page · raw message
t/t6403-merge-file.sh +58 -0
85 lines not on this page · raw message
Re: [PATCH v3 2/2] merge-file: add an option to process object IDs
Quoted 8 lines · brian m. carlson
From: "brian m. carlson" <[email protected]>
git merge-file knows how to merge files on the file system already. It would be helpful, however, to allow it to also merge single blobs. Teach it an
--object-idoption which means that its arguments are object IDs and not files to allow it to do so.
Quoted 4 lines
We handle the empty blob specially since
read_mmblobdoesn't read it directly and otherwise users cannot specify an empty ancestor.Signed-off-by brian m. carlson <[email protected]>
Ok, good solution to the misleading paragraph I noticed: dropping it.
Documentation/git-merge-file.txt SYNOPSIS · line 14
Quoted 4 lines
'git merge-file' [-L <current-name> [-L <base-name> [-L <other-name>]]]
[--ours|--theirs|--union] [-p|--stdout] [-q|--quiet] [--marker-size=<n>]Documentation/git-merge-file.txt +1
-1- [--[no-]diff3] <current> <base> <other> + [--[no-]diff3] [--object-id] <current> <base> <other>
Ok. This is where rebasing onto the new, initial patch could possibly have tripped up. Of course you didn't. Looks good.
Martin
Quoted 7 lines · brian m. carlson
This series introduces an --object-id option to git merge-file such that, instead of reading and writing from files on the system, it reads from and writes to the object store using blobs.
Changes from v2:
* Include a patch from Martin to pre-improve the documentation
* Remove incorrect portion of commit message
Looking good. Will replace. Shall we mark the topic ready for 'next'?
Thanks.