Repository: iterative/dvc

Issue:
3.x cache: `data status` reports unmodified 2.x data as changed
              Is this expected to change?
```bash
#! /bin/bash

set -x

# pipx install --suffix 2.58 dvc==2.58.2
pushd "$(mktemp -d)"

git init && dvc init
echo -ne "foo\r\n" > foo
dvc2.58 add foo

git add -A

dvc2.58 data status
dvc data status
```


```console
+ dvc2.58 data status
No changes in an empty git repo.
(there are changes not tracked by dvc, use "git status" to see)
+ dvc data status
DVC uncommitted changes:
  (use "dvc commit <file>..." to track changes)
  (use "dvc checkout <file>..." to discard changes)
        modified: foo
(there are other changes not tracked by dvc, use "git status" to see)
```

```python
Change(
    typ='modify',
    old=DataIndexEntry(
        key=('foo',),
        meta=Meta(
            isdir=False,
            size=5,
            nfiles=None,
            isexec=False,
            version_id=None,
            etag=None,
            checksum=None,
            md5='d3b07384d113edec49eaa6238ad5ff00',
            inode=None,
            mtime=None,
            remote=None
        ),
        hash_info=HashInfo(name='md5', value='d3b07384d113edec49eaa6238ad5ff00', obj_name=None),
        loaded=None
    ),
    new=DataIndexEntry(
        key=('foo',),
        meta=Meta(
            isdir=False,
            size=5,
            nfiles=None,
            isexec=False,
            version_id=None,
            etag=None,
            checksum=None,
            md5=None,
            inode=2547,
            mtime=1686459999.367395,
            remote=None
        ),
        hash_info=HashInfo(name='md5', value='2145971cf82058b108229a3a2e3bff35', obj_name=None),
        loaded=None
    )
)
```

For reference,
```console
$ dvc-data hash -n md5 foo
md5: 2145971cf82058b108229a3a2e3bff35
$ dvc-data hash -n md5-dos2unix foo 
md5-dos2unix: d3b07384d113edec49eaa6238ad5ff00
```

_Originally posted by @skshetry in https://github.com/iterative/dvc/issues/9538#issuecomment-1586021037_
            


Discussion:

Resolving patch:
diff --git a/dvc/repo/index.py b/dvc/repo/index.py
--- a/dvc/repo/index.py
+++ b/dvc/repo/index.py
@@ -656,12 +656,14 @@ def build_data_index(  # noqa: C901
         if not fs.exists(out_path):
             continue
 
+        hash_name = _get_entry_hash_name(index, workspace, key)
         try:
             out_entry = build_entry(
                 out_path,
                 fs,
                 compute_hash=compute_hash,
                 state=index.repo.state,
+                hash_name=hash_name,
             )
         except FileNotFoundError:
             continue
@@ -679,6 +681,7 @@ def build_data_index(  # noqa: C901
             compute_hash=compute_hash,
             state=index.repo.state,
             ignore=ignore,
+            hash_name=hash_name,
         ):
             if not entry.key or entry.key == ("",):
                 # NOTE: whether the root will be returned by build_entries
@@ -690,7 +693,7 @@ def build_data_index(  # noqa: C901
             callback.relative_update(1)
 
         if compute_hash:
-            tree_meta, tree = build_tree(data, key)
+            tree_meta, tree = build_tree(data, key, name=hash_name)
             out_entry.meta = tree_meta
             out_entry.hash_info = tree.hash_info
             out_entry.loaded = True
@@ -706,3 +709,17 @@ def build_data_index(  # noqa: C901
         callback.relative_update(1)
 
     return data
+
+
+def _get_entry_hash_name(
+    index: Union["Index", "IndexView"], workspace: str, key: "DataIndexKey"
+) -> str:
+    from dvc_data.hashfile.hash import DEFAULT_ALGORITHM
+
+    try:
+        src_entry = index.data[workspace][key]
+        if src_entry.hash_info and src_entry.hash_info.name:
+            return src_entry.hash_info.name
+    except KeyError:
+        pass
+    return DEFAULT_ALGORITHM


Test patch: