mirror of
https://github.com/mangosfour/server.git
synced 2025-12-12 10:37:03 +00:00
Only use the new index if there are staged changes that need to be preserved
This commit is contained in:
parent
5709c3cb20
commit
1f6d6929f6
1 changed files with 22 additions and 3 deletions
|
|
@ -85,6 +85,7 @@ bool allow_replace = false;
|
||||||
bool local = false;
|
bool local = false;
|
||||||
bool do_fetch = false;
|
bool do_fetch = false;
|
||||||
bool do_sql = false;
|
bool do_sql = false;
|
||||||
|
bool use_new_index = true;
|
||||||
|
|
||||||
// aux
|
// aux
|
||||||
|
|
||||||
|
|
@ -274,6 +275,7 @@ void system_switch_index(const char *cmd)
|
||||||
// but the new index will contains only the desired changes
|
// but the new index will contains only the desired changes
|
||||||
// while the old may contain others
|
// while the old may contain others
|
||||||
system(cmd);
|
system(cmd);
|
||||||
|
if(!use_new_index) return;
|
||||||
if(putenv(new_index_cmd) != 0) return;
|
if(putenv(new_index_cmd) != 0) return;
|
||||||
system(cmd);
|
system(cmd);
|
||||||
if(putenv(old_index_cmd) != 0) return;
|
if(putenv(old_index_cmd) != 0) return;
|
||||||
|
|
@ -340,15 +342,15 @@ bool amend_commit()
|
||||||
{
|
{
|
||||||
printf("+ amending last commit\n");
|
printf("+ amending last commit\n");
|
||||||
|
|
||||||
// commit the contents of the new index
|
// commit the contents of the (new) index
|
||||||
if(putenv(new_index_cmd) != 0) return false;
|
if(use_new_index && putenv(new_index_cmd) != 0) return false;
|
||||||
snprintf(cmd, MAX_CMD, "git commit --amend -F-");
|
snprintf(cmd, MAX_CMD, "git commit --amend -F-");
|
||||||
if( (cmd_pipe = popen( cmd, "w" )) == NULL )
|
if( (cmd_pipe = popen( cmd, "w" )) == NULL )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
fprintf(cmd_pipe, "[%d] %s", rev, head_message);
|
fprintf(cmd_pipe, "[%d] %s", rev, head_message);
|
||||||
pclose(cmd_pipe);
|
pclose(cmd_pipe);
|
||||||
if(putenv(old_index_cmd) != 0) return false;
|
if(use_new_index && putenv(old_index_cmd) != 0) return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -736,7 +738,23 @@ bool change_sql_history()
|
||||||
|
|
||||||
bool prepare_new_index()
|
bool prepare_new_index()
|
||||||
{
|
{
|
||||||
|
if(!use_new_index) return true;
|
||||||
|
|
||||||
|
// only use a new index if there are staged changes that should be preserved
|
||||||
|
if( (cmd_pipe = popen( "git diff --cached", "r" )) == NULL )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(!fgets(buffer, MAX_BUF, cmd_pipe))
|
||||||
|
{
|
||||||
|
use_new_index = false;
|
||||||
|
pclose(cmd_pipe);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
pclose(cmd_pipe);
|
||||||
|
|
||||||
printf("+ preparing new index\n");
|
printf("+ preparing new index\n");
|
||||||
|
|
||||||
// copy the existing index file to a new one
|
// copy the existing index file to a new one
|
||||||
char src_file[MAX_PATH], dst_file[MAX_PATH];
|
char src_file[MAX_PATH], dst_file[MAX_PATH];
|
||||||
|
|
||||||
|
|
@ -762,6 +780,7 @@ bool prepare_new_index()
|
||||||
|
|
||||||
bool cleanup_new_index()
|
bool cleanup_new_index()
|
||||||
{
|
{
|
||||||
|
if(!use_new_index) return true;
|
||||||
printf("+ cleaning up the new index\n");
|
printf("+ cleaning up the new index\n");
|
||||||
char idx_file[MAX_PATH];
|
char idx_file[MAX_PATH];
|
||||||
snprintf(idx_file, MAX_PATH, "%s%s", path_prefix, new_index_file);
|
snprintf(idx_file, MAX_PATH, "%s%s", path_prefix, new_index_file);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue