[fastmanifest] support the 0-argument fastmanifest constructor

Summary: If it is 0-argument, then just attach an empty tree.

Test Plan:
```
[andromeda]:~/work/mercurial/facebook-hg-rpms/fb-hgext:24160e2> ipython-2.7
Python 2.7.11 (default, Mar  1 2016, 18:40:10)
Type "copyright", "credits" or "license" for more information.

IPython 2.2.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import fastmanifest_wrapper

In [2]: a = fastmanifest_wrapper.fastManifest()

In [3]: a['foo'] = ('c'*20, "")

In [4]: a.text()
Out[4]: 'foo\x006363636363636363636363636363636363636363\n'

In [5]: del a['foo']

In [6]: a.text()
Out[6]: ''
```

Reviewers: lcharignon

Reviewed By: lcharignon

Subscribers: mitrandir, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D3289430

Tasks: 11145013

Signature: t1:3289430:1463063731:f99f4690c9c8e57b2845010a62ceaea16d3643cc
This commit is contained in:
Tony Tung 2016-05-16 12:41:26 -07:00
parent bf2275ddbe
commit ef50166560

View File

@ -163,9 +163,20 @@ static int fastmanifest_init(fastmanifest *self, PyObject *args) {
PyObject *pydata = NULL;
char *data;
ssize_t len;
if (!PyArg_ParseTuple(args, "S", &pydata)) {
if (!PyArg_ParseTuple(args, "|S", &pydata)) {
return -1;
}
if (pydata == NULL) {
// no string. initialize it to an empty tree.
self->tree = alloc_tree();
if (self->tree == NULL) {
PyErr_NoMemory();
return -1;
}
return 0;
}
int err = PyString_AsStringAndSize(pydata, &data, &len);
if (err == -1)
return -1;