From d813ba08564cd34e1175189bf02433c0c53b422f Mon Sep 17 00:00:00 2001
From: Even Rouault <even.rouault@spatialys.com>
Date: Wed, 22 Nov 2023 02:17:55 +0100
Subject: [PATCH] gdalwarp: progress bar tunings

- make sure that progress for each source file goes to 100%
- display first progress bar after message about copying nodata values
---
 apps/gdalwarp_bin.cpp | 2 ++
 apps/gdalwarp_lib.cpp | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/apps/gdalwarp_bin.cpp b/apps/gdalwarp_bin.cpp
index f3a51f64f333..6ea6411f1fb7 100644
--- a/apps/gdalwarp_bin.cpp
+++ b/apps/gdalwarp_bin.cpp
@@ -149,6 +149,8 @@ static int CPL_STDCALL WarpTermProgress(double dfProgress,
     }
     else if (pszMessage != osLastMsg)
     {
+        if (!osLastMsg.empty())
+            GDALTermProgress(1.0, nullptr, nullptr);
         printf("%s : ", pszMessage);
         osLastMsg = pszMessage;
         iSrc++;
diff --git a/apps/gdalwarp_lib.cpp b/apps/gdalwarp_lib.cpp
index ae3d59bce4b0..6171679a241b 100644
--- a/apps/gdalwarp_lib.cpp
+++ b/apps/gdalwarp_lib.cpp
@@ -2582,7 +2582,6 @@ static GDALDatasetH GDALWarpDirect(const char *pszDest, GDALDatasetH hDstDS,
          */
         hSrcDS = pahSrcDS[iSrc];
         oProgress.iSrc = iSrc;
-        oProgress.Do(0);
 
         /* --------------------------------------------------------------------
          */
@@ -3028,6 +3027,8 @@ static GDALDatasetH GDALWarpDirect(const char *pszDest, GDALDatasetH hDstDS,
         SetupNoData(pszDest, iSrc, hSrcDS, hWrkSrcDS, hDstDS, psWO, psOptions,
                     bEnableDstAlpha, bInitDestSetByUser);
 
+        oProgress.Do(0);
+
         /* --------------------------------------------------------------------
          */
         /*      For the first source image of a newly created dataset, decide */