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
1=== modified file 'subvertpy/client.c'
2--- subvertpy/client.c 2012-03-12 17:27:31 +0000
3+++ subvertpy/client.c 2012-03-28 15:08:18 +0000
4@@ -1280,7 +1280,6 @@
5 apr_array_header_t *c_diffopts;
6 PyObject *outfile, *errfile;
7 apr_file_t *c_outfile, *c_errfile;
8- apr_off_t offset;
9
10 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "OO|zzzOsbbb:diff", kwnames,
11 &rev1, &rev2, &path1, &path2,
12@@ -1349,12 +1348,6 @@
13 ignore_content_type, encoding,
14 c_outfile, c_errfile, NULL,
15 client->client, temp_pool));
16-
17- offset = 0;
18- apr_file_seek(c_outfile, APR_SET, &offset);
19- offset = 0;
20- apr_file_seek(c_errfile, APR_SET, &offset);
21-
22 apr_pool_destroy(temp_pool);
23
24 return Py_BuildValue("(NN)", outfile, errfile);
25
26=== modified file 'subvertpy/tests/test_client.py'
27--- subvertpy/tests/test_client.py 2012-03-04 20:32:19 +0000
28+++ subvertpy/tests/test_client.py 2012-03-28 15:08:18 +0000
29@@ -140,8 +140,6 @@
30 return # Skip test
31
32 (outf, errf) = self.client.diff(1, 2, self.repos_url, self.repos_url)
33- outf.seek(0)
34- errf.seek(0)
35 self.assertEquals("""Index: foo
36 ===================================================================
37 --- foo\t(revision 1)
38@@ -151,8 +149,10 @@
39 \\ No newline at end of file
40 +foo2
41 \\ No newline at end of file
42-""", outf.read())
43+""".splitlines(), outf.read().splitlines())
44 self.assertEquals("", errf.read())
45+ outf.close()
46+ errf.close()
47
48 def assertCatEquals(self, value, revision=None):
49 io = StringIO()
50
51=== modified file 'subvertpy/util.c'
52--- subvertpy/util.c 2012-02-24 06:42:47 +0000
53+++ subvertpy/util.c 2012-03-28 15:08:18 +0000
54@@ -178,14 +178,14 @@
55
56 PyObject *PyOS_tmpfile(void)
57 {
58- PyObject *osmodule, *tmpfile_fn, *ret;
59+ PyObject *tempfile, *tmpfile_fn, *ret;
60
61- osmodule = PyImport_ImportModule("os");
62- if (osmodule == NULL)
63+ tempfile = PyImport_ImportModule("tempfile");
64+ if (tempfile == NULL)
65 return NULL;
66
67- tmpfile_fn = PyObject_GetAttrString(osmodule, "tmpfile");
68- Py_DECREF(osmodule);
69+ tmpfile_fn = PyObject_GetAttrString(tempfile, "NamedTemporaryFile");
70+ Py_DECREF(tempfile);
71
72 if (tmpfile_fn == NULL)
73 return NULL;
74@@ -717,26 +717,20 @@
75
76 apr_file_t *apr_file_from_object(PyObject *object, apr_pool_t *pool)
77 {
78- apr_status_t status;
79- FILE *file;
80- apr_file_t *fp;
81- apr_os_file_t osfile;
82-
83- file = PyFile_AsFile(object);
84-#ifdef WIN32
85- osfile = (apr_os_file_t)_get_osfhandle(_fileno(file));
86-#else
87- osfile = (apr_os_file_t)fileno(file);
88-#endif
89-
90- status = apr_os_file_put(&fp, &osfile,
91- APR_FOPEN_WRITE | APR_FOPEN_CREATE, pool);
92- if (status) {
93- PyErr_SetAprStatus(status);
94- return NULL;
95- }
96-
97- return fp;
98+ PyObject *filenameObject;
99+ char *filename;
100+ apr_file_t *fp;
101+ apr_status_t status;
102+ filenameObject = PyObject_GetAttrString(object, "name");
103+ filename = PyString_AsString(filenameObject);
104+ status = apr_file_open(&fp, filename, APR_WRITE | APR_CREATE,
105+ APR_REG,pool);
106+ if (status) {
107+ PyErr_SetAprStatus(status);
108+ return NULL;
109+ }
110+
111+ return fp;
112 }
113
114 static void stream_dealloc(PyObject *self)

Subscribers

People subscribed via source and target branches

to all changes: