Skip to content

Commit 8e9b946

Browse files
committed
feat: add configuration for Prakasa Git branch in config manager
1 parent 2fae0be commit 8e9b946

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

src/parallax/config/config_manager.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace parallax
1717
const std::string KEY_WSL_INSTALLER_URL = "wsl_installer_url";
1818
const std::string KEY_WSL_KERNEL_URL = "wsl_kernel_url";
1919
const std::string KEY_PRAKASA_GIT_REPO_URL = "prakasa_git_repo_url";
20+
const std::string KEY_PRAKASA_GIT_BRANCH = "prakasa_git_branch";
2021

2122
// Default configuration file name
2223
const std::string ConfigManager::DEFAULT_CONFIG_PATH = "parallax_config.txt";
@@ -60,6 +61,7 @@ namespace parallax
6061
"wsl_update_x64.msi";
6162
config_values_[KEY_PRAKASA_GIT_REPO_URL] =
6263
"https://github.com/hetu-project/prakasa.git";
64+
config_values_[KEY_PRAKASA_GIT_BRANCH] = "main";
6365
// proxy_url has no default value
6466
}
6567

@@ -106,7 +108,8 @@ namespace parallax
106108
{KEY_WSL_LINUX_DISTRO, config_values_[KEY_WSL_LINUX_DISTRO]},
107109
{KEY_WSL_INSTALLER_URL, config_values_[KEY_WSL_INSTALLER_URL]},
108110
{KEY_WSL_KERNEL_URL, config_values_[KEY_WSL_KERNEL_URL]},
109-
{KEY_PRAKASA_GIT_REPO_URL, config_values_[KEY_PRAKASA_GIT_REPO_URL]}};
111+
{KEY_PRAKASA_GIT_REPO_URL, config_values_[KEY_PRAKASA_GIT_REPO_URL]},
112+
{KEY_PRAKASA_GIT_BRANCH, config_values_[KEY_PRAKASA_GIT_BRANCH]}};
110113

111114
std::string line;
112115
while (std::getline(file, line))
@@ -322,7 +325,7 @@ namespace parallax
322325
{
323326
static const std::set<std::string> valid_keys = {
324327
KEY_PROXY_URL, KEY_WSL_LINUX_DISTRO, KEY_WSL_INSTALLER_URL,
325-
KEY_WSL_KERNEL_URL, KEY_PRAKASA_GIT_REPO_URL};
328+
KEY_WSL_KERNEL_URL, KEY_PRAKASA_GIT_REPO_URL, KEY_PRAKASA_GIT_BRANCH};
326329

327330
return valid_keys.find(key) != valid_keys.end();
328331
}

src/parallax/config/config_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace parallax
1414
extern const std::string KEY_WSL_INSTALLER_URL;
1515
extern const std::string KEY_WSL_KERNEL_URL;
1616
extern const std::string KEY_PRAKASA_GIT_REPO_URL;
17+
extern const std::string KEY_PRAKASA_GIT_BRANCH;
1718

1819
// Configuration file manager class
1920
class ConfigManager

src/parallax/environment/software_installer2.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ namespace parallax
172172
std::string repo_url =
173173
parallax::config::ConfigManager::GetInstance().GetConfigValue(
174174
parallax::config::KEY_PRAKASA_GIT_REPO_URL);
175+
std::string git_branch =
176+
parallax::config::ConfigManager::GetInstance().GetConfigValue(
177+
parallax::config::KEY_PRAKASA_GIT_BRANCH);
175178

176179
const std::string &proxy_url = context_->GetProxyUrl();
177180

@@ -185,26 +188,26 @@ namespace parallax
185188
if (is_update_mode)
186189
{
187190
// Project is installed and has updates, only execute git pull update
188-
std::string pull_cmd = "cd ~/prakasa && git pull";
191+
std::string pull_cmd = "cd ~/prakasa && git checkout " + git_branch + " && git pull";
189192
if (!proxy_url.empty())
190193
{
191-
pull_cmd = "cd ~/prakasa && ALL_PROXY=" + proxy_url + " git pull";
194+
pull_cmd = "cd ~/prakasa && git checkout " + git_branch + " && ALL_PROXY=" + proxy_url + " git pull";
192195
}
193196
commands.emplace_back("update_parallax", pull_cmd, 300, false);
194197
}
195198
else
196199
{
197-
// Project not installed, check if parallax directory exists, decide
200+
// Project not installed, check if prakasa directory exists, decide
198201
// whether to clone or pull
199202
auto [check_dir_code, check_dir_output] = executor_->ExecuteWSL(
200-
"ls -la ~/parallax/.git 2>/dev/null || echo 'not found'", 30);
203+
"ls -la ~/prakasa/.git 2>/dev/null || echo 'not found'", 30);
201204

202205
if (check_dir_code == 0 &&
203206
check_dir_output.find("not found") == std::string::npos)
204207
{
205208
// Directory exists, check if it's a git repository
206209
auto [check_git_code, check_git_output] = executor_->ExecuteWSL(
207-
"cd ~/parallax && git branch 2>/dev/null || echo 'not git'",
210+
"cd ~/prakasa && git branch 2>/dev/null || echo 'not git'",
208211
30);
209212

210213
if (check_git_code == 0 &&
@@ -214,11 +217,11 @@ namespace parallax
214217
info_log(
215218
"[ENV] Prakasa directory exists, updating with git "
216219
"pull...");
217-
std::string pull_cmd = "cd ~/prakasa && git pull";
220+
std::string pull_cmd = "cd ~/prakasa && git checkout " + git_branch + " && git pull";
218221
if (!proxy_url.empty())
219222
{
220223
pull_cmd =
221-
"cd ~/prakasa && ALL_PROXY=" + proxy_url + " git pull";
224+
"cd ~/prakasa && git checkout " + git_branch + " && ALL_PROXY=" + proxy_url + " git pull";
222225
}
223226
commands.emplace_back("update_parallax", pull_cmd, 300, false);
224227
}
@@ -237,7 +240,7 @@ namespace parallax
237240
{
238241
clone_cmd += "ALL_PROXY=" + proxy_url + " ";
239242
}
240-
clone_cmd += "git clone " + repo_url;
243+
clone_cmd += "git clone -b " + git_branch + " " + repo_url;
241244
commands.emplace_back("clone_prakasa", clone_cmd, 600, false);
242245
}
243246
}
@@ -251,7 +254,7 @@ namespace parallax
251254
{
252255
clone_cmd += "ALL_PROXY=" + proxy_url + " ";
253256
}
254-
clone_cmd += "git clone " + repo_url;
257+
clone_cmd += "git clone -b " + git_branch + " " + repo_url;
255258
commands.emplace_back("clone_prakasa", clone_cmd, 600, false);
256259
}
257260
}
@@ -368,22 +371,25 @@ namespace parallax
368371

369372
bool ParallaxProjectInstaller::IsParallaxProjectInstalled()
370373
{
371-
// Check if parallax project is installed (need to check in virtual
374+
// Check if prakasa project is installed (need to check in virtual
372375
// environment)
373376
auto [check_code, check_output] = executor_->ExecuteWSL(
374-
"cd ~/parallax && [ -d ./venv ] && source ./venv/bin/activate && pip "
375-
"list | grep parallax");
377+
"cd ~/prakasa && [ -d ./venv ] && source ./venv/bin/activate && pip "
378+
"list | grep prakasa");
376379
return (check_code == 0 && !check_output.empty());
377380
}
378381

379382
bool ParallaxProjectInstaller::HasParallaxProjectGitUpdates()
380383
{
381384
const std::string &proxy_url = context_->GetProxyUrl();
385+
std::string git_branch =
386+
parallax::config::ConfigManager::GetInstance().GetConfigValue(
387+
parallax::config::KEY_PRAKASA_GIT_BRANCH);
382388

383-
// Check if Parallax project has git updates
389+
// Check if Prakasa project has git updates
384390
// First check if git repository exists
385391
auto [check_git_code, check_git_output] = executor_->ExecuteWSL(
386-
"cd ~/parallax && git rev-parse --is-inside-work-tree 2>/dev/null", 30);
392+
"cd ~/prakasa && git rev-parse --is-inside-work-tree 2>/dev/null", 30);
387393

388394
if (check_git_code != 0)
389395
{
@@ -408,7 +414,7 @@ namespace parallax
408414

409415
// Check if there are differences between local and remote
410416
auto [diff_code, diff_output] = executor_->ExecuteWSL(
411-
"cd ~/prakasa && git rev-list HEAD...origin/main --count 2>/dev/null",
417+
"cd ~/prakasa && git rev-list HEAD...origin/" + git_branch + " --count 2>/dev/null",
412418
30);
413419

414420
if (diff_code == 0 && !diff_output.empty())

0 commit comments

Comments
 (0)