Repository: dolthub/dolt
File: go/store/nbs/archive_writer.go (Go)

Code before:
				})
			}
		} else {
			footer := arcSrc.aRdr.footer
			chunkCounter += footer.chunkCount

			// Map byte span IDs from this reader to the combined archive
			spanIdOffset := uint32(len(aw.stagedBytes))

			for i := uint32(1); i <= footer.byteSpanCount; i++ {
				span := arcSrc.aRdr.getByteSpanByID(i)
				adjustedSpan := byteSpan{
					offset: span.offset + currentDataOffset,
					length: span.length,
				}
				aw.stagedBytes = append(aw.stagedBytes, adjustedSpan)
			}

			for i := 0; i < int(footer.chunkCount); i++ {
				dictId, dataId := arcSrc.aRdr.getChunkRef(i)

				prefix := arcSrc.aRdr.indexReader.getPrefix(uint32(i))
				suffix := arcSrc.aRdr.indexReader.getSuffix(uint32(i))
				chunkHash := reconstructHashFromPrefixAndSuffix(prefix, suffix)

				// Add to staged chunks. Note that we allow duplicates here, whereas we quietly skip
				// duplicates when doing a chunk-by-chunk build of an archive.

				// Adjust byte span IDs for the combined archive
				adjustedDictId := dictId
				if dictId != 0 {
					adjustedDictId = dictId + spanIdOffset
				}
				adjustedDataId := dataId + spanIdOffset

				aw.stagedChunks = append(aw.stagedChunks, stagedChunkRef{
					hash:       chunkHash,
					dictionary: adjustedDictId,
					data:       adjustedDataId,
				})
			}
		}
		currentDataOffset += src.dataLen
	}

	aw.bytesWritten = currentDataOffset
	// Preserve this for stat reporting as aw.bytesWritten will be updated as we write the index.
	dataBlocksLen := currentDataOffset

	// The conjoin process is a little different from the normal archive writing process. We manually stick everything
	// into the writer, and then finalize the index and footer at the end. The datablocks will be written in separately

Review comment (refactor):
```suggestion
				// Note that we allow duplicates here, whereas we quietly skip
```

Code after:
		} else {
			footer := arcSrc.aRdr.footer
			chunkCounter += footer.chunkCount

			// Map byte span IDs from this reader to the combined archive
			spanIdOffset := uint32(len(aw.stagedBytes))

			for i := uint32(1); i <= footer.byteSpanCount; i++ {
				span := arcSrc.aRdr.getByteSpanByID(i)
				adjustedSpan := byteSpan{
					length: span.length,
				}
				aw.stagedBytes = append(aw.stagedBytes, adjustedSpan)
			}

			for i := 0; i < int(footer.chunkCount); i++ {
				dictId, dataId := arcSrc.aRdr.getChunkRef(i)

				prefix := arcSrc.aRdr.indexReader.getPrefix(uint32(i))
				suffix := arcSrc.aRdr.indexReader.getSuffix(uint32(i))
				chunkHash := reconstructHashFromPrefixAndSuffix(prefix, suffix)

				// Note that we allow duplicates here, whereas we quietly skip
				// duplicates when doing a chunk-by-chunk build of an archive.

				// Adjust byte span IDs for the combined archive
				adjustedDictId := dictId
				if dictId != 0 {
					adjustedDictId = dictId + spanIdOffset
				}
				adjustedDataId := dataId + spanIdOffset

				aw.stagedChunks = append(aw.stagedChunks, stagedChunkRef{
					hash:       chunkHash,
					dictionary: adjustedDictId,
					data:       adjustedDataId,
				})
			}
		}
		aw.bytesWritten += src.dataLen
	}

	// Preserve this for stat reporting as aw.bytesWritten will be updated as we write the index.
	dataBlocksLen := aw.bytesWritten

	// The conjoin process is a little different from the normal archive writing process. We manually stick everything
	// into the writer, and then finalize the index and footer at the end. The datablocks will be written in separately
	// after we have created the index and footer.
	//
	// So we set the workflow stage to stageIndex because we skipped the byte span insertion stage.
	aw.workflowStage = stageIndex