Allow to configure the timeout value for the GitInput plugin in different places.

[?]
Apr 14, 2017, 12:10 AM
34SOPSVFSYMJ4BTJBGREAU4H2LHFWI2GKTGZ6R3B4CTUITMVX35QC

Dependencies

  • [2] Y55DIQQU Support using Git revisions as branch names
  • [3] 7EGUBBRQ Lock paths in the scm cache
  • [4] 2XGB45G7 only checkout the target branch when topgit is used
  • [5] JAH3UPWA Support revision control systems via plugins
  • [6] 3BTJRSU3 GitInput.pm: Don't do a chdir to the Git clone

Change contents

  • edit in src/lib/Hydra/Plugin/GitInput.pm at line 11
    [3.22]
    [4.5040]
    use Env;
    use Data::Dumper;
    my $CONFIG_SECTION = "git-input";
  • edit in src/lib/Hydra/Plugin/GitInput.pm at line 16
    [4.5041]
    [4.5041]
  • replacement in src/lib/Hydra/Plugin/GitInput.pm at line 29
    [3.63][3.63:125]()
    (my $uri, my $branch, my $deepClone) = split ' ', $value;
    [3.63]
    [3.125]
    my @parts = split ' ', $value;
    (my $uri, my $branch, my $deepClone) = @parts;
  • replacement in src/lib/Hydra/Plugin/GitInput.pm at line 32
    [3.177][3.177:217]()
    return ($uri, $branch, $deepClone);
    [3.177]
    [3.217]
    my $options = {};
    my $start_options = 3;
    # if deepClone has "=" then is considered an option
    # and not the enabling of deepClone
    if (index($deepClone, "=") != -1) {
    undef $deepClone;
    $start_options = 2;
    }
    foreach my $option (@parts[$start_options .. $#parts]) {
    (my $key, my $value) = split('=', $option);
    $options->{$key} = $value;
    }
    return ($uri, $branch, $deepClone, $options);
    }
    sub _printIfDebug {
    my ($msg) = @_;
    print STDERR "GitInput: $msg" if $ENV{'HYDRA_DEBUG'};
    }
    =item _pluginConfig($main_config, $input_name)
    Read the configuration from the main hydra config file.
    The configuration is loaded from the "git-input" block.
    Currently only the "timeout" variable is been looked up in the file.
    The variables defined directly in the input value will override
    the ones on the configuration file, to define the variables
    as an input value use: <name>=<value> without spaces and
    specify at least he repo url and branch.
    <git-input>
    # general timeout
    timeout = 400
    <input-name>
    # specific timeout for a particular input name
    timeout = 400
    </input-name>
    # use quotes when the input name has spaces
    <"foot with spaces">
    # specific timeout for a particular input name
    timeout = 400
    </"foo with spaces">
    </git-input>
    =cut
    sub _pluginConfig {
    my ($main_config, $input_name) = @_;
    my $cfg = $main_config->{$CONFIG_SECTION};
    # default values
    my $values = {
    timeout => 600,
    };
    unless (defined $cfg) {
    _printIfDebug "Unable to load $CONFIG_SECTION section\n";
    _printIfDebug "Using default values\n";
    return $values;
    } else {
    _printIfDebug "Parsing plugin configuration: ";
    _printIfDebug Dumper($cfg);
    }
    if (defined $cfg->{$input_name} and %{$cfg->{$input_name}}) {
    _printIfDebug "Merging sections for $input_name\n";
    $cfg = {%{$cfg}, %{$cfg->{$input_name}}}; # merge with precedense to the input name
    }
    if (exists $cfg->{timeout}) {
    $values->{timeout} = int($cfg->{timeout});
    _printIfDebug "Using custom timeout for $input_name:";
    } else {
    _printIfDebug "Using default timeout for $input_name:";
    }
    _printIfDebug "$values->{timeout}\n";
    return $values;
  • replacement in src/lib/Hydra/Plugin/GitInput.pm at line 114
    [3.318][3.318:376]()
    my ($uri, $branch, $deepClone) = _parseValue($value);
    [3.318]
    [4.5421]
    my ($uri, $branch, $deepClone, $options) = _parseValue($value);
    my $cfg = _pluginConfig($self->{config}, $name);
    # give preference to the options from the input value
    while (my ($opt_name, $opt_value) = each %{$options}) {
    if ($opt_value =~ /\d+/) {
    $opt_value = int($opt_value);
    }
    $cfg->{$opt_name} = $opt_value;
    _printIfDebug "'$name': override '$opt_name' with input value: $opt_value\n";
    }
  • replacement in src/lib/Hydra/Plugin/GitInput.pm at line 146
    [2.422][2.422:540](),[2.540][4.1322:1433](),[4.1322][4.1322:1433]()
    $res = run(cmd => ["git", "fetch", "-fu", "origin", "+$branch:$localBranch"], dir => $clonePath, timeout => 600);
    $res = run(cmd => ["git", "fetch", "-fu", "origin"], dir => $clonePath, timeout => 600) if $res->{status};
    [2.422]
    [4.1433]
    $res = run(cmd => ["git", "fetch", "-fu", "origin", "+$branch:$localBranch"], dir => $clonePath,
    timeout => $cfg->{timeout});
    $res = run(cmd => ["git", "fetch", "-fu", "origin"], dir => $clonePath, timeout => $cfg->{timeout}) if $res->{status};
  • replacement in src/lib/Hydra/Plugin/GitInput.pm at line 165
    [4.7509][4.1712:1820]()
    $res = run(cmd => ["tg", "remote", "--populate", "origin"], dir => $clonePath, timeout => 600);
    [4.7509]
    [4.1820]
    $res = run(cmd => ["tg", "remote", "--populate", "origin"], dir => $clonePath, timeout => $cfg->{timeout});