Merge lp:~luoyonggang/subvertpy/python2 into lp:~jelmer/subvertpy/trunk

Proposed by Yonggang Luo
Status: Superseded
Proposed branch: lp:~luoyonggang/subvertpy/python2
Merge into: lp:~jelmer/subvertpy/trunk
Diff against target: 114 lines (+22/-35)
3 files modified
subvertpy/client.c (+0/-7)
subvertpy/tests/test_client.py (+3/-3)
subvertpy/util.c (+19/-25)
To merge this branch: bzr merge lp:~luoyonggang/subvertpy/python2
Reviewer Review Type Date Requested Status
Jelmer Vernooij Needs Fixing
Review via email: mp+99708@code.launchpad.net

Description of the change

Get client diff works under Windows.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Moving away from os.tmpfile() to NamedTemporaryFile (or something similar) seems reasonable to me, especially given os.tmpfile()'s status.

However:
 * We can't use b"" - subvertpy is compatible with 2.4 which AFAIK doesn't have b"".
 * Please don't mix formatting with code changes - it makes it hard to actually see what's going on.
 * There is no need to explicitly close the apr file handles - that's done when their pool is cleaned up AFAIK.
 * Please don't reopen files in apr_file_from_object(); this may not always be possible

review: Needs Fixing
Revision history for this message
Yonggang Luo (luoyonggang) wrote :

2012/3/28 Jelmer Vernooij <email address hidden>

> Review: Needs Fixing
>
> Moving away from os.tmpfile() to NamedTemporaryFile (or something similar)
> seems reasonable to me, especially given os.tmpfile()'s status.
>
> However:
> * We can't use b"" - subvertpy is compatible with 2.4 which AFAIK doesn't
> have b"".
>
For python 3

> * Please don't mix formatting with code changes - it makes it hard to
> actually see what's going on.
>
It's inconsistent mix up tab and space. And it's not so much code.

> * There is no need to explicitly close the apr file handles - that's done
> when their pool is cleaned up AFAIK.

 * Please don't reopen files in apr_file_from_object(); this may not always
> be possible
>
That's the key to get diff works under windows.
Because the file handle can not directly covert to apr_file_t.

--
> https://code.launchpad.net/~luoyonggang/subvertpy/python2/+merge/99708
> You are the owner of lp:~luoyonggang/subvertpy/python2.
>

--
         此致

罗勇刚
Yours
    sincerely,
Yonggang Luo

lp:~luoyonggang/subvertpy/python2 updated
2451. By Yonggang Luo

Python 2.4 didn't support for b prefix.
apr_pool_destroy(temp_pool) can close files.

2452. By Yonggang Luo

Use addCleanup instead directly file close.

2453. By Yonggang Luo

Becuase apr_os_file_put didn't works under win32, so use apr_file_open instead
apr_os_file_put under win32.

2454. By Yonggang Luo

comments update.

Unmerged revisions

2454. By Yonggang Luo

comments update.

2453. By Yonggang Luo

Becuase apr_os_file_put didn't works under win32, so use apr_file_open instead
apr_os_file_put under win32.

2452. By Yonggang Luo

Use addCleanup instead directly file close.

2451. By Yonggang Luo

Python 2.4 didn't support for b prefix.
apr_pool_destroy(temp_pool) can close files.

2450. By Yonggang Luo

The newlines are different under Windows to Unix-like system.
So only compare with splits.
The diff resulted files should be closed.

2449. By Yonggang Luo

os.tmpfile is deperated and not works properly under Win7. use tempfile.NamedTemporaryFile
instead, so that it works under Windows.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'subvertpy/client.c'
--- subvertpy/client.c 2012-03-12 17:27:31 +0000
+++ subvertpy/client.c 2012-03-28 15:08:18 +0000
@@ -1280,7 +1280,6 @@
1280 apr_array_header_t *c_diffopts;1280 apr_array_header_t *c_diffopts;
1281 PyObject *outfile, *errfile;1281 PyObject *outfile, *errfile;
1282 apr_file_t *c_outfile, *c_errfile;1282 apr_file_t *c_outfile, *c_errfile;
1283 apr_off_t offset;
12841283
1285 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|zzzOsbbb:diff", kwnames,1284 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|zzzOsbbb:diff", kwnames,
1286 &rev1, &rev2, &path1, &path2,1285 &rev1, &rev2, &path1, &path2,
@@ -1349,12 +1348,6 @@
1349 ignore_content_type, encoding,1348 ignore_content_type, encoding,
1350 c_outfile, c_errfile, NULL,1349 c_outfile, c_errfile, NULL,
1351 client->client, temp_pool));1350 client->client, temp_pool));
1352
1353 offset = 0;
1354 apr_file_seek(c_outfile, APR_SET, &offset);
1355 offset = 0;
1356 apr_file_seek(c_errfile, APR_SET, &offset);
1357
1358 apr_pool_destroy(temp_pool);1351 apr_pool_destroy(temp_pool);
13591352
1360 return Py_BuildValue("(NN)", outfile, errfile);1353 return Py_BuildValue("(NN)", outfile, errfile);
13611354
=== modified file 'subvertpy/tests/test_client.py'
--- subvertpy/tests/test_client.py 2012-03-04 20:32:19 +0000
+++ subvertpy/tests/test_client.py 2012-03-28 15:08:18 +0000
@@ -140,8 +140,6 @@
140 return # Skip test140 return # Skip test
141141
142 (outf, errf) = self.client.diff(1, 2, self.repos_url, self.repos_url)142 (outf, errf) = self.client.diff(1, 2, self.repos_url, self.repos_url)
143 outf.seek(0)
144 errf.seek(0)
145 self.assertEquals("""Index: foo143 self.assertEquals("""Index: foo
146===================================================================144===================================================================
147--- foo\t(revision 1)145--- foo\t(revision 1)
@@ -151,8 +149,10 @@
151\\ No newline at end of file149\\ No newline at end of file
152+foo2150+foo2
153\\ No newline at end of file151\\ No newline at end of file
154""", outf.read())152""".splitlines(), outf.read().splitlines())
155 self.assertEquals("", errf.read())153 self.assertEquals("", errf.read())
154 outf.close()
155 errf.close()
156156
157 def assertCatEquals(self, value, revision=None):157 def assertCatEquals(self, value, revision=None):
158 io = StringIO()158 io = StringIO()
159159
=== modified file 'subvertpy/util.c'
--- subvertpy/util.c 2012-02-24 06:42:47 +0000
+++ subvertpy/util.c 2012-03-28 15:08:18 +0000
@@ -178,14 +178,14 @@
178178
179PyObject *PyOS_tmpfile(void)179PyObject *PyOS_tmpfile(void)
180{180{
181 PyObject *osmodule, *tmpfile_fn, *ret;181 PyObject *tempfile, *tmpfile_fn, *ret;
182182
183 osmodule = PyImport_ImportModule("os");183 tempfile = PyImport_ImportModule("tempfile");
184 if (osmodule == NULL)184 if (tempfile == NULL)
185 return NULL;185 return NULL;
186186
187 tmpfile_fn = PyObject_GetAttrString(osmodule, "tmpfile");187 tmpfile_fn = PyObject_GetAttrString(tempfile, "NamedTemporaryFile");
188 Py_DECREF(osmodule);188 Py_DECREF(tempfile);
189189
190 if (tmpfile_fn == NULL)190 if (tmpfile_fn == NULL)
191 return NULL;191 return NULL;
@@ -717,26 +717,20 @@
717717
718apr_file_t *apr_file_from_object(PyObject *object, apr_pool_t *pool)718apr_file_t *apr_file_from_object(PyObject *object, apr_pool_t *pool)
719{719{
720 apr_status_t status;720 PyObject *filenameObject;
721 FILE *file;721 char *filename;
722 apr_file_t *fp;722 apr_file_t *fp;
723 apr_os_file_t osfile;723 apr_status_t status;
724 724 filenameObject = PyObject_GetAttrString(object, "name");
725 file = PyFile_AsFile(object);725 filename = PyString_AsString(filenameObject);
726#ifdef WIN32726 status = apr_file_open(&fp, filename, APR_WRITE | APR_CREATE,
727 osfile = (apr_os_file_t)_get_osfhandle(_fileno(file));727 APR_REG,pool);
728#else728 if (status) {
729 osfile = (apr_os_file_t)fileno(file);729 PyErr_SetAprStatus(status);
730#endif730 return NULL;
731731 }
732 status = apr_os_file_put(&fp, &osfile,732
733 APR_FOPEN_WRITE | APR_FOPEN_CREATE, pool);733 return fp;
734 if (status) {
735 PyErr_SetAprStatus(status);
736 return NULL;
737 }
738
739 return fp;
740}734}
741735
742static void stream_dealloc(PyObject *self)736static void stream_dealloc(PyObject *self)

Subscribers

People subscribed via source and target branches

to all changes: