Skip to content

Commit d7123f0

Browse files
amoralejGerrit Code Review
authored andcommitted
Use always parse_info_file in get_info
Currently, when using parameter gitrev, parsing of rdoinfo file is done in rdopkg instead of using parse_info_file function provided by rdoinfo. In https://review.rdoproject.org/r/#/c/6105/ rdoinfo is adding a second file for dependencies so current yaml load in rdopkg is not enough for proper parsing. This patch changes rdopkg to use parse_info_file from rdoinfo always, even when used with gitrev. In this case rdoinfo will checkout the desired commit and after parsing it checkout again to the original position. Note that we need to force rdoinfo module reload after each checkout as the content may change. Change-Id: If0db2426bb9ecf8612c3f0d58384e748c332c04b
1 parent c0643fe commit d7123f0

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

rdopkg/actionmods/rdoinfo.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import collections
22
import imp
33
import re
4+
import sys
45
import yaml
56

67
from rdopkg import exception
@@ -91,19 +92,26 @@ def __init__(self, *args, **kwargs):
9192
self._info = None
9293

9394
def ensure_rdoinfo(self):
94-
if self.rdoinfo:
95-
return
95+
# when running get_info with gitrev, we are modifying rdoinfo module
96+
# while runing rdopkg. This seems to be problematic if we are using
97+
# the compiled .pyc so i'm forcing to load rdoinfo module from .py
98+
sys.dont_write_bytecode = True
9699
file, path, desc = imp.find_module('rdoinfo', [self.repo_path])
97100
self.rdoinfo = imp.load_module('rdoinfo', file, path, desc)
101+
sys.dont_write_bytecode = False
98102

99103
def get_info(self, gitrev=None):
100-
self.ensure_rdoinfo()
101104
with self.repo_dir():
102105
if gitrev:
103-
infofile = git.get_file_content(gitrev, self.info_file)
104-
info = yaml.load(infofile)
105-
self.rdoinfo.parse_info(info, apply_tag=self.apply_tag)
106+
commit1 = git.current_commit()
107+
git('checkout', gitrev, log_cmd=False)
108+
self.ensure_rdoinfo()
109+
info = self.rdoinfo.parse_info_file(
110+
self.info_file, apply_tag=self.apply_tag)
111+
git('checkout', commit1, log_cmd=False)
112+
self.ensure_rdoinfo()
106113
else:
114+
self.ensure_rdoinfo()
107115
info = self.rdoinfo.parse_info_file(
108116
self.info_file, apply_tag=self.apply_tag)
109117
return info

rdopkg/utils/cmd.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ def current_branch(self):
149149
branch = self('rev-parse', '--abbrev-ref', 'HEAD', log_cmd=False)
150150
return branch
151151

152+
def current_commit(self):
153+
commit = self('rev-parse', 'HEAD', log_cmd=False)
154+
return commit
155+
152156
def ref_exists(self, ref):
153157
o = self('show-ref', '--verify', '--quiet', ref,
154158
fatal=False, log_cmd=False, log_fail=False)

0 commit comments

Comments
 (0)