4.6 Exercise 6
From git repo, checkout revision 0194c9ad72 and merge revision aa46a0da30.
There will be a CB in ref-filter.c:
Listing 4.14:Exercise 6 - CB in ref-filter.c843<<<<<<< HEAD 844/* 845 * Given an object name, read the object data and size, and return a 846 * "struct object". If the object data we are returning is also borrowed 847 * by the "struct object" representation, set *eaten as well---it is a 848 * signal from parse_object_buffer to us not to free the buffer. 849 */ 850static void *get_obj(const struct object_id *oid, struct object **obj, unsigned long *sz, int *eaten) 851{ 852 enum object_type type; 853 void *buf = read_object_file(oid, &type, sz); 854 855 if (buf) 856 *obj = parse_object_buffer(the_repository, oid, type, *sz, 857 buf, eaten); 858 else 859 *obj = NULL; 860 return buf; 861} 862 863||||||| e3331758f1 864/* 865 * Given an object name, read the object data and size, and return a 866 * "struct object". If the object data we are returning is also borrowed 867 * by the "struct object" representation, set *eaten as well---it is a 868 * signal from parse_object_buffer to us not to free the buffer. 869 */ 870static void *get_obj(const struct object_id *oid, struct object **obj, unsigned long *sz, int *eaten) 871{ 872 enum object_type type; 873 void *buf = read_object_file(oid, &type, sz); 874 875 if (buf) 876 *obj = parse_object_buffer(oid, type, *sz, buf, eaten); 877 else 878 *obj = NULL; 879 return buf; 880} 881 882======= 883>>>>>>> aa46a0da30
It’s a conflict ouf of deleted code.
dMU
Modified the call to parse_object_buffer() to have the_repository as the first
argument on line 856.
dML
Deleted the whole section of code.
Resolution
Should we delete the whole CB and move on with our lives? I really hope you had a
Pavlov reflex saying NOOOOO!!!!! Good! All the hard work is paying off. We need
to find out what happened with that code. The hard way is to find out in what
revision that code was deleted to see if it was moved. First, we do the git blame
–reverse:
Listing 4.15:Exercise 6 - git blame –reverse on ref-filter.c. . . 04f6ee1a58e 807) if (buf) 04f6ee1a58e 808) *obj = parse_object_buffer(oid, type, *sz, buf, eaten); 04f6ee1a58e 809) else 04f6ee1a58e 810) *obj = NULL;
The last revision when the line was present was on 04f6ee1a58e. Let’s check
what follows that revision:
Listing 4.16:Exercise 6 - git log –oneline on ref-filter.c$ git log --oneline --graph 04f6ee1a58e..aa46a0da30 -- ref-filter.c * aa46a0da30 ref-filter: use oid_object_info() to get object * e2255179f6 ref-filter: merge get_obj and get_object
And checking those two revisions we find that the code was apparently deleted in
e2255179f6.
Listing 4.17:Exercise 6 - git show e2255179f6843$ git show e2255179f6 --pretty= 844diff --git a/ref-filter.c b/ref-filter.c 845index 8db7ca95b1..2b401a17c4 100644 846--- a/ref-filter.c 847+++ b/ref-filter.c 848@@ -797,24 +797,6 @@ int verify_ref_format(struct ref_format *format) 849 return 0; 850 } 851 852-/* 853- * Given an object name, read the object data and size, and return a 854- * "struct object". If the object data we are returning is also borrowed 855- * by the "struct object" representation, set *eaten as well---it is a 856- * signal from parse_object_buffer to us not to free the buffer. 857- */ 858-static void *get_obj(const struct object_id *oid, struct object **obj, unsigned long *sz, int *eaten) 859-{ 860- enum object_type type; 861- void *buf = read_object_file(oid, &type, sz); 862- 863- if (buf) 864- *obj = parse_object_buffer(oid, type, *sz, buf, eaten); 865- else 866- *obj = NULL; 867- return buf; 868-} 869- 870 static int grab_objectname(const char *name, const struct object_id *oid, 871 struct atom_value *v, struct used_atom *atom) 872 { 873@@ -1437,21 +1419,25 @@ static const char *get_refname(struct used_atom *atom, struct ref_array_item *re 874 } 875 876 static int get_object(struct ref_array_item *ref, const struct object_id *oid, 877- int deref, struct object **obj, struct strbuf *err) 878+ int deref, struct object **obj, struct strbuf *err) 879 { 880 /* parse_object_buffer() will set eaten to 0 if free() will be needed */ 881 int eaten = 1; 882 int ret = 0; 883 unsigned long size; 884- void *buf = get_obj(oid, obj, &size, &eaten); 885+ enum object_type type; 886+ void *buf = read_object_file(oid, &type, &size); 887 if (!buf) 888 ret = strbuf_addf_ret(err, -1, _("missing object %s for %s"), 889 oid_to_hex(oid), ref->refname); 890- else if (!*obj) 891- ret = strbuf_addf_ret(err, -1, _("parse_object_buffer failed on %s for %s"), 892- oid_to_hex(oid), ref->refname); 893- else 894- grab_values(ref->value, deref, *obj, buf, size); 895+ else { 896+ *obj = parse_object_buffer(oid, type, size, buf, &eaten); 897+ if (!*obj) 898+ ret = strbuf_addf_ret(err, -1, _("parse_object_buffer failed on %s for %s"), 899+ oid_to_hex(oid), ref->refname); 900+ else 901+ grab_values(ref->value, deref, *obj, buf, size); 902+ } 903 if (!eaten) 904 free(buf); 905 return ret;
In the second hunk we can see that the call to parse_object_buffer was added
back. In other words, the call was moved, and that call is still in our conflicted file,
in line 1520:
Listing 4.18:Exercise 6 - section of ref-filter.c1519 if (oi->info.contentp) { 1520 *obj = parse_object_buffer(&oi->oid, oi->type, oi->size, oi->content, &eaten); 1521 if (!obj) { 1522 if (!eaten) 1523 free(oi->content); 1524 return strbuf_addf_ret(err, -1, _("parse_object_buffer failed on %s for %s"), 1525 oid_to_hex(&oi->oid), ref->refname); 1526 } 1527 grab_values(ref->value, deref, *obj, oi->content, oi->size); 1528 }
So all we need to do, as our dMU requests, is to add the_repository as the first
argument to the call on line 1520:
Listing 4.19:Exercise 6 - adjusted section of ref-filter.c1519 if (oi->info.contentp) { 1520 *obj = parse_object_buffer(the_repository, &oi->oid, oi->type, oi->size, oi->content, &eaten); 1521 if (!obj) { 1522 if (!eaten) 1523 free(oi->content); 1524 return strbuf_addf_ret(err, -1, _("parse_object_buffer failed on %s for %s"), 1525 oid_to_hex(&oi->oid), ref->refname); 1526 } 1527 grab_values(ref->value, deref, *obj, oi->content, oi->size); 1528 }
We remove the original CB:
Listing 4.20:Exercise 6 - remove CB in ref-filter.c840 return 0; 841} 842 843static int grab_objectname(const char *name, const struct object_id *oid, 844 struct atom_value *v, struct used_atom *atom) 845{
And if you now check differences with revision c83149ace6, you should get
none.