summaryrefslogtreecommitdiff
path: root/usd/importer.py
diff options
context:
space:
mode:
Diffstat (limited to 'usd/importer.py')
-rwxr-xr-xusd/importer.py97
1 files changed, 55 insertions, 42 deletions
diff --git a/usd/importer.py b/usd/importer.py
index 12a825b..dc6c122 100755
--- a/usd/importer.py
+++ b/usd/importer.py
@@ -47,6 +47,46 @@ except ImportError:
logging.error('Is %s installed?', pkg)
sys.exit(1)
+
+def dsc_to_tree_hash(repo, dsc_path):
+ '''Convert a dsc file into a git tree in the given repo
+
+ repo: USDGitRepository object
+ dsc_path: string path to dsc file
+
+ Returns: tree hash as a hex string
+ '''
+ extract_dir = tempfile.mkdtemp()
+
+ oldcwd = os.getcwd()
+ os.chdir(extract_dir)
+
+ run(['dpkg-source',
+ '-x',
+ '--skip-patches',
+ dsc_path,
+ ]
+ )
+
+ extracted_dir = None
+ for path in os.listdir(extract_dir):
+ if os.path.isdir(path):
+ extracted_dir = os.path.join(extract_dir, path)
+ break
+ if extracted_dir is None:
+ logging.exception('No source extracted?')
+ raise SourceExtractionException
+
+ repo.git_run(['--work-tree', extracted_dir, 'add', '-f', '-A'])
+ cp = repo.git_run(['--work-tree', extracted_dir, 'write-tree'])
+ import_tree_hash = decode_binary(cp.stdout).strip()
+
+ os.chdir(oldcwd)
+ shutil.rmtree(extract_dir)
+
+ return import_tree_hash
+
+
class USDImport:
def __init__(self):
self.parent_overrides = None
@@ -179,7 +219,8 @@ class USDImport:
msg = (b'Import %s version %b to %b\n\nImported using usd-importer.' %
(import_type.encode(), spi.version.encode(), pretty_head_name.encode())
)
- commit_tree = ['git', 'commit-tree', tree_hash]
+
+ parents = []
if publish_parent_commit is None and \
changelog_parent_commit is None and \
@@ -192,29 +233,26 @@ class USDImport:
msg += b'\n'
if publish_parent_commit is not None:
- commit_tree += ['-p', publish_parent_commit]
+ parents.append(publish_parent_commit)
msg += b'\nPublish parent: %b' % publish_parent_commit.encode()
if changelog_parent_commit is not None:
- commit_tree += ['-p', changelog_parent_commit]
+ parents.append(changelog_parent_commit)
msg += b'\nChangelog parent: %b' % changelog_parent_commit.encode()
if upload_parent_commit is not None:
- commit_tree += ['-p', upload_parent_commit]
+ parents.append('-p', upload_parent_commit)
msg += b'\nUpload parent: %b' % upload_parent_commit.encode()
if unapplied_parent_commit is not None:
- commit_tree += ['-p', unapplied_parent_commit]
+ parents.append(unapplied_parent_commit)
msg += b'\nUnapplied parent: %b' % unapplied_parent_commit.encode()
msg += b'%b' % changelog_entry
- commit_env = copy.copy(self.local_repo.env)
- commit_env.update(self.local_repo.get_commit_environment(tree_hash, spi))
- with tempfile.NamedTemporaryFile() as fp:
- fp.write(msg)
- fp.flush()
- commit_tree += ['-F', fp.name]
- cp = run(commit_tree, env=commit_env)
-
- commit_hash = decode_binary(cp.stdout).strip()
+ commit_hash = local_repo.commit_tree_hash(
+ tree_hash,
+ parents,
+ msg,
+ environment_spi=spi
+ )
self.local_repo.update_head_to_commit(target_head_name, commit_hash)
@@ -351,35 +389,10 @@ class USDImport:
spi - A USDSourcePackageInformation instance
"""
- extract_dir = tempfile.mkdtemp()
-
- oldcwd = os.getcwd()
- os.chdir(extract_dir)
-
- run(['dpkg-source',
- '-x',
- '--skip-patches',
- os.path.join(oldcwd, spi.dsc_pathname),
- ]
- )
-
- extracted_dir = None
- for path in os.listdir(extract_dir):
- if os.path.isdir(path):
- extracted_dir = os.path.join(extract_dir, path)
- break
- if extracted_dir is None:
- logging.exception('No source extracted?')
- raise SourceExtractionException
-
- self.local_repo.git_run(['--work-tree', extracted_dir, 'add', '-f', '-A'])
- cp = self.local_repo.git_run(['--work-tree', extracted_dir, 'write-tree'])
- import_tree_hash = decode_binary(cp.stdout).strip()
-
- os.chdir(oldcwd)
- shutil.rmtree(extract_dir)
+ import_tree_hash = dsc_to_tree_hash(
+ os.path.join(oldcwd, spi.dsc_pathname)
+ )
self.local_repo.clean_repository_state()
-
return import_tree_hash
def import_patches_applied_tree(self, spi):