#1031693 import-dsc: dangling pristine-tar treeish with multiple components

#1031693#5
Date:
2023-02-20 17:24:29 UTC
From:
To:
Dear Maintainer,

*** Reporter, please consider answering these questions, where appropriate ***

   * What led up to the situation?
   * What exactly did you do (or not do) that was effective (or
     ineffective)?
   * What was the outcome of this action?
   * What outcome did you expect instead?

*** End of the template - remove these template lines ***
import-dsc leaves a dangling treeish when importing a dsc with multiple components.

For example, sqlite3

```
$ dget --download-only --quiet --allow-unauthenticated http://ftp.debian.org/debian/pool/main/s/sqlite3/sqlite3_3.34.1-3.dsc
$ gbp import-dsc -v --pristine-tar sqlite3_3.34.1-3.dsc
gbp:debug: ['git', 'rev-parse', '--show-cdup']
gbp:debug: Upstream version: 3.34.1
gbp:debug: Debian version: 3
gbp:debug: Upstream tarball: /tmp/sqlite3/sqlite3_3.34.1.orig.tar.xz
gbp:debug: Additional tarballs: /tmp/sqlite3/sqlite3_3.34.1.orig-www.tar.xz
gbp:debug: Debian patch: /tmp/sqlite3/sqlite3_3.34.1-3.debian.tar.xz
gbp:info: No git repository found, creating one.
gbp:debug: ['git', 'init']
gbp:debug: ['git', 'rev-parse', '--show-cdup']
gbp:debug: ['git', 'rev-parse', '--is-bare-repository']
gbp:debug: ['git', 'rev-parse', '--git-dir']
gbp:debug: tar ['-C', '/tmp/sqlite3/tmp4mt7atb8', '-a', '-xf', '/tmp/sqlite3/sqlite3_3.34.1.orig.tar.xz'] []
gbp:info: Found component tarball 'sqlite3_3.34.1.orig-www.tar.xz'
gbp:debug: tar ['-C', '/tmp/sqlite3/tmp4mt7atb8/tmpcrfvrq1w', '-a', '-xf', '/tmp/sqlite3/sqlite3_3.34.1.orig-www.tar.xz'] []
gbp:debug: rm ['-rf', '/tmp/sqlite3/tmp4mt7atb8/tmpcrfvrq1w'] []
gbp:debug: ['git', 'tag', '-l', 'debian/3.34.1-3']
gbp:debug: ['git', 'tag', '-l', 'debian/3.34.1-3']
gbp:debug: ['git', 'tag', '-l', 'upstream/3.34.1']
gbp:debug: ['git', 'tag', '-l', 'upstream/3.34.1']
gbp:debug: ['git', 'tag', '-l', 'upstream/3.34.1']
gbp:debug: ['git', 'tag', '-l', 'upstream/3.34.1']
gbp:debug: ['git', 'add', '-f', '.']
gbp:debug: ['git', 'write-tree']
gbp:debug: ['git', 'commit-tree', '1d6f0d8b6276d7ee72fa76fcd2e4cd2d35b86b33']
gbp:debug: ['git', 'update-ref', '-m', 'gbp: Import Upstream version 3.34.1', 'refs/heads/master', 'cefbc7af913751e761e8b9ff7beb83e0d3f59abe']
gbp:debug: ['git', 'symbolic-ref', 'HEAD']
gbp:debug: ['git', 'show-ref', 'refs/heads/master']
gbp:debug: ['git', 'branch', 'upstream', 'master']
gbp:debug: ['git', 'tag', '-m', 'Upstream version 3.34.1', 'upstream/3.34.1', 'cefbc7af913751e761e8b9ff7beb83e0d3f59abe']
gbp:debug: ['git', 'show-ref', '--verify', 'refs/heads/master']
gbp:debug: tar ['-C', '.', '-a', '-xf', '/tmp/sqlite3/sqlite3_3.34.1-3.debian.tar.xz'] []
gbp:debug: ['git', 'rev-parse', '--quiet', '--verify', 'cefbc7af913751e761e8b9ff7beb83e0d3f59abe^{commit}']
gbp:debug: ['git', 'branch', '--contains', 'cefbc7af913751e761e8b9ff7beb83e0d3f59abe']
gbp:debug: ['git', 'add', '-f', '.']
gbp:debug: ['git', 'write-tree']
gbp:debug: ['git', 'rev-parse', '--quiet', '--verify', 'master']
gbp:debug: ['git', 'commit-tree', 'a39172afdec174692199169ccecf1578cfc4b84e', '-p', 'cefbc7af913751e761e8b9ff7beb83e0d3f59abe']
gbp:debug: ['git', 'update-ref', '-m', 'gbp: Import Debian changes 3.34.1-3', 'refs/heads/master', '9ab03e07211eb7c103ebd31fabc5325f47cd2d8d', 'cefbc7af913751e761e8b9ff7beb83e0d3f59abe']
gbp:debug: ['git', 'tag', '-m', 'Debian release 3.34.1-3', 'debian/3.34.1-3', '9ab03e07211eb7c103ebd31fabc5325f47cd2d8d']
gbp:debug: ['git', 'ls-tree', '-z', 'cefbc7af913751e761e8b9ff7beb83e0d3f59abe', '--']
gbp:debug: ['git', 'mktree', '-z']
gbp:debug: ['git', 'ls-tree', '-z', 'cefbc7af913751e761e8b9ff7beb83e0d3f59abe', '--']
gbp:debug: Creating pristine tar commit '/tmp/sqlite3/sqlite3_3.34.1.orig-www.tar.xz' from 'caa99a00bc6709686138dd8813a810f6fa9eef90'
gbp:debug: pristine-tar [] ['commit', '/tmp/sqlite3/sqlite3_3.34.1.orig-www.tar.xz', 'caa99a00bc6709686138dd8813a810f6fa9eef90']
gbp:debug: pristine-tar [] ['commit', '/tmp/sqlite3/sqlite3_3.34.1.orig.tar.xz', 'b8d2ba8963a49f910bb8dfe27e0a3926c3f9a72c']
gbp:debug: ['git', 'symbolic-ref', 'HEAD']
gbp:debug: ['git', 'show-ref', 'refs/heads/master']
gbp:debug: ['git', 'rev-parse', '--quiet', '--verify', 'master']
gbp:debug: ['git', 'reset', '--quiet', '--hard', '9ab03e07211eb7c103ebd31fabc5325f47cd2d8d', '--']
gbp:debug: rm ['-rf', '/tmp/sqlite3/tmp4mt7atb8'] []
gbp:info: Version '3.34.1-3' imported under '/tmp/sqlite3/sqlite3'
```

gbp imports ok, but leaves a dangling tree-ish
```
$ git fsck --lost-found
Checking object directories: 100% (256/256), done.
dangling tree b8d2ba8963a49f910bb8dfe27e0a3926c3f9a72c
```

This means that if you push (not mirror), or prune dangling objects, you cannot checkout the main tarball.
```
$ git reflog expire --expire=now && git gc --aggressive --prune=now && git fsck --lost-found
Enumerating objects: 2909, done.
Counting objects: 100% (2909/2909), done.
Delta compression using up to 16 threads
Compressing objects: 100% (2884/2884), done.
Writing objects: 100% (2909/2909), done.
Total 2909 (delta 730), reused 0 (delta 0), pack-reused 0
Checking object directories: 100% (256/256), done.
Checking objects: 100% (2909/2909), done.

$ git checkout pristine-tar
$ pristine-tar checkout sqlite3_3.34.1.orig.tar.xz
fatal: ambiguous argument 'b8d2ba8963a49f910bb8dfe27e0a3926c3f9a72c^{tree}': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
fatal: not a valid object name: b8d2ba8963a49f910bb8dfe27e0a3926c3f9a72c^{tree}
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
pristine-tar: command failed: git archive --format=tar b8d2ba8963a49f910bb8dfe27e0a3926c3f9a72c\^\{tree\} | (cd '/tmp/pristine-tar.0K_dbuDp2t' && tar x)
```

After playing this afternoon, my quick fix is
```diff
diff --git a/gbp/deb/git.py b/gbp/deb/git.py
index 4a17c2d..8ec06b2 100644
--- a/gbp/deb/git.py
+++ b/gbp/deb/git.py
@@ -292,7 +292,7 @@ class DebianGitRepository(PkgGitRepository):
                        tarball the other ones additional tarballs.
         """
         components = [t.component for t in sources[1:]]
-        main_tree = self.tree_drop_dirs(upstream_tree, components)
+        main_tree = upstream_tree  # self.tree_drop_dirs(upstream_tree, components)

         try:
             for source in sources[1:]:
```

#1031693#10
Date:
2023-12-08 15:52:30 UTC
From:
To:
Hi,

Is there anything I can do to help resolve this issue?

Kind regards,
Huw

#1031693#15
Date:
2024-02-07 18:35:02 UTC
From:
To:
FWIW, this also affects plain "gbp import-orig" with component tar
balls, and the patch from this bug fixes the issue for me when applied
on top of 0.9.33 from sid.