4.6 Ejercicio 6
Del repo de git, hagan checkout de la revisión 0194c9ad72 y hagan un merge de
aa46a0da30. Van a ver un CB en ref-filter.c:
Listing 4.14:Ejercico 6 - CB en 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
Es un conflicto por código borrado.
dMU
Se modificó la llamada a parse_object_buffer() para que el primer argumento sea
the_repository en la línea 856.
dML
Se borró toda la sección de código.
Resolución
Deberíamos borrar todo el CB y seguir adelante con nuestras vidas? Espero que
hayan tenid un rejlejo de Pavlov diciendo NOOOOO!!!!!. Excelente! Todo ese
trabajo duro está dando frutos. Debemos averiguar qué pasó con ese código. La
forma dura es averiguar en qué revision se borró el código para ver si fue movido.
Primero hacemos el git blame –reverse:
Listing 4.15:Ejercicio 6 - git blame –reverse en 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;
La última revisión en la cual la línea estuvo presente fue en 04f6ee1a58e.
Vemos qué sigue a esa revisión:
Listing 4.16:Ejercicio 6 - git log –oneline en 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
Y al verificar esas dos revisions vemos queel código fue aparentemente borrado
en e2255179f6:
Listing 4.17:Ejercicio 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;
Pero en el segundo hunk se puede ver que la llamada a parse_object_buffer
fue agregada de nuevo. En otras palabras, la llamada fue movida, y esa llamada
sigue en nuestro archivo, en la línea 1520:
Listing 4.18:Ejercicio 6 - sección de 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 }
Así que todo loque debemos hacer, como nos lo quiere el dMU, es agregar
the_repository como primer argumento a la llamada e la línea 1520:
Listing 4.19:Ejercicio 6 - Sección ajustada de 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 }
Se remuele el CB original:
Listing 4.20:Ejercicio 6 - CB removido en 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{
Y si verifican las diferencias con la revisión c83149ace6, no deberían obtener
ninguna.