~jelmer/bzr-svn/svn-1.5

« back to all changes in this revision

Viewing changes to ra.c

  • Committer: Jelmer Vernooij
  • Date: 2008-07-07 11:29:11 UTC
  • mfrom: (1196.1.245 0.4)
  • Revision ID: jelmer@samba.org-20080707112911-fca6wpxr457n690x
MergeĀ 0.4.

Show diffs side-by-side

added added

removed removed

Lines of Context:
414
414
                if (ops == NULL)
415
415
                        return NULL;
416
416
                for (i = 0; i < window->num_ops; i++) {
417
 
                        PyList_SetItem(ops, i, Py_BuildValue("(iII)", window->ops[i].action_code, 
418
 
                                                window->ops[i].offset, 
419
 
                                                window->ops[i].length));
 
417
                        PyObject *pyval = Py_BuildValue("(iII)", 
 
418
                                                                                        window->ops[i].action_code, 
 
419
                                                                                        window->ops[i].offset, 
 
420
                                                                                        window->ops[i].length);
 
421
                        if (pyval == NULL)
 
422
                                return NULL;
 
423
                        PyList_SetItem(ops, i, pyval);
420
424
                }
421
425
                if (window->new_data != NULL && window->new_data->data != NULL) {
422
426
                        py_new_data = PyString_FromStringAndSize(window->new_data->data, window->new_data->len);
423
427
                } else {
424
428
                        py_new_data = Py_None;
425
429
                }
426
 
                py_window = Py_BuildValue("((LIIiOO))", window->sview_offset, window->sview_len, window->tview_len, 
427
 
                                                                        window->src_ops, ops, py_new_data);
 
430
                py_window = Py_BuildValue("((LIIiOO))", 
 
431
                                                                  window->sview_offset, 
 
432
                                                                  window->sview_len, 
 
433
                                                                  window->tview_len, 
 
434
                                                                  window->src_ops, ops, py_new_data);
 
435
                if (py_window == NULL)
 
436
                        return NULL;
428
437
                Py_DECREF(ops);
429
438
                Py_DECREF(py_new_data);
430
439
        }
655
664
        if (fn == Py_None) {
656
665
                return;
657
666
        }
658
 
        ret = PyObject_CallFunction(fn, "ll", progress, total);
 
667
        ret = PyObject_CallFunction(fn, "LL", progress, total);
659
668
        /* TODO: What to do with exceptions raised here ? */
660
669
        Py_XDECREF(ret);
661
670
}
1450
1459
                rev = (svn_revnum_t *)apr_palloc(temp_pool, sizeof(svn_revnum_t));
1451
1460
                *rev = PyLong_AsLong(v);
1452
1461
                apr_hash_set(hash_path_revs, PyString_AsString(k), PyString_Size(k), 
1453
 
                                         PyString_AsString(v));
 
1462
                                         rev);
1454
1463
        }
1455
1464
        RUN_RA_WITH_POOL(temp_pool, ra, svn_ra_lock(ra->ra, hash_path_revs, comment, steal_lock,
1456
1465
                                         py_lock_func, lock_func, temp_pool));
1457
1466
        apr_pool_destroy(temp_pool);
1458
 
        return NULL;
 
1467
        Py_RETURN_NONE;
1459
1468
}
1460
1469
 
1461
1470
static PyObject *ra_get_locks(PyObject *self, PyObject *args)
1484
1493
        ret = PyDict_New();
1485
1494
        for (idx = apr_hash_first(temp_pool, hash_locks); idx != NULL;
1486
1495
                 idx = apr_hash_next(idx)) {
 
1496
                PyObject *pyval;
1487
1497
                apr_hash_this(idx, (const void **)&key, &klen, (void **)&lock);
1488
 
                PyDict_SetItemString(ret, key, pyify_lock(lock));
 
1498
                pyval = pyify_lock(lock);
 
1499
                if (pyval == NULL) {
 
1500
                        apr_pool_destroy(temp_pool);
 
1501
                        return NULL;
 
1502
                }
 
1503
                PyDict_SetItemString(ret, key, pyval);
1489
1504
        }
1490
1505
 
1491
1506
        apr_pool_destroy(temp_pool);
1529
1544
        apr_pool_destroy(temp_pool);
1530
1545
        return ret;
1531
1546
}
 
1547
 
 
1548
#if SVN_VER_MAJOR >= 1 && SVN_VER_MINOR >= 5
 
1549
static PyObject *range_to_tuple(svn_merge_range_t *range)
 
1550
{
 
1551
        return Py_BuildValue("(llb)", range->start, range->end, range->inheritable);
 
1552
}
 
1553
 
 
1554
static PyObject *merge_rangelist_to_list(apr_array_header_t *rangelist)
 
1555
{
 
1556
        PyObject *ret;
 
1557
        int i;
 
1558
 
 
1559
        ret = PyList_New(rangelist->nelts);
 
1560
 
 
1561
        for (i = 0; i < rangelist->nelts; i++) {
 
1562
                PyObject *pyval = range_to_tuple(APR_ARRAY_IDX(rangelist, i, svn_merge_range_t *));
 
1563
                if (pyval == NULL)
 
1564
                        return NULL;
 
1565
                PyList_SetItem(ret, i, pyval);
 
1566
        }
 
1567
        return ret;
 
1568
}
 
1569
 
 
1570
static PyObject *mergeinfo_to_dict(svn_mergeinfo_t mergeinfo, apr_pool_t *temp_pool)
 
1571
{
 
1572
        PyObject *ret = PyDict_New();
 
1573
        char *key;
 
1574
        apr_ssize_t klen;
 
1575
        apr_hash_index_t *idx;
 
1576
        apr_array_header_t *range;
 
1577
 
 
1578
        for (idx = apr_hash_first(temp_pool, mergeinfo); idx != NULL; 
 
1579
                idx = apr_hash_next(idx)) {
 
1580
                PyObject *pyval;
 
1581
                apr_hash_this(idx, (const void **)&key, &klen, (void **)&range);
 
1582
                pyval = merge_rangelist_to_list(range);
 
1583
                if (pyval == NULL)
 
1584
                        return NULL;
 
1585
                PyDict_SetItemString(ret, key, pyval);
 
1586
        }
 
1587
 
 
1588
        return ret;
 
1589
}
 
1590
#endif
 
1591
 
 
1592
static PyObject *ra_mergeinfo(PyObject *self, PyObject *args)
 
1593
{
 
1594
#if SVN_VER_MAJOR >= 1 && SVN_VER_MINOR >= 5
 
1595
        RemoteAccessObject *ra = (RemoteAccessObject *)self;
 
1596
        apr_array_header_t *apr_paths;
 
1597
        apr_pool_t *temp_pool;
 
1598
        svn_mergeinfo_catalog_t catalog;
 
1599
        apr_ssize_t klen;
 
1600
        apr_hash_index_t *idx;
 
1601
        svn_mergeinfo_t val;
 
1602
        char *key;
 
1603
        PyObject *ret;
 
1604
        svn_revnum_t revision = -1;
 
1605
        PyObject *paths;
 
1606
        svn_mergeinfo_inheritance_t inherit = svn_mergeinfo_explicit;
 
1607
        svn_boolean_t include_descendants;
 
1608
 
 
1609
        if (!PyArg_ParseTuple(args, "O|lib", &paths, &revision, &inherit, &include_descendants))
 
1610
                return NULL;
 
1611
 
 
1612
        temp_pool = Pool(NULL);
 
1613
        if (temp_pool == NULL)
 
1614
                return NULL;
 
1615
 
 
1616
        if (!string_list_to_apr_array(temp_pool, paths, &apr_paths)) {
 
1617
                apr_pool_destroy(temp_pool);
 
1618
                return NULL;
 
1619
        }
 
1620
 
 
1621
        RUN_RA_WITH_POOL(temp_pool, ra, svn_ra_get_mergeinfo(ra->ra, 
 
1622
                     &catalog, apr_paths, revision, inherit, 
 
1623
                                         include_descendants,
 
1624
                     temp_pool));
 
1625
 
 
1626
        ret = PyDict_New();
 
1627
 
 
1628
        if (catalog != NULL) {
 
1629
                for (idx = apr_hash_first(temp_pool, catalog); idx != NULL; 
 
1630
                        idx = apr_hash_next(idx)) {
 
1631
                        PyObject *pyval;
 
1632
                        apr_hash_this(idx, (const void **)&key, &klen, (void **)&val);
 
1633
                        pyval = mergeinfo_to_dict(val, temp_pool);
 
1634
                        if (pyval == NULL) {
 
1635
                                apr_pool_destroy(temp_pool);
 
1636
                                return NULL;
 
1637
                        }
 
1638
                        PyDict_SetItemString(ret, key, pyval);
 
1639
                }
 
1640
        }
 
1641
 
 
1642
        apr_pool_destroy(temp_pool);
 
1643
 
 
1644
        return ret;
 
1645
#else
 
1646
        PyErr_SetString(PyExc_NotImplementedError, "mergeinfo is only supported in Subversion >= 1.5");
 
1647
        return NULL;
 
1648
#endif
 
1649
}
 
1650
 
 
1651
#if SVN_VER_MAJOR >= 1 && SVN_VER_MINOR >= 5
 
1652
static svn_error_t *py_location_segment_receiver(svn_location_segment_t *segment, void *baton, apr_pool_t *pool)
 
1653
{
 
1654
        PyObject *fn = baton, *ret;
 
1655
 
 
1656
        ret = PyObject_CallFunction(fn, "llz", segment->range_start, segment->range_end, segment->path);
 
1657
        if (ret == NULL)
 
1658
                return py_svn_error();
 
1659
        Py_XDECREF(ret);
 
1660
        return NULL;
 
1661
}
 
1662
#endif
 
1663
 
 
1664
static PyObject *ra_get_location_segments(PyObject *self, PyObject *args)
 
1665
{
 
1666
#if SVN_VER_MAJOR >= 1 && SVN_VER_MINOR >= 5
 
1667
        RemoteAccessObject *ra = (RemoteAccessObject *)self;
 
1668
        svn_revnum_t peg_revision, start_revision, end_revision;
 
1669
        char *path;
 
1670
        PyObject *py_rcvr;
 
1671
        apr_pool_t *temp_pool;
 
1672
 
 
1673
        if (!PyArg_ParseTuple(args, "slllO", &path, &peg_revision, &start_revision, 
 
1674
                                                  &end_revision, &py_rcvr))
 
1675
                return NULL;
 
1676
 
 
1677
        temp_pool = Pool(NULL);
 
1678
        if (temp_pool == NULL)
 
1679
                return NULL;
 
1680
 
 
1681
        RUN_RA_WITH_POOL(temp_pool, ra, svn_ra_get_location_segments(ra->ra, 
 
1682
                                         path, peg_revision, start_revision, end_revision,
 
1683
                                         py_location_segment_receiver, 
 
1684
                                         py_rcvr, temp_pool));
 
1685
 
 
1686
        apr_pool_destroy(temp_pool);
 
1687
        Py_RETURN_NONE;
 
1688
#else
 
1689
        PyErr_SetString(PyExc_NotImplementedError, "mergeinfo is only supported in Subversion >= 1.5");
 
1690
        return NULL;
 
1691
#endif
 
1692
}
 
1693
 
1532
1694
        
1533
1695
static PyObject *ra_get_file_revs(PyObject *self, PyObject *args)
1534
1696
{
1592
1754
        { "get_locks", ra_get_locks, METH_VARARGS, NULL },
1593
1755
        { "lock", ra_lock, METH_VARARGS, NULL },
1594
1756
        { "unlock", ra_unlock, METH_VARARGS, NULL },
 
1757
        { "mergeinfo", ra_mergeinfo, METH_VARARGS, NULL },
 
1758
        { "get_location_segments", ra_get_location_segments, METH_VARARGS, NULL },
1595
1759
        { "has_capability", ra_has_capability, METH_VARARGS, NULL },
1596
1760
        { "check_path", ra_check_path, METH_VARARGS, NULL },
1597
1761
        { "get_lock", ra_get_lock, METH_VARARGS, NULL },
2160
2324
                                                  cert_info->issuer_dname, cert_info->ascii_cert);
2161
2325
        }
2162
2326
 
 
2327
        if (py_cert == NULL)
 
2328
                return py_svn_error();
 
2329
 
2163
2330
        ret = PyObject_CallFunction(fn, "slOb", realm, failures, py_cert, may_save);
2164
2331
        Py_DECREF(py_cert);
2165
2332
        if (ret == NULL)
2450
2617
        PyModule_AddIntConstant(mod, "DIRENT_LAST_AUTHOR", SVN_DIRENT_LAST_AUTHOR);
2451
2618
        PyModule_AddIntConstant(mod, "DIRENT_ALL", SVN_DIRENT_ALL);
2452
2619
 
 
2620
#if SVN_VER_MAJOR >= 1 && SVN_VER_MINOR >= 5
 
2621
        PyModule_AddIntConstant(mod, "MERGEINFO_EXPLICIT", svn_mergeinfo_explicit);
 
2622
        PyModule_AddIntConstant(mod, "MERGEINFO_INHERITED", svn_mergeinfo_inherited);
 
2623
        PyModule_AddIntConstant(mod, "MERGEINFO_NEAREST_ANCESTOR", svn_mergeinfo_nearest_ancestor);
 
2624
#endif
 
2625
 
2453
2626
#ifdef SVN_VER_REVISION
2454
2627
        PyModule_AddIntConstant(mod, "SVN_REVISION", SVN_VER_REVISION);
2455
2628
#endif