contrib/diffall: eliminate duplicate while loops