mercurial/cext/revlog.c
changeset 47034 0d8ff1f4ab0c
parent 46974 3c9208702db3
child 47035 4f2b5f9d8cc4
equal deleted inserted replaced
47033:824ee4aaa09b 47034:0d8ff1f4ab0c
   339 		return Py_BuildValue(v2_tuple_format, offset_flags, comp_len,
   339 		return Py_BuildValue(v2_tuple_format, offset_flags, comp_len,
   340 		                     uncomp_len, base_rev, link_rev, parent_1,
   340 		                     uncomp_len, base_rev, link_rev, parent_1,
   341 		                     parent_2, c_node_id, self->nodelen,
   341 		                     parent_2, c_node_id, self->nodelen,
   342 		                     sidedata_offset, sidedata_comp_len);
   342 		                     sidedata_offset, sidedata_comp_len);
   343 	}
   343 	}
       
   344 }
       
   345 /*
       
   346  * Return the raw binary string representing a revision
       
   347  */
       
   348 static PyObject *index_entry_binary(indexObject *self, PyObject *args)
       
   349 {
       
   350 	long rev;
       
   351 	int header;
       
   352 	const char *data;
       
   353 	char entry[v2_hdrsize];
       
   354 
       
   355 	Py_ssize_t length = index_length(self);
       
   356 
       
   357 	if (!PyArg_ParseTuple(args, "lI", &rev, &header)) {
       
   358 		return NULL;
       
   359 	}
       
   360 	if (rev < 0 || rev >= length) {
       
   361 		PyErr_Format(PyExc_ValueError, "revlog index out of range: %ld",
       
   362 		             rev);
       
   363 		return NULL;
       
   364 	};
       
   365 
       
   366 	data = index_deref(self, rev);
       
   367 	if (data == NULL)
       
   368 		return NULL;
       
   369 	if (rev == 0) {
       
   370 		// put the header at the start of the first entry
       
   371 		memcpy(entry, data, self->hdrsize);
       
   372 		putbe32(header, entry);
       
   373 		return PyBytes_FromStringAndSize(entry, self->hdrsize);
       
   374 	}
       
   375 	return PyBytes_FromStringAndSize(data, self->hdrsize);
   344 }
   376 }
   345 
   377 
   346 /*
   378 /*
   347  * Return the hash of node corresponding to the given rev.
   379  * Return the hash of node corresponding to the given rev.
   348  */
   380  */
  2857     {"partialmatch", (PyCFunction)index_partialmatch, METH_VARARGS,
  2889     {"partialmatch", (PyCFunction)index_partialmatch, METH_VARARGS,
  2858      "match a potentially ambiguous node ID"},
  2890      "match a potentially ambiguous node ID"},
  2859     {"shortest", (PyCFunction)index_shortest, METH_VARARGS,
  2891     {"shortest", (PyCFunction)index_shortest, METH_VARARGS,
  2860      "find length of shortest hex nodeid of a binary ID"},
  2892      "find length of shortest hex nodeid of a binary ID"},
  2861     {"stats", (PyCFunction)index_stats, METH_NOARGS, "stats for the index"},
  2893     {"stats", (PyCFunction)index_stats, METH_NOARGS, "stats for the index"},
       
  2894     {"entry_binary", (PyCFunction)index_entry_binary, METH_VARARGS,
       
  2895      "return an entry in binary form"},
  2862     {NULL} /* Sentinel */
  2896     {NULL} /* Sentinel */
  2863 };
  2897 };
  2864 
  2898 
  2865 static PyGetSetDef index_getset[] = {
  2899 static PyGetSetDef index_getset[] = {
  2866     {"nodemap", (getter)index_nodemap, NULL, "nodemap", NULL},
  2900     {"nodemap", (getter)index_nodemap, NULL, "nodemap", NULL},