Remove redundant buffer_fdinit calls
Re: [PATCH svn-fe 5/7] Fix vcs-svn/fast_export reinit bugs
In reply to a message not in the archiveHi,
Quoted 2 lines · Dmitry Ivankov
first_commit_donewas not set in_init, but it
is needed iffast_export_is used/_init-ed twice.
Thanks, good catch. I wonder if it's possible to detect this kind of thing automatically --- maybe it would make sense for test-svn-fe to learn to apply two dumps in sequence so this code could be exercised.
Quoted 1 line
Same thing for the
branch_name.
This one should be squashed with the previous patch for easier review imho. New readers never have to know the details of early mistakes.
Quoted 20 lines
Signed-off-by Dmitry Ivankov <[email protected]>--- vcs-svn/fast_export.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)vcs-svn/fast_export.c +2
-0@@ -32,6 +32,8 @@ static int init_postimage(void)void fast_export_init (int fd,const char * branch) { + first_commit_done =0 ; +strbuf_reset (&branch_name);strbuf_addstr (&branch_name, branch);if (buffer_fdinit (&report_buffer, fd))die_errno ("cannot read from file descriptor %d" , fd);
vcs-svn/fast_export.c void fast_export_deinit(void) · line 50
Quoted 4 lines
vcs-svn/fast_export.c +1
-0@@ -45,7 +47,9 @@ void fast_export_deinit(void)void fast_export_reset (void ) { + first_commit_done =0 ;
I don't think this is needed --- fast_export_reset is called when we are about to exit. Maybe the vcs-svn::*_reset functions should be renamed to foo_free or something similar to avoid confusion (especially when comparing to strbuf_reset).
Quoted 8 lines
vcs-svn/fast_export.c +1
-0buffer_reset (&report_buffer); +strbuf_reset (&branch_name); }void fast_export_delete (const char *path)Signature · 1 line
1.7.3.4
Jonathan Nieder
Reviewed-byHi,
Quoted 6 lines · Dmitry Ivankov
First of all
fast_export_initcalledbuffer_fdinitdirectly, andinit_reportbuffer did fdopen once more - it is a FILE* leak. The second problem is thatfast_export_initused fd passed whileapply_deltaused hardcodedREPORT_FILENO.Signed-off-by Dmitry Ivankov <[email protected]>
Good eyes. As the patch "vcs-svn: implement text-delta handling" bounced forward to a newer codebase it seems we let report_buffer be initialized twice. :/
About the log message: it would be easier to read text that is (at least mostly) wrapped to a consistent width.
Okay, okay, more substantive comments. The ideal log message will explain what the program currently does, why that's bad, and how the patch will improve it. In this example, that could mean something vaguely like:
When importing from a dump with deltas, svn-fe's fast-export module calls buffer_fdinit to initialize report_buffer twice: once in fast_export_init and once in init_report_buffer when processing the first delta. The second initialization is redundant and leaks a FILE *.
Fix it by relying on fast_export_init to initialize report_buffer. On one hand explicitly initializing like this is simpler than the on-demand initialization implemented by init_report_buffer, and on the other hand fast_export_init takes an fd as a parameter rather than hard-coding the requirement to read from fd 3.
Except as noted above:
By the way, I think it would make sense to initialize "postimage" in fast_export_init (and deinitialize it in fast_export_deinit), too, for a similar reason (simplification).
Thanks. Patch left unsnipped in case others have thoughts.
Quoted 46 lines
---
I've added two more patches on top, they are less baked and so lack s-o-b.vcs-svn/fast_export.c | 12 ------------ 1 files changed, 0 insertions(+), 12 deletions(-)vcs-svn/fast_export.c +0
-12@@ -14,7 +14,6 @@#include "line_buffer.h" #define MAX_GITSVN_LINE_LEN 4096 -#define REPORT_FILENO 3static uint32_t first_commit_done;static struct line_buffer postimage =LINE_BUFFER_INIT ;@@ -30,15 +29,6 @@ static int init_postimage(void)return buffer_tmpfile_init (&postimage); } -static int init_report_buffer (int fd) -{ -static int report_buffer_initialized; -if (report_buffer_initialized) -return 0 ; - report_buffer_initialized =1 ; -return buffer_fdinit (&report_buffer, fd); -} -void fast_export_init (int fd) {if (buffer_fdinit (&report_buffer, fd))@@ -203,8 +193,6 @@ static long apply_delta(off_t len, struct line_buffer *input,if (init_postimage () || !(out =buffer_tmpfile_rewind (&postimage)))die ("cannot open temporary file for blob retrieval" ); -if (init_report_buffer (REPORT_FILENO )) -die ("cannot open fd 3 for feedback from fast-import" );if (old_data) {const char *response;printf ("cat-blob %s\n" , old_data);Signature · 1 line
1.7.3.4