Backed out changeset 7f46fb9d639b

The cstore changes are breaking the build in some unusual ways and I will need
some time to fix them. Let's back it out for now.
This commit is contained in:
Durham Goode 2017-02-16 14:37:23 -08:00
parent ac609a8fcd
commit f797211a24
9 changed files with 14 additions and 355 deletions

View File

@ -116,7 +116,20 @@ DeltaChainIterator DatapackStore::getDeltaChain(const Key &key) {
Key *DatapackStoreKeyIterator::next() {
Key *key;
while ((key = _missing.next()) != NULL) {
if (!_store.contains(*key)) {
bool found = false;
for(std::vector<datapack_handle_t*>::iterator it = _store._packs.begin();
it != _store._packs.end();
it++) {
datapack_handle_t *pack = *it;
pack_index_entry_t packindex;
if (find(pack, (uint8_t*)key->node, &packindex)) {
found = true;
break;
}
}
if (!found) {
return key;
}
}
@ -124,20 +137,6 @@ Key *DatapackStoreKeyIterator::next() {
return NULL;
}
bool DatapackStore::contains(const Key &key) {
for(std::vector<datapack_handle_t*>::iterator it = _packs.begin();
it != _packs.end();
it++) {
datapack_handle_t *pack = *it;
pack_index_entry_t packindex;
if (find(pack, (uint8_t*)key.node, &packindex)) {
return true;
}
}
return false;
}
DatapackStoreKeyIterator DatapackStore::getMissing(KeyIterator &missing) {
return DatapackStoreKeyIterator(*this, missing);
}

View File

@ -80,8 +80,6 @@ class DatapackStore {
DeltaChainIterator getDeltaChain(const Key &key);
DatapackStoreKeyIterator getMissing(KeyIterator &missing);
bool contains(const Key &key);
};
#endif //DATAPACKSTORE_H

View File

@ -18,9 +18,6 @@ extern "C" {
#include "../ctreemanifest/pythonutil.h"
#include "datapackstore.h"
#include "key.h"
#include "uniondatapackstore.h"
// --------- DatapackStore Implementation ---------
struct py_datapackstore {
PyObject_HEAD;
@ -164,8 +161,6 @@ static PyObject *datapackstore_getmissing(py_datapackstore *self, PyObject *keys
}
}
// --------- DatapackStore Declaration ---------
static PyMethodDef datapackstore_methods[] = {
{"getdeltachain", (PyCFunction)datapackstore_getdeltachain, METH_VARARGS, ""},
{"getmissing", (PyCFunction)datapackstore_getmissing, METH_O, ""},
@ -213,145 +208,6 @@ static PyTypeObject datapackstoreType = {
0, /* tp_alloc */
};
// --------- UnionDatapackStore Implementation ---------
struct py_uniondatapackstore {
PyObject_HEAD;
UnionDatapackStore uniondatapackstore;
// Keep a reference to the python objects so we can decref them later.
std::vector<PythonObj> substores;
};
/*
* Initializes the contents of a uniondatapackstore
*/
static int uniondatapackstore_init(py_uniondatapackstore *self, PyObject *args) {
PyObject *storeList;
if (!PyArg_ParseTuple(args, "O", &storeList)) {
return -1;
}
try {
std::vector<DatapackStore*> stores;
std::vector<PythonObj> pySubStores;
PyObject *item;
PythonObj inputIterator = PyObject_GetIter(storeList);
while ((item = PyIter_Next(inputIterator)) != NULL) {
// Record the substore references, so:
// A) We can decref them in case of an error.
// B) They don't get GC'd while the uniondatapackstore holds on to them.
pySubStores.push_back(PythonObj(item));
int isinstance = PyObject_IsInstance(item, (PyObject*)&datapackstoreType);
if (isinstance == 0) {
PyErr_SetString(PyExc_RuntimeError, "cuniondatapackstore only accepts cdatapackstore");
return -1;
} else if (isinstance != 1) {
// Error
return -1;
}
py_datapackstore *pySubStore = (py_datapackstore*)item;
stores.push_back(&pySubStore->datapackstore);
}
// We have to manually call the member constructor, since the provided 'self'
// is just zerod out memory.
new(&self->uniondatapackstore) UnionDatapackStore(stores);
new(&self->substores) std::vector<PythonObj>();
self->substores = pySubStores;
} catch (const std::exception &ex) {
PyErr_SetString(PyExc_RuntimeError, ex.what());
return -1;
}
return 0;
}
static void uniondatapackstore_dealloc(py_uniondatapackstore *self) {
self->uniondatapackstore.~UnionDatapackStore();
self->substores.~vector<PythonObj>();
PyObject_Del(self);
}
static PyObject *uniondatapackstore_getmissing(py_uniondatapackstore *self, PyObject *keys) {
try {
PythonObj result = PyList_New(0);
PythonObj inputIterator = PyObject_GetIter(keys);
PythonKeyIterator keysIter((PyObject*)inputIterator);
UnionDatapackStoreKeyIterator missingIter = self->uniondatapackstore.getMissing(keysIter);
Key *key;
while ((key = missingIter.next()) != NULL) {
PythonObj missingKey = Py_BuildValue("(s#s#)", key->name.c_str(), key->name.size(),
key->node, 20);
if (PyList_Append(result, (PyObject*)missingKey)) {
return NULL;
}
}
return result.returnval();
} catch (const pyexception &ex) {
return NULL;
} catch (const std::exception &ex) {
PyErr_SetString(PyExc_RuntimeError, ex.what());
return NULL;
}
}
// --------- UnionDatapackStore Declaration ---------
static PyMethodDef uniondatapackstore_methods[] = {
{"getmissing", (PyCFunction)uniondatapackstore_getmissing, METH_O, ""},
{NULL, NULL}
};
static PyTypeObject uniondatapackstoreType = {
PyObject_HEAD_INIT(NULL)
0, /* ob_size */
"cstore.uniondatapackstore", /* tp_name */
sizeof(py_uniondatapackstore), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)uniondatapackstore_dealloc, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_compare */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence - length/contains */
0, /* tp_as_mapping - getitem/setitem */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"TODO", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
uniondatapackstore_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
(initproc)uniondatapackstore_init, /* tp_init */
0, /* tp_alloc */
};
static PyMethodDef mod_methods[] = {
{NULL, NULL}
};
@ -371,12 +227,4 @@ PyMODINIT_FUNC initcstore(void)
}
Py_INCREF(&datapackstoreType);
PyModule_AddObject(mod, "datapackstore", (PyObject *)&datapackstoreType);
// Init datapackstore
uniondatapackstoreType.tp_new = PyType_GenericNew;
if (PyType_Ready(&uniondatapackstoreType) < 0) {
return;
}
Py_INCREF(&uniondatapackstoreType);
PyModule_AddObject(mod, "uniondatapackstore", (PyObject *)&uniondatapackstoreType);
}

View File

@ -1,49 +0,0 @@
// uniondatapackstore.cpp - implementation of a union datapack store
//
// Copyright 2017 Facebook, Inc.
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
//
// no-check-code
#include <algorithm>
#include "uniondatapackstore.h"
UnionDatapackStore::UnionDatapackStore(std::vector<DatapackStore*> stores) :
_stores(stores) {
}
UnionDatapackStore::~UnionDatapackStore() {
// TODO: we should manage the substore lifetimes here, but because they are
// also controlled by Python, we need to let python handle it and manage the
// refcount in the py_uniondatapackstore type.
}
Key *UnionDatapackStoreKeyIterator::next() {
Key *key;
while ((key = _missing.next()) != NULL) {
if (!_store.contains(*key)) {
return key;
}
}
return NULL;
}
bool UnionDatapackStore::contains(const Key &key) {
for(std::vector<DatapackStore*>::iterator it = _stores.begin();
it != _stores.end();
it++) {
DatapackStore *substore = *it;
if (substore->contains(key)) {
return true;
}
}
return false;
}
UnionDatapackStoreKeyIterator UnionDatapackStore::getMissing(KeyIterator &missing) {
return UnionDatapackStoreKeyIterator(*this, missing);
}

View File

@ -1,51 +0,0 @@
// uniondatapackstore.h - c++ declarations for a union datapack store
//
// Copyright 2017 Facebook, Inc.
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2 or any later version.
//
// no-check-code
#ifndef UNIONDATAPACKSTORE_H
#define UNIONDATAPACKSTORE_H
extern "C" {
#include "../cdatapack/cdatapack.h"
}
#include "key.h"
#include "datapackstore.h"
#include <cstring>
#include <vector>
#include <stdexcept>
class UnionDatapackStore;
class UnionDatapackStoreKeyIterator : public KeyIterator {
private:
UnionDatapackStore &_store;
KeyIterator &_missing;
public:
UnionDatapackStoreKeyIterator(UnionDatapackStore &store, KeyIterator &missing) :
_store(store),
_missing(missing) {}
Key *next();
};
class UnionDatapackStore {
public:
std::vector<DatapackStore*> _stores;
UnionDatapackStore(std::vector<DatapackStore*> stores);
~UnionDatapackStore();
bool contains(const Key &key);
UnionDatapackStoreKeyIterator getMissing(KeyIterator &missing);
};
#endif //UNIONDATAPACKSTORE_H

View File

@ -126,7 +126,6 @@ else:
sources=[
'cstore/py-cstore.cpp',
'cstore/datapackstore.cpp',
'cstore/uniondatapackstore.cpp',
],
include_dirs=[
'cstore',

View File

@ -1,82 +0,0 @@
#!/usr/bin/env python2.7
import hashlib
import os
import random
import shutil
import sys
import tempfile
import unittest
import silenttestrunner
# Load the local cstore, not the system one
fullpath = os.path.join(os.getcwd(), __file__)
sys.path.insert(0, os.path.dirname(os.path.dirname(fullpath)))
from cstore import (
datapackstore,
uniondatapackstore,
)
from remotefilelog.datapack import (
fastdatapack,
mutabledatapack,
)
from mercurial.node import nullid
import mercurial.ui
class uniondatapackstoretests(unittest.TestCase):
def setUp(self):
random.seed(0)
self.tempdirs = []
def tearDown(self):
for d in self.tempdirs:
shutil.rmtree(d)
def makeTempDir(self):
tempdir = tempfile.mkdtemp()
self.tempdirs.append(tempdir)
return tempdir
def getHash(self, content):
return hashlib.sha1(content).digest()
def getFakeHash(self):
return ''.join(chr(random.randint(0, 255)) for _ in range(20))
def createPack(self, packdir, revisions=None):
if revisions is None:
revisions = [("filename", self.getFakeHash(), nullid, "content")]
packer = mutabledatapack(mercurial.ui.ui(), packdir)
for filename, node, base, content in revisions:
packer.add(filename, node, base, content)
path = packer.close()
return fastdatapack(path)
def testGetMissing(self):
packdir = self.makeTempDir()
revisions = [("foo", self.getFakeHash(), nullid, "content")]
self.createPack(packdir, revisions=revisions)
unionstore = uniondatapackstore([datapackstore(packdir)])
missinghash1 = self.getFakeHash()
missinghash2 = self.getFakeHash()
missing = unionstore.getmissing([
(revisions[0][0], revisions[0][1]),
("foo", missinghash1),
("foo2", missinghash2),
])
self.assertEquals(2, len(missing))
self.assertEquals(set([("foo", missinghash1), ("foo2", missinghash2)]),
set(missing))
if __name__ == '__main__':
silenttestrunner.main(__name__)

View File

@ -58,8 +58,6 @@ New errors are not allowed. Warnings are strongly discouraged.
Skipping cstore/datapackstore.cpp it has no-che?k-code (glob)
Skipping cstore/datapackstore.h it has no-che?k-code (glob)
Skipping cstore/key.h it has no-che?k-code (glob)
Skipping cstore/uniondatapackstore.cpp it has no-che?k-code (glob)
Skipping cstore/uniondatapackstore.h it has no-che?k-code (glob)
Skipping ctreemanifest/convert.h it has no-che?k-code (glob)
Skipping ctreemanifest/manifest.cpp it has no-che?k-code (glob)
Skipping ctreemanifest/manifest.h it has no-che?k-code (glob)

View File

@ -5,4 +5,3 @@
$ export PYTHONPATH
$ python $TESTDIR/cstore-datapackstore.py
$ python $TESTDIR/cstore-uniondatapackstore.py