@@ -192,115 +192,119 @@ M.parse = function(bufnr)
192
192
seen_names [name ] = true
193
193
end
194
194
end
195
- for i , line in ipairs (lines ) do
196
- if line :match (" ^/%d+" ) then
197
- -- Parse the line for an existing entry
198
- local result , err = M .parse_line (adapter , line , column_defs )
199
- if not result or err then
200
- table.insert (errors , {
201
- message = err ,
202
- lnum = i - 1 ,
203
- end_lnum = i ,
204
- col = 0 ,
205
- })
206
- goto continue
207
- elseif result .data .id == 0 then
208
- -- Ignore entries with ID 0 (typically the "../" entry)
209
- goto continue
210
- end
211
- local parsed_entry = result .data
212
- local entry = result .entry
213
195
214
- local err_message
215
- if not parsed_entry .name then
216
- err_message = " No filename found"
217
- elseif not entry then
218
- err_message = " Could not find existing entry (was the ID changed?)"
219
- elseif parsed_entry .name :match (" /" ) or parsed_entry .name :match (fs .sep ) then
220
- err_message = " Filename cannot contain path separator"
221
- end
222
- if err_message then
223
- table.insert (errors , {
224
- message = err_message ,
225
- lnum = i - 1 ,
226
- end_lnum = i ,
227
- col = 0 ,
228
- })
229
- goto continue
230
- end
231
- assert (entry )
196
+ for i , line in ipairs (lines ) do
197
+ -- hack to be compatible with Lua 5.1
198
+ -- use return instead of goto
199
+ (function ()
200
+ if line :match (" ^/%d+" ) then
201
+ -- Parse the line for an existing entry
202
+ local result , err = M .parse_line (adapter , line , column_defs )
203
+ if not result or err then
204
+ table.insert (errors , {
205
+ message = err ,
206
+ lnum = i - 1 ,
207
+ end_lnum = i ,
208
+ col = 0 ,
209
+ })
210
+ return
211
+ elseif result .data .id == 0 then
212
+ -- Ignore entries with ID 0 (typically the "../" entry)
213
+ return
214
+ end
215
+ local parsed_entry = result .data
216
+ local entry = result .entry
232
217
233
- check_dupe (parsed_entry .name , i )
234
- local meta = entry [FIELD_META ]
235
- if original_entries [parsed_entry .name ] == parsed_entry .id then
236
- if entry [FIELD_TYPE ] == " link" and not compare_link_target (meta , parsed_entry ) then
237
- table.insert (diffs , {
238
- type = " new" ,
239
- name = parsed_entry .name ,
240
- entry_type = " link" ,
241
- link = parsed_entry .link_target ,
218
+ local err_message
219
+ if not parsed_entry .name then
220
+ err_message = " No filename found"
221
+ elseif not entry then
222
+ err_message = " Could not find existing entry (was the ID changed?)"
223
+ elseif parsed_entry .name :match (" /" ) or parsed_entry .name :match (fs .sep ) then
224
+ err_message = " Filename cannot contain path separator"
225
+ end
226
+ if err_message then
227
+ table.insert (errors , {
228
+ message = err_message ,
229
+ lnum = i - 1 ,
230
+ end_lnum = i ,
231
+ col = 0 ,
242
232
})
243
- elseif entry [FIELD_TYPE ] ~= parsed_entry ._type then
233
+ return
234
+ end
235
+ assert (entry )
236
+
237
+ check_dupe (parsed_entry .name , i )
238
+ local meta = entry [FIELD_META ]
239
+ if original_entries [parsed_entry .name ] == parsed_entry .id then
240
+ if entry [FIELD_TYPE ] == " link" and not compare_link_target (meta , parsed_entry ) then
241
+ table.insert (diffs , {
242
+ type = " new" ,
243
+ name = parsed_entry .name ,
244
+ entry_type = " link" ,
245
+ link = parsed_entry .link_target ,
246
+ })
247
+ elseif entry [FIELD_TYPE ] ~= parsed_entry ._type then
248
+ table.insert (diffs , {
249
+ type = " new" ,
250
+ name = parsed_entry .name ,
251
+ entry_type = parsed_entry ._type ,
252
+ })
253
+ else
254
+ original_entries [parsed_entry .name ] = nil
255
+ end
256
+ else
244
257
table.insert (diffs , {
245
258
type = " new" ,
246
259
name = parsed_entry .name ,
247
260
entry_type = parsed_entry ._type ,
261
+ id = parsed_entry .id ,
262
+ link = parsed_entry .link_target ,
248
263
})
249
- else
250
- original_entries [parsed_entry .name ] = nil
251
264
end
252
- else
253
- table.insert (diffs , {
254
- type = " new" ,
255
- name = parsed_entry .name ,
256
- entry_type = parsed_entry ._type ,
257
- id = parsed_entry .id ,
258
- link = parsed_entry .link_target ,
259
- })
260
- end
261
265
262
- for _ , col_def in ipairs (column_defs ) do
263
- local col_name = util .split_config (col_def )
264
- if columns .compare (adapter , col_name , entry , parsed_entry [col_name ]) then
265
- table.insert (diffs , {
266
- type = " change" ,
267
- name = parsed_entry .name ,
268
- entry_type = entry [FIELD_TYPE ],
269
- column = col_name ,
270
- value = parsed_entry [col_name ],
266
+ for _ , col_def in ipairs (column_defs ) do
267
+ local col_name = util .split_config (col_def )
268
+ if columns .compare (adapter , col_name , entry , parsed_entry [col_name ]) then
269
+ table.insert (diffs , {
270
+ type = " change" ,
271
+ name = parsed_entry .name ,
272
+ entry_type = entry [FIELD_TYPE ],
273
+ column = col_name ,
274
+ value = parsed_entry [col_name ],
275
+ })
276
+ end
277
+ end
278
+ else
279
+ -- Parse a new entry
280
+ local name , isdir = parsedir (vim .trim (line ))
281
+ if vim .startswith (name , " /" ) then
282
+ table.insert (errors , {
283
+ message = " Paths cannot start with '/'" ,
284
+ lnum = i - 1 ,
285
+ end_lnum = i ,
286
+ col = 0 ,
271
287
})
288
+ return
272
289
end
273
- end
274
- else
275
- -- Parse a new entry
276
- local name , isdir = parsedir (vim .trim (line ))
277
- if vim .startswith (name , " /" ) then
278
- table.insert (errors , {
279
- message = " Paths cannot start with '/'" ,
280
- lnum = i - 1 ,
281
- end_lnum = i ,
282
- col = 0 ,
283
- })
284
- goto continue
285
- end
286
- if name ~= " " then
287
- local link_pieces = vim .split (name , " -> " , { plain = true })
288
- local entry_type = isdir and " directory" or " file"
289
- local link
290
- if # link_pieces == 2 then
291
- entry_type = " link"
292
- name , link = unpack (link_pieces )
290
+ if name ~= " " then
291
+ local link_pieces = vim .split (name , " -> " , { plain = true })
292
+ local entry_type = isdir and " directory" or " file"
293
+ local link
294
+ if # link_pieces == 2 then
295
+ entry_type = " link"
296
+ name , link = unpack (link_pieces )
297
+ end
298
+ check_dupe (name , i )
299
+ table.insert (diffs , {
300
+ type = " new" ,
301
+ name = name ,
302
+ entry_type = entry_type ,
303
+ link = link ,
304
+ })
293
305
end
294
- check_dupe (name , i )
295
- table.insert (diffs , {
296
- type = " new" ,
297
- name = name ,
298
- entry_type = entry_type ,
299
- link = link ,
300
- })
301
306
end
302
- end
303
- :: continue::
307
+ end )()
304
308
end
305
309
306
310
for name , child_id in pairs (original_entries ) do
0 commit comments