| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | begin_test "progress log: file counts" |
| 6 | ( |
| 7 | set -e |
| 8 | |
| 9 | reponame="progress-log-file-counts" |
| 10 | setup_remote_repo "$reponame" |
| 11 | clone_repo "$reponame" "$reponame" |
| 12 | |
| 13 | git lfs track "*.dat" |
| 14 | |
| 15 | echo "a" > a.dat |
| 16 | echo "b" > b.dat |
| 17 | echo "c" > c.dat |
| 18 | echo "d" > d.dat |
| 19 | echo "e" > e.dat |
| 20 | |
| 21 | progress_log_dir="$TRASHDIR/${reponame}-logs" |
| 22 | |
| 23 | progress_log="$progress_log_dir/progress-clean.log" |
| 24 | GIT_LFS_PROGRESS="$progress_log" git add .gitattributes *.dat |
| 25 | cat "$progress_log" |
| 26 | |
| 27 | [ 5 -eq "$(grep -c "clean 1/1" "$progress_log")" ] |
| 28 | |
| 29 | git commit -m "add files" |
| 30 | |
| 31 | progress_log="$progress_log_dir/progress-push.log" |
| 32 | GIT_LFS_PROGRESS="$progress_log" git push origin main 2>&1 | tee push.log |
| 33 | [ 0 -eq "${PIPESTATUS[0]}" ] |
| 34 | cat "$progress_log" |
| 35 | |
| 36 | grep "Uploading LFS objects: 100% (5/5), 10 B" push.log |
| 37 | |
| 38 | grep "upload 1/5" "$progress_log" |
| 39 | grep "upload 2/5" "$progress_log" |
| 40 | grep "upload 3/5" "$progress_log" |
| 41 | grep "upload 4/5" "$progress_log" |
| 42 | grep "upload 5/5" "$progress_log" |
| 43 | |
| 44 | cd .. |
| 45 | |
| 46 | progress_log="$progress_log_dir/progress-clone.log" |
| 47 | GIT_LFS_PROGRESS="$progress_log" git lfs clone "$GITSERVER/$reponame" "${reponame}-assert" |
| 48 | cat "$progress_log" |
| 49 | |
| 50 | grep "download 1/5" "$progress_log" |
| 51 | grep "download 2/5" "$progress_log" |
| 52 | grep "download 3/5" "$progress_log" |
| 53 | grep "download 4/5" "$progress_log" |
| 54 | grep "download 5/5" "$progress_log" |
| 55 | |
| 56 | rm -rf "${reponame}-assert" |
| 57 | |
| 58 | GIT_LFS_SKIP_SMUDGE=1 git clone "$GITSERVER/$reponame" "${reponame}-assert" |
| 59 | cd "${reponame}-assert" |
| 60 | |
| 61 | rm -rf .git/lfs/objects |
| 62 | |
| 63 | progress_log="$progress_log_dir/progress-fetch.log" |
| 64 | GIT_LFS_PROGRESS="$progress_log" git lfs fetch --all |
| 65 | cat "$progress_log" |
| 66 | |
| 67 | grep "download 1/5" "$progress_log" |
| 68 | grep "download 2/5" "$progress_log" |
| 69 | grep "download 3/5" "$progress_log" |
| 70 | grep "download 4/5" "$progress_log" |
| 71 | grep "download 5/5" "$progress_log" |
| 72 | |
| 73 | progress_log="$progress_log_dir/progress-checkout.log" |
| 74 | GIT_LFS_PROGRESS="$progress_log" git lfs checkout |
| 75 | cat "$progress_log" |
| 76 | |
| 77 | grep "checkout 1/5" "$progress_log" |
| 78 | grep "checkout 2/5" "$progress_log" |
| 79 | grep "checkout 3/5" "$progress_log" |
| 80 | grep "checkout 4/5" "$progress_log" |
| 81 | grep "checkout 5/5" "$progress_log" |
| 82 | ) |
| 83 | end_test |
| 84 | |
| 85 | begin_test "progress log: unknown initial size (clean)" |
| 86 | ( |
| 87 | set -e |
| 88 | |
| 89 | reponame="progress-log-unknown-total-clean" |
| 90 | setup_remote_repo "$reponame" |
| 91 | clone_repo "$reponame" "$reponame" |
| 92 | |
| 93 | git lfs track "*.dat" |
| 94 | git add .gitattributes |
| 95 | git commit -m "initial commit" |
| 96 | |
| 97 | # Test with a file size larger than the size of the read buffer used when |
| 98 | # decoding pointers. See the secondary issue reported in |
| 99 | # https://github.com/git-lfs/git-lfs/issues/4974#issuecomment-2717907543 |
| 100 | # and https://github.com/git-lfs/git-lfs/pull/6011. |
| 101 | max_pointer_size="$(lfstest-getlimit --max-pointer-size)" |
| 102 | contents_size=$((max_pointer_size * 2)) |
| 103 | head -c "$contents_size" /dev/zero >large.dat |
| 104 | |
| 105 | progress_log="$TRASHDIR/${reponame}-logs/progress.log" |
| 106 | GIT_LFS_PROGRESS="$progress_log" git add large.dat |
| 107 | cat "$progress_log" |
| 108 | |
| 109 | # Confirm that the callback created by the CopyCallbackFile() method |
| 110 | # of lfs.GitFilter reports the final object size in the progress log. |
| 111 | # |
| 112 | # Note that we will probably not see a preceding entry with a "????"-style |
| 113 | # field indicating an unknown total size, even though a callback will |
| 114 | # likely be made after the read buffer used to decode pointers is copied |
| 115 | # and before the remainder of the data is copied. Specifically, when |
| 116 | # io.Copy() reads from io.MultiReader() and reaches the end of the initial |
| 117 | # pointer detection buffer, a callback is likely to be made. However, |
| 118 | # the callback will not write an entry because insufficient time will |
| 119 | # have elapsed, as it only writes if its throttling deadline has passed |
| 120 | # or if the byte count has just reached the expected total. |
| 121 | grep "clean 1/1 $contents_size/$contents_size large.dat" "$progress_log" |
| 122 | ) |
| 123 | end_test |
| 124 | |
| 125 | begin_test "progress log: unknown initial size (smudge)" |
| 126 | ( |
| 127 | set -e |
| 128 | |
| 129 | reponame="progress-log-unknown-total-smudge" |
| 130 | setup_remote_repo "$reponame" |
| 131 | clone_repo "$reponame" "$reponame" |
| 132 | |
| 133 | git lfs track "*.dat" |
| 134 | |
| 135 | # This content announces to the server that it should expect an |
| 136 | # "Accept-Encoding: gzip" header and send a gzip-compressed response. |
| 137 | contents="storage-download-encoding-gzip" |
| 138 | printf "%s" "$contents" >a.dat |
| 139 | |
| 140 | git add .gitattributes a.dat |
| 141 | git commit -m "add a.dat" |
| 142 | |
| 143 | git push origin main |
| 144 | |
| 145 | # We force the use of "git lfs smudge" rather than "git lfs filter-process" |
| 146 | # because the latter downloads object files asynchronously and writes them |
| 147 | # to local storage, and then only invokes the progress logging callback |
| 148 | # when spooling those files back to Git in response to its second phase |
| 149 | # of "smudge" filter commands where it does not specify the "can-delay" |
| 150 | # flag. As a result, the total size of each file is known during these |
| 151 | # callbacks. |
| 152 | # |
| 153 | # By contrast, when using "git lfs smudge" the progress logging callback |
| 154 | # is called as object file data is downloaded by the transfer adapter, |
| 155 | # and the lack of a Content-Length header means the total size is |
| 156 | # unknown until EOF is reached. |
| 157 | git config --global --unset filter.lfs.process |
| 158 | |
| 159 | cd .. |
| 160 | progress_log="$TRASHDIR/${reponame}-logs/progress.log" |
| 161 | GIT_LFS_PROGRESS="$progress_log" GIT_TRACE=1 \ |
| 162 | git clone "$GITSERVER/$reponame" "${reponame}-assert" 2>&1 | tee clone.log |
| 163 | [ 0 -eq "${PIPESTATUS[0]}" ] |
| 164 | cat "$progress_log" |
| 165 | |
| 166 | # Confirm we saw a gzip-encoded response, which should not include a |
| 167 | # Content-Length header, so the size of the download will be initially |
| 168 | # unknown. For a more comprehensive test of gzip-encoding, see the |
| 169 | # t/t-batch-storage-encoding.sh script. |
| 170 | grep -c "decompressed gzipped response" clone.log |
| 171 | |
| 172 | # Confirm that the callback created by the CopyCallbackFile() method |
| 173 | # of lfs.GitFilter reports the final object size in the progress log. |
| 174 | # |
| 175 | # Note that we will probably not see a preceding entry with a "????"-style |
| 176 | # field indicating an unknown total size because an EOF is usually provided |
| 177 | # at the same time the final bytes are read from the HTTP download stream. |
| 178 | # Once EOF is reached, the Read() method of tools.CallbackReader should pass |
| 179 | # the final byte count to the callback as the total size, so the callback |
| 180 | # will likely never be invoked with a negative (i.e., unknown) total size. |
| 181 | grep "download 1/1 ${#contents}/${#contents} a.dat" "$progress_log" |
| 182 | ) |
| 183 | end_test |
| 184 | |
| 185 | begin_test "progress log: unknown initial size (fetch/pull)" |
| 186 | ( |
| 187 | set -e |
| 188 | |
| 189 | reponame="progress-log-unknown-total-pull" |
| 190 | setup_remote_repo "$reponame" |
| 191 | clone_repo "$reponame" "$reponame" |
| 192 | |
| 193 | git lfs track "*.dat" |
| 194 | |
| 195 | # This content announces to the server that it should expect an |
| 196 | # "Accept-Encoding: gzip" header and send a gzip-compressed response. |
| 197 | contents="storage-download-encoding-gzip" |
| 198 | printf "%s" "$contents" >a.dat |
| 199 | |
| 200 | git add .gitattributes a.dat |
| 201 | git commit -m "add a.dat" |
| 202 | |
| 203 | git push origin main |
| 204 | |
| 205 | progress_log_dir="$TRASHDIR/${reponame}-logs" |
| 206 | |
| 207 | rm -rf .git/lfs/objects a.dat |
| 208 | |
| 209 | progress_log="$progress_log_dir/progress-fetch.log" |
| 210 | GIT_LFS_PROGRESS="$progress_log" GIT_TRACE=1 git lfs fetch 2>&1 | tee fetch.log |
| 211 | [ 0 -eq "${PIPESTATUS[0]}" ] |
| 212 | cat "$progress_log" |
| 213 | |
| 214 | # Confirm we saw a gzip-encoded response, which should not include a |
| 215 | # Content-Length header, so the size of the download will be initially |
| 216 | # unknown. For a more comprehensive test of gzip-encoding, see the |
| 217 | # t/t-batch-storage-encoding.sh script. |
| 218 | grep -c "decompressed gzipped response" fetch.log |
| 219 | |
| 220 | # Confirm that the callback created by the ensureAdapterBegun() method |
| 221 | # of tq.TransferQueue reports the final object size in the progress log. |
| 222 | # |
| 223 | # Note that we will probably not see a preceding entry with a "????"-style |
| 224 | # field indicating an unknown total size because an EOF is usually provided |
| 225 | # at the same time the final bytes are read from the HTTP download stream. |
| 226 | # Once EOF is reached, the Read() method of tools.CallbackReader should pass |
| 227 | # the final byte count to the callback as the total size, so the callback |
| 228 | # will likely never be invoked with a negative (i.e., unknown) total size. |
| 229 | grep "download 1/1 ${#contents}/${#contents} a.dat" "$progress_log" |
| 230 | |
| 231 | rm -rf .git/lfs/objects |
| 232 | |
| 233 | progress_log="$progress_log_dir/progress-pull.log" |
| 234 | GIT_LFS_PROGRESS="$progress_log" GIT_TRACE=1 git lfs pull 2>&1 | tee pull.log |
| 235 | [ 0 -eq "${PIPESTATUS[0]}" ] |
| 236 | cat "$progress_log" |
| 237 | |
| 238 | # Confirm we saw a gzip-encoded response, which should not include a |
| 239 | # Content-Length header, so the size of the download will be initially |
| 240 | # unknown. |
| 241 | grep -c "decompressed gzipped response" pull.log |
| 242 | |
| 243 | # Confirm that the callback created by the ensureAdapterBegun() method |
| 244 | # of tq.TransferQueue reports the final object size in the progress log. |
| 245 | # |
| 246 | # Note that we will probably not see a preceding entry with a "????"-style |
| 247 | # field indicating an unknown total size because an EOF is usually provided |
| 248 | # at the same time the final bytes are read from the HTTP download stream. |
| 249 | # Once EOF is reached, the Read() method of tools.CallbackReader should pass |
| 250 | # the final byte count to the callback as the total size, so the callback |
| 251 | # will likely never be invoked with a negative (i.e., unknown) total size. |
| 252 | grep "download 1/1 ${#contents}/${#contents} a.dat" "$progress_log" |
| 253 | ) |
| 254 | end_test |