mirror of
https://github.com/mangosfour/server.git
synced 2025-12-15 10:37:02 +00:00
[6807] Fixed multi line messages and other bugs in git_id
This commit is contained in:
parent
0dba9362d6
commit
82ad991969
2 changed files with 34 additions and 28 deletions
|
|
@ -25,7 +25,7 @@ char remotes[NUM_REMOTES][256] = {
|
||||||
|
|
||||||
char origins[NUM_REMOTES][256];
|
char origins[NUM_REMOTES][256];
|
||||||
int rev;
|
int rev;
|
||||||
char head_message[256];
|
char head_message[16384];
|
||||||
char write_file[2048];
|
char write_file[2048];
|
||||||
|
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
|
|
@ -96,7 +96,7 @@ int get_rev(const char *from_msg)
|
||||||
// accept only the rev number format, not the sql update format
|
// accept only the rev number format, not the sql update format
|
||||||
char nr_str[256];
|
char nr_str[256];
|
||||||
if(sscanf(from_msg, "[%[0123456789]]", nr_str) != 1) return 0;
|
if(sscanf(from_msg, "[%[0123456789]]", nr_str) != 1) return 0;
|
||||||
if(buffer[strlen(nr_str)+1] != ']') return 0;
|
if(from_msg[strlen(nr_str)+1] != ']') return 0;
|
||||||
return atoi(nr_str);
|
return atoi(nr_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,24 +105,20 @@ bool find_rev()
|
||||||
// find the highest rev number on either of the remotes
|
// find the highest rev number on either of the remotes
|
||||||
for(int i = 0; i < NUM_REMOTES; i++)
|
for(int i = 0; i < NUM_REMOTES; i++)
|
||||||
{
|
{
|
||||||
if(!origins[i][0]) continue;
|
if(!local && !origins[i][0]) continue;
|
||||||
|
|
||||||
char cmd[512];
|
char cmd[512];
|
||||||
if(local) sprintf(cmd, "git rev-list HEAD --pretty=\"format:%%s\"");
|
if(local) sprintf(cmd, "git log HEAD --pretty=\"format:%%s\"");
|
||||||
else sprintf(cmd, "git rev-list %s/master --pretty=\"format:%%s\"", origins[i]);
|
else sprintf(cmd, "git log %s/master --pretty=\"format:%%s\"", origins[i]);
|
||||||
if( (cmd_pipe = popen( cmd, "rt" )) == NULL )
|
if( (cmd_pipe = popen( cmd, "rt" )) == NULL )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int count = 0, nr;
|
int nr;
|
||||||
while(fgets(buffer, 256, cmd_pipe))
|
while(fgets(buffer, 256, cmd_pipe))
|
||||||
{
|
{
|
||||||
// every second line contains the commit message
|
nr = get_rev(buffer);
|
||||||
if(count++ % 2 == 1)
|
if(nr >= rev)
|
||||||
{
|
rev = nr+1;
|
||||||
nr = get_rev(buffer);
|
|
||||||
if(nr >= rev)
|
|
||||||
rev = nr+1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pclose(cmd_pipe);
|
pclose(cmd_pipe);
|
||||||
}
|
}
|
||||||
|
|
@ -158,36 +154,40 @@ bool write_rev()
|
||||||
|
|
||||||
bool find_head_msg()
|
bool find_head_msg()
|
||||||
{
|
{
|
||||||
if( (cmd_pipe = popen( "git rev-list HEAD --pretty=\"format:%s\"", "rt" )) == NULL )
|
if( (cmd_pipe = popen( "git log -n 1 --pretty=\"format:%s%n%n%b\"", "rt" )) == NULL )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!fgets(buffer, 256, cmd_pipe)) return false;
|
int poz = 0;
|
||||||
if(!fgets(buffer, 256, cmd_pipe)) return false;
|
while(poz < 16384-1 && EOF != (head_message[poz++] = fgetc(cmd_pipe)));
|
||||||
|
head_message[poz-1] = '\0';
|
||||||
|
|
||||||
int len = (int)strnlen(buffer, 256);
|
pclose(cmd_pipe);
|
||||||
if(len <= 0 || len >= 256) return false;
|
|
||||||
// clear the terminating newline
|
|
||||||
buffer[len-1] = '\0';
|
|
||||||
|
|
||||||
if(get_rev(buffer))
|
if(get_rev(head_message))
|
||||||
{
|
{
|
||||||
if(!allow_replace) return false;
|
if(!allow_replace) return false;
|
||||||
// skip the rev number in the commit
|
// skip the rev number in the commit
|
||||||
char *p = strchr(buffer, ']');
|
char *p = strchr(head_message, ']'), *q = head_message;
|
||||||
assert(p && *(p+1));
|
assert(p && *(p+1));
|
||||||
strncpy(head_message, p+2, 256 - (p-buffer));
|
p+=2;
|
||||||
|
while(*p) *q = *p, p++, q++;
|
||||||
|
*q = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(head_message, buffer);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool amend_commit()
|
bool amend_commit()
|
||||||
{
|
{
|
||||||
char cmd[512];
|
char cmd[512];
|
||||||
sprintf(cmd, "git commit -a --amend -m \"[%d] %s\"", rev, head_message);
|
sprintf(cmd, "git commit --amend -F- %s", write_file);
|
||||||
system(cmd);
|
if( (cmd_pipe = popen( cmd, "wt" )) == NULL )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
fprintf(cmd_pipe, "[%d] %s", rev, head_message);
|
||||||
|
pclose(cmd_pipe);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -200,6 +200,10 @@ int main(int argc, char *argv[])
|
||||||
allow_replace = true;
|
allow_replace = true;
|
||||||
if(strncmp(argv[i], "-l", 2) == 0)
|
if(strncmp(argv[i], "-l", 2) == 0)
|
||||||
local = true;
|
local = true;
|
||||||
|
if(strncmp(argv[i], "-h", 2) == 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!find_path()) { printf("ERROR: can't find path\n"); return 1; }
|
if(!find_path()) { printf("ERROR: can't find path\n"); return 1; }
|
||||||
|
|
@ -208,6 +212,8 @@ int main(int argc, char *argv[])
|
||||||
if(!find_head_msg()) { printf("ERROR: can't find head message\n"); return 1; }
|
if(!find_head_msg()) { printf("ERROR: can't find head message\n"); return 1; }
|
||||||
if(!write_rev()) { printf("ERROR: can't write revision_nr.h\n"); return 1; }
|
if(!write_rev()) { printf("ERROR: can't write revision_nr.h\n"); return 1; }
|
||||||
if(!amend_commit()) { printf("ERROR: can't ammend commit\n"); return 1; }
|
if(!amend_commit()) { printf("ERROR: can't ammend commit\n"); return 1; }
|
||||||
|
|
||||||
|
printf("Generated rev %d\n", rev);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#ifndef __REVISION_NR_H__
|
#ifndef __REVISION_NR_H__
|
||||||
#define __REVISION_NR_H__
|
#define __REVISION_NR_H__
|
||||||
#define REVISION_NR "6806"
|
#define REVISION_NR "6807"
|
||||||
#endif // __REVISION_NR_H__
|
#endif // __REVISION_NR_H__
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue