|
1 | 1 | /************************************************************************** |
2 | 2 | * |
3 | | - * Copyright (c) 2004-18 Simon Peter |
| 3 | + * Copyright (c) 2004-19 Simon Peter |
4 | 4 | * |
5 | 5 | * All Rights Reserved. |
6 | 6 | * |
@@ -483,10 +483,6 @@ static GOptionEntry entries[] = |
483 | 483 | int |
484 | 484 | main (int argc, char *argv[]) |
485 | 485 | { |
486 | | - /* Parse VERSION environment variable. |
487 | | - * We cannot use g_environ_getenv (g_get_environ() since it is too new for CentOS 6 */ |
488 | | - char* version_env; |
489 | | - version_env = getenv("VERSION"); |
490 | 486 |
|
491 | 487 | /* Parse Travis CI environment variables. |
492 | 488 | * https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables |
@@ -556,6 +552,39 @@ main (int argc, char *argv[]) |
556 | 552 | if (showVersionOnly) |
557 | 553 | exit(0); |
558 | 554 |
|
| 555 | + /* Parse VERSION environment variable. |
| 556 | + * We cannot use g_environ_getenv (g_get_environ() since it is too new for CentOS 6 |
| 557 | + * Also, if VERSION is not set and -g is called and if git is on the path, use |
| 558 | + * git rev-parse --short HEAD |
| 559 | + * TODO: Might also want to somehow make use of |
| 560 | + * git rev-parse --abbrev-ref HEAD |
| 561 | + * git log -1 --format=%ci */ |
| 562 | + gchar *version_env; // In which cases do we need to malloc() here? |
| 563 | + version_env = getenv("VERSION"); |
| 564 | + if(guessupdateinformation){ |
| 565 | + if(g_find_program_in_path ("git")) { |
| 566 | + if (version_env == NULL) { |
| 567 | + GError *error = NULL; |
| 568 | + gchar *out = NULL; |
| 569 | + GString *command_line = g_string_new("git"); |
| 570 | + g_string_append_printf(command_line, " rev-parse --short HEAD"); |
| 571 | + int ret = g_spawn_command_line_sync(command_line->str, &out, NULL, NULL, &error); |
| 572 | + g_assert_no_error(error); |
| 573 | + if (ret) { |
| 574 | + version_env = g_strstrip(out); |
| 575 | + } else { |
| 576 | + g_print("Failed to run 'git rev-parse --short HEAD'"); |
| 577 | + } |
| 578 | + g_string_free(command_line, true); |
| 579 | + if (version_env != NULL) { |
| 580 | + g_print("NOTE: Using the output of 'git rev-parse --short HEAD' as the version:\n"); |
| 581 | + g_print(" %s\n", version_env); |
| 582 | + g_print(" Please set the $VERSION environment variable if this is not intended\n"); |
| 583 | + } |
| 584 | + } |
| 585 | + } |
| 586 | + } |
| 587 | + |
559 | 588 | if(!((0 == strcmp(sqfs_comp, "gzip")) || (0 ==strcmp(sqfs_comp, "xz")))) |
560 | 589 | die("Only gzip (faster execution, larger files) and xz (slower execution, smaller files) compression is supported at the moment. Let us know if there are reasons for more, should be easy to add. You could help the project by doing some systematic size/performance measurements. Watch for size, execution speed, and zsync delta size."); |
561 | 590 | /* Check for dependencies here. Better fail early if they are not present. */ |
|
0 commit comments