diff options
Diffstat (limited to 'org.eclipse.jgit.test')
42 files changed, 1416 insertions, 228 deletions
diff --git a/org.eclipse.jgit.test/.classpath b/org.eclipse.jgit.test/.classpath index c99a7b0d34..363ffa34c5 100644 --- a/org.eclipse.jgit.test/.classpath +++ b/org.eclipse.jgit.test/.classpath @@ -16,7 +16,11 @@ <attribute name="test" value="true"/> </attributes> </classpathentry> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"> + <attributes> + <attribute name="module" value="true"/> + </attributes> + </classpathentry> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/org.eclipse.jgit.test/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jgit.test/.settings/org.eclipse.jdt.core.prefs index b853c6a7ed..69e9221102 100644 --- a/org.eclipse.jgit.test/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.jgit.test/.settings/org.eclipse.jdt.core.prefs @@ -7,9 +7,9 @@ org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nul org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.compliance=11 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate @@ -24,6 +24,7 @@ org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled org.eclipse.jdt.core.compiler.problem.discouragedReference=warning org.eclipse.jdt.core.compiler.problem.emptyStatement=warning +org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning @@ -80,6 +81,7 @@ org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warn org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=error org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=error org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled @@ -112,34 +114,66 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=error org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=error -org.eclipse.jdt.core.compiler.source=1.8 +org.eclipse.jdt.core.compiler.release=enabled +org.eclipse.jdt.core.compiler.source=11 +org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false +org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false +org.eclipse.jdt.core.formatter.align_variable_declarations_on_columns=false +org.eclipse.jdt.core.formatter.align_with_spaces=false +org.eclipse.jdt.core.formatter.alignment_for_additive_operator=16 +org.eclipse.jdt.core.formatter.alignment_for_annotations_on_enum_constant=0 +org.eclipse.jdt.core.formatter.alignment_for_annotations_on_field=49 +org.eclipse.jdt.core.formatter.alignment_for_annotations_on_local_variable=49 +org.eclipse.jdt.core.formatter.alignment_for_annotations_on_method=49 +org.eclipse.jdt.core.formatter.alignment_for_annotations_on_package=49 +org.eclipse.jdt.core.formatter.alignment_for_annotations_on_parameter=0 +org.eclipse.jdt.core.formatter.alignment_for_annotations_on_type=49 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_assertion_message=0 org.eclipse.jdt.core.formatter.alignment_for_assignment=0 org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 +org.eclipse.jdt.core.formatter.alignment_for_bitwise_operator=16 org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 +org.eclipse.jdt.core.formatter.alignment_for_compact_loops=16 org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 +org.eclipse.jdt.core.formatter.alignment_for_conditional_expression_chain=0 org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 +org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0 +org.eclipse.jdt.core.formatter.alignment_for_logical_operator=16 org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_module_statements=16 org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 +org.eclipse.jdt.core.formatter.alignment_for_multiplicative_operator=16 +org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_record_components=16 +org.eclipse.jdt.core.formatter.alignment_for_relational_operator=0 org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80 org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 +org.eclipse.jdt.core.formatter.alignment_for_shift_operator=0 +org.eclipse.jdt.core.formatter.alignment_for_string_concatenation=16 org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_record_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 +org.eclipse.jdt.core.formatter.alignment_for_type_annotations=0 +org.eclipse.jdt.core.formatter.alignment_for_type_arguments=0 +org.eclipse.jdt.core.formatter.alignment_for_type_parameters=0 org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16 org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 +org.eclipse.jdt.core.formatter.blank_lines_after_last_class_body_declaration=0 org.eclipse.jdt.core.formatter.blank_lines_after_package=1 +org.eclipse.jdt.core.formatter.blank_lines_before_abstract_method=1 org.eclipse.jdt.core.formatter.blank_lines_before_field=1 org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 @@ -148,6 +182,7 @@ org.eclipse.jdt.core.formatter.blank_lines_before_method=1 org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 org.eclipse.jdt.core.formatter.blank_lines_before_package=0 org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 +org.eclipse.jdt.core.formatter.blank_lines_between_statement_group_in_switch=0 org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line @@ -157,12 +192,18 @@ org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_lambda_body=end_of_line org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_record_constructor=end_of_line +org.eclipse.jdt.core.formatter.brace_position_for_record_declaration=end_of_line org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line +org.eclipse.jdt.core.formatter.comment.align_tags_descriptions_grouped=false +org.eclipse.jdt.core.formatter.comment.align_tags_names_descriptions=false org.eclipse.jdt.core.formatter.comment.clear_blank_lines=false org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false +org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position=false org.eclipse.jdt.core.formatter.comment.format_block_comments=true org.eclipse.jdt.core.formatter.comment.format_comments=true org.eclipse.jdt.core.formatter.comment.format_header=false @@ -172,7 +213,9 @@ org.eclipse.jdt.core.formatter.comment.format_line_comments=true org.eclipse.jdt.core.formatter.comment.format_source_code=true org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true org.eclipse.jdt.core.formatter.comment.indent_root_tags=true +org.eclipse.jdt.core.formatter.comment.indent_tag_description=false org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert +org.eclipse.jdt.core.formatter.comment.insert_new_line_between_different_tags=do not insert org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert org.eclipse.jdt.core.formatter.comment.line_length=80 org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true @@ -184,10 +227,11 @@ org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false -org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true +org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=false org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true +org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_record_header=true org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true org.eclipse.jdt.core.formatter.indent_empty_lines=false @@ -197,15 +241,17 @@ org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false org.eclipse.jdt.core.formatter.indentation.size=4 org.eclipse.jdt.core.formatter.insert_new_line_after_annotation=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package=insert -org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=insert +org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type=insert org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert +org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation=do not insert org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert @@ -219,11 +265,15 @@ org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_after_additive_operator=insert org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_case=insert +org.eclipse.jdt.core.formatter.insert_space_after_arrow_in_switch_default=insert org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_bitwise_operator=insert org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert @@ -249,10 +299,16 @@ org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arg org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_record_components=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert +org.eclipse.jdt.core.formatter.insert_space_after_comma_in_switch_case_expressions=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert +org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow=insert +org.eclipse.jdt.core.formatter.insert_space_after_logical_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_multiplicative_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_not_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert @@ -269,6 +325,7 @@ org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not ins org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_record_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert @@ -277,13 +334,20 @@ org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_after_relational_operator=insert org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert +org.eclipse.jdt.core.formatter.insert_space_after_shift_operator=insert +org.eclipse.jdt.core.formatter.insert_space_after_string_concatenation=insert org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_additive_operator=insert org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert +org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_case=insert +org.eclipse.jdt.core.formatter.insert_space_before_arrow_in_switch_default=insert org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_bitwise_operator=insert org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert @@ -300,6 +364,7 @@ org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not in org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_record_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert @@ -326,10 +391,15 @@ org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_ar org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_record_components=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_comma_in_switch_case_expressions=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow=insert +org.eclipse.jdt.core.formatter.insert_space_before_logical_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_multiplicative_operator=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert @@ -341,6 +411,8 @@ org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_ org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_constructor=insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_record_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert @@ -356,6 +428,7 @@ org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_record_declaration=do not insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert @@ -366,9 +439,12 @@ org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not inser org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_relational_operator=insert org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert +org.eclipse.jdt.core.formatter.insert_space_before_shift_operator=insert +org.eclipse.jdt.core.formatter.insert_space_before_string_concatenation=insert org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert @@ -380,20 +456,63 @@ org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_decla org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert org.eclipse.jdt.core.formatter.join_lines_in_comments=true org.eclipse.jdt.core.formatter.join_wrapped_lines=true +org.eclipse.jdt.core.formatter.keep_annotation_declaration_on_one_line=one_line_never +org.eclipse.jdt.core.formatter.keep_anonymous_type_declaration_on_one_line=one_line_never +org.eclipse.jdt.core.formatter.keep_code_block_on_one_line=one_line_never org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false +org.eclipse.jdt.core.formatter.keep_enum_constant_declaration_on_one_line=one_line_never +org.eclipse.jdt.core.formatter.keep_enum_declaration_on_one_line=one_line_never +org.eclipse.jdt.core.formatter.keep_if_then_body_block_on_one_line=one_line_never org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false +org.eclipse.jdt.core.formatter.keep_lambda_body_block_on_one_line=one_line_never +org.eclipse.jdt.core.formatter.keep_loop_body_block_on_one_line=one_line_never +org.eclipse.jdt.core.formatter.keep_method_body_on_one_line=one_line_never +org.eclipse.jdt.core.formatter.keep_record_constructor_on_one_line=one_line_never +org.eclipse.jdt.core.formatter.keep_record_declaration_on_one_line=one_line_never +org.eclipse.jdt.core.formatter.keep_simple_do_while_body_on_same_line=false +org.eclipse.jdt.core.formatter.keep_simple_for_body_on_same_line=false +org.eclipse.jdt.core.formatter.keep_simple_getter_setter_on_one_line=false +org.eclipse.jdt.core.formatter.keep_simple_while_body_on_same_line=false org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false +org.eclipse.jdt.core.formatter.keep_type_declaration_on_one_line=one_line_never org.eclipse.jdt.core.formatter.lineSplit=80 org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false +org.eclipse.jdt.core.formatter.number_of_blank_lines_after_code_block=0 +org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_code_block=0 org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 +org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_code_block=0 +org.eclipse.jdt.core.formatter.number_of_blank_lines_at_end_of_method_body=0 +org.eclipse.jdt.core.formatter.number_of_blank_lines_before_code_block=0 org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 +org.eclipse.jdt.core.formatter.parentheses_positions_in_annotation=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_catch_clause=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_enum_constant_declaration=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_for_statment=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_if_while_statement=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_lambda_declaration=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_method_delcaration=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_method_invocation=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_record_declaration=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_switch_statement=common_lines +org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true org.eclipse.jdt.core.formatter.tabulation.char=tab org.eclipse.jdt.core.formatter.tabulation.size=4 +org.eclipse.jdt.core.formatter.text_block_indentation=0 org.eclipse.jdt.core.formatter.use_on_off_tags=true org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false +org.eclipse.jdt.core.formatter.wrap_before_additive_operator=true +org.eclipse.jdt.core.formatter.wrap_before_assertion_message_operator=true +org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true +org.eclipse.jdt.core.formatter.wrap_before_bitwise_operator=true +org.eclipse.jdt.core.formatter.wrap_before_conditional_operator=true +org.eclipse.jdt.core.formatter.wrap_before_logical_operator=true +org.eclipse.jdt.core.formatter.wrap_before_multiplicative_operator=true org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true +org.eclipse.jdt.core.formatter.wrap_before_relational_operator=true +org.eclipse.jdt.core.formatter.wrap_before_shift_operator=true +org.eclipse.jdt.core.formatter.wrap_before_string_concatenation=true org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true diff --git a/org.eclipse.jgit.test/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.jgit.test/.settings/org.eclipse.jdt.ui.prefs index fef3713825..5cfb8b6ac6 100644 --- a/org.eclipse.jgit.test/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.jgit.test/.settings/org.eclipse.jdt.ui.prefs @@ -1,7 +1,7 @@ eclipse.preferences.version=1 editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_JGit Format -formatter_settings_version=12 +formatter_settings_version=21 org.eclipse.jdt.ui.ignorelowercasenames=true org.eclipse.jdt.ui.importorder=java;javax;org;com; org.eclipse.jdt.ui.ondemandthreshold=99 diff --git a/org.eclipse.jgit.test/BUILD b/org.eclipse.jgit.test/BUILD index c9b5d37265..9e787fee71 100644 --- a/org.eclipse.jgit.test/BUILD +++ b/org.eclipse.jgit.test/BUILD @@ -42,6 +42,7 @@ DATA = [ EXCLUDED = [ PKG + "api/SecurityManagerTest.java", PKG + "api/SecurityManagerMissingPermissionsTest.java", + PKG + "lib/CommitTemplateConfigTest.java", ] tests(tests = glob( diff --git a/org.eclipse.jgit.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.test/META-INF/MANIFEST.MF index f7a4ae3196..0469113443 100644 --- a/org.eclipse.jgit.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.test/META-INF/MANIFEST.MF @@ -3,10 +3,10 @@ Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Automatic-Module-Name: org.eclipse.jgit.test Bundle-SymbolicName: org.eclipse.jgit.test -Bundle-Version: 5.13.2.qualifier +Bundle-Version: 6.0.1.qualifier Bundle-Localization: plugin Bundle-Vendor: %Bundle-Vendor -Bundle-RequiredExecutionEnvironment: JavaSE-1.8 +Bundle-RequiredExecutionEnvironment: JavaSE-11 Import-Package: com.googlecode.javaewah;version="[1.1.6,2.0.0)", net.bytebuddy.dynamic.loading;version="[1.9.0,2.0.0)", org.apache.commons.compress.archivers;version="[1.15.0,2.0)", @@ -16,59 +16,60 @@ Import-Package: com.googlecode.javaewah;version="[1.1.6,2.0.0)", org.apache.commons.compress.compressors.gzip;version="[1.15.0,2.0)", org.apache.commons.compress.compressors.xz;version="[1.15.0,2.0)", org.assertj.core.api;version="[3.14.0,4.0.0)", - org.eclipse.jgit.annotations;version="[5.13.2,5.14.0)", - org.eclipse.jgit.api;version="[5.13.2,5.14.0)", - org.eclipse.jgit.api.errors;version="[5.13.2,5.14.0)", - org.eclipse.jgit.archive;version="[5.13.2,5.14.0)", - org.eclipse.jgit.attributes;version="[5.13.2,5.14.0)", - org.eclipse.jgit.awtui;version="[5.13.2,5.14.0)", - org.eclipse.jgit.blame;version="[5.13.2,5.14.0)", - org.eclipse.jgit.diff;version="[5.13.2,5.14.0)", - org.eclipse.jgit.dircache;version="[5.13.2,5.14.0)", - org.eclipse.jgit.errors;version="[5.13.2,5.14.0)", - org.eclipse.jgit.events;version="[5.13.2,5.14.0)", - org.eclipse.jgit.fnmatch;version="[5.13.2,5.14.0)", - org.eclipse.jgit.gitrepo;version="[5.13.2,5.14.0)", - org.eclipse.jgit.hooks;version="[5.13.2,5.14.0)", - org.eclipse.jgit.ignore;version="[5.13.2,5.14.0)", - org.eclipse.jgit.ignore.internal;version="[5.13.2,5.14.0)", - org.eclipse.jgit.internal;version="[5.13.2,5.14.0)", - org.eclipse.jgit.internal.fsck;version="[5.13.2,5.14.0)", - org.eclipse.jgit.internal.revwalk;version="[5.13.2,5.14.0)", - org.eclipse.jgit.internal.storage.dfs;version="[5.13.2,5.14.0)", - org.eclipse.jgit.internal.storage.file;version="[5.13.2,5.14.0)", - org.eclipse.jgit.internal.storage.io;version="[5.13.2,5.14.0)", - org.eclipse.jgit.internal.storage.pack;version="[5.13.2,5.14.0)", - org.eclipse.jgit.internal.storage.reftable;version="[5.13.2,5.14.0)", - org.eclipse.jgit.internal.transport.connectivity;version="[5.13.2,5.14.0)", - org.eclipse.jgit.internal.transport.http;version="[5.13.2,5.14.0)", - org.eclipse.jgit.internal.transport.parser;version="[5.13.2,5.14.0)", - org.eclipse.jgit.junit;version="[5.13.2,5.14.0)", - org.eclipse.jgit.junit.time;version="[5.13.2,5.14.0)", - org.eclipse.jgit.lfs;version="[5.13.2,5.14.0)", - org.eclipse.jgit.lib;version="[5.13.2,5.14.0)", - org.eclipse.jgit.lib.internal;version="[5.13.2,5.14.0)", - org.eclipse.jgit.logging;version="[5.13.2,5.14.0)", - org.eclipse.jgit.merge;version="[5.13.2,5.14.0)", - org.eclipse.jgit.nls;version="[5.13.2,5.14.0)", - org.eclipse.jgit.notes;version="[5.13.2,5.14.0)", - org.eclipse.jgit.patch;version="[5.13.2,5.14.0)", - org.eclipse.jgit.pgm;version="[5.13.2,5.14.0)", - org.eclipse.jgit.pgm.internal;version="[5.13.2,5.14.0)", - org.eclipse.jgit.revplot;version="[5.13.2,5.14.0)", - org.eclipse.jgit.revwalk;version="[5.13.2,5.14.0)", - org.eclipse.jgit.revwalk.filter;version="[5.13.2,5.14.0)", - org.eclipse.jgit.storage.file;version="[5.13.2,5.14.0)", - org.eclipse.jgit.storage.pack;version="[5.13.2,5.14.0)", - org.eclipse.jgit.submodule;version="[5.13.2,5.14.0)", - org.eclipse.jgit.transport;version="[5.13.2,5.14.0)", - org.eclipse.jgit.transport.http;version="[5.13.2,5.14.0)", - org.eclipse.jgit.transport.resolver;version="[5.13.2,5.14.0)", - org.eclipse.jgit.treewalk;version="[5.13.2,5.14.0)", - org.eclipse.jgit.treewalk.filter;version="[5.13.2,5.14.0)", - org.eclipse.jgit.util;version="[5.13.2,5.14.0)", - org.eclipse.jgit.util.io;version="[5.13.2,5.14.0)", - org.eclipse.jgit.util.sha1;version="[5.13.2,5.14.0)", + org.eclipse.jgit.annotations;version="[6.0.1,6.1.0)", + org.eclipse.jgit.api;version="[6.0.1,6.1.0)", + org.eclipse.jgit.api.errors;version="[6.0.1,6.1.0)", + org.eclipse.jgit.archive;version="[6.0.1,6.1.0)", + org.eclipse.jgit.attributes;version="[6.0.1,6.1.0)", + org.eclipse.jgit.awtui;version="[6.0.1,6.1.0)", + org.eclipse.jgit.blame;version="[6.0.1,6.1.0)", + org.eclipse.jgit.diff;version="[6.0.1,6.1.0)", + org.eclipse.jgit.dircache;version="[6.0.1,6.1.0)", + org.eclipse.jgit.errors;version="[6.0.1,6.1.0)", + org.eclipse.jgit.events;version="[6.0.1,6.1.0)", + org.eclipse.jgit.fnmatch;version="[6.0.1,6.1.0)", + org.eclipse.jgit.gitrepo;version="[6.0.1,6.1.0)", + org.eclipse.jgit.hooks;version="[6.0.1,6.1.0)", + org.eclipse.jgit.ignore;version="[6.0.1,6.1.0)", + org.eclipse.jgit.ignore.internal;version="[6.0.1,6.1.0)", + org.eclipse.jgit.internal;version="[6.0.1,6.1.0)", + org.eclipse.jgit.internal.fsck;version="[6.0.1,6.1.0)", + org.eclipse.jgit.internal.revwalk;version="[6.0.1,6.1.0)", + org.eclipse.jgit.internal.storage.dfs;version="[6.0.1,6.1.0)", + org.eclipse.jgit.internal.storage.file;version="[6.0.1,6.1.0)", + org.eclipse.jgit.internal.storage.io;version="[6.0.1,6.1.0)", + org.eclipse.jgit.internal.storage.pack;version="[6.0.1,6.1.0)", + org.eclipse.jgit.internal.storage.reftable;version="[6.0.1,6.1.0)", + org.eclipse.jgit.internal.transport.connectivity;version="[6.0.1,6.1.0)", + org.eclipse.jgit.internal.transport.http;version="[6.0.1,6.1.0)", + org.eclipse.jgit.internal.transport.parser;version="[6.0.1,6.1.0)", + org.eclipse.jgit.internal.transport.ssh;version="[6.0.1,6.1.0)", + org.eclipse.jgit.junit;version="[6.0.1,6.1.0)", + org.eclipse.jgit.junit.time;version="[6.0.1,6.1.0)", + org.eclipse.jgit.lfs;version="[6.0.1,6.1.0)", + org.eclipse.jgit.lib;version="[6.0.1,6.1.0)", + org.eclipse.jgit.lib.internal;version="[6.0.1,6.1.0)", + org.eclipse.jgit.logging;version="[6.0.1,6.1.0)", + org.eclipse.jgit.merge;version="[6.0.1,6.1.0)", + org.eclipse.jgit.nls;version="[6.0.1,6.1.0)", + org.eclipse.jgit.notes;version="[6.0.1,6.1.0)", + org.eclipse.jgit.patch;version="[6.0.1,6.1.0)", + org.eclipse.jgit.pgm;version="[6.0.1,6.1.0)", + org.eclipse.jgit.pgm.internal;version="[6.0.1,6.1.0)", + org.eclipse.jgit.revplot;version="[6.0.1,6.1.0)", + org.eclipse.jgit.revwalk;version="[6.0.1,6.1.0)", + org.eclipse.jgit.revwalk.filter;version="[6.0.1,6.1.0)", + org.eclipse.jgit.storage.file;version="[6.0.1,6.1.0)", + org.eclipse.jgit.storage.pack;version="[6.0.1,6.1.0)", + org.eclipse.jgit.submodule;version="[6.0.1,6.1.0)", + org.eclipse.jgit.transport;version="[6.0.1,6.1.0)", + org.eclipse.jgit.transport.http;version="[6.0.1,6.1.0)", + org.eclipse.jgit.transport.resolver;version="[6.0.1,6.1.0)", + org.eclipse.jgit.treewalk;version="[6.0.1,6.1.0)", + org.eclipse.jgit.treewalk.filter;version="[6.0.1,6.1.0)", + org.eclipse.jgit.util;version="[6.0.1,6.1.0)", + org.eclipse.jgit.util.io;version="[6.0.1,6.1.0)", + org.eclipse.jgit.util.sha1;version="[6.0.1,6.1.0)", org.hamcrest;version="[1.1.0,3.0.0)", org.hamcrest.collection;version="[1.1.0,3.0.0)", org.junit;version="[4.13,5.0.0)", diff --git a/org.eclipse.jgit.test/org.eclipse.jgit.core--All-Tests (Java 8) (de).launch b/org.eclipse.jgit.test/org.eclipse.jgit.core--All-Tests (Java 11) (de).launch index f12a529e14..fdfdce834e 100644 --- a/org.eclipse.jgit.test/org.eclipse.jgit.core--All-Tests (Java 8) (de).launch +++ b/org.eclipse.jgit.test/org.eclipse.jgit.core--All-Tests (Java 11) (de).launch @@ -24,7 +24,7 @@ <listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry id="org.eclipse.jdt.launching.classpathentry.defaultClasspath"> <memento exportedEntriesOnly="false" project="org.eclipse.jgit.test"/> </runtimeClasspathEntry> "/> </listAttribute> <booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/> -<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> +<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/> <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.jgit.test"/> <stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx256m"/> diff --git a/org.eclipse.jgit.test/org.eclipse.jgit.core--All-Tests (Java 8).launch b/org.eclipse.jgit.test/org.eclipse.jgit.core--All-Tests (Java 11).launch index b221a11a55..89c23c3234 100644 --- a/org.eclipse.jgit.test/org.eclipse.jgit.core--All-Tests (Java 8).launch +++ b/org.eclipse.jgit.test/org.eclipse.jgit.core--All-Tests (Java 11).launch @@ -21,7 +21,7 @@ <listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry id="org.eclipse.jdt.launching.classpathentry.defaultClasspath"> <memento exportedEntriesOnly="false" project="org.eclipse.jgit.test"/> </runtimeClasspathEntry> "/> </listAttribute> <booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/> -<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> +<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/> <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/> <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.jgit.test"/> <stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx256m"/> diff --git a/org.eclipse.jgit.test/pom.xml b/org.eclipse.jgit.test/pom.xml index 498cc45e5d..3cab362f3e 100644 --- a/org.eclipse.jgit.test/pom.xml +++ b/org.eclipse.jgit.test/pom.xml @@ -19,7 +19,7 @@ <parent> <groupId>org.eclipse.jgit</groupId> <artifactId>org.eclipse.jgit-parent</artifactId> - <version>5.13.2-SNAPSHOT</version> + <version>6.0.1-SNAPSHOT</version> </parent> <artifactId>org.eclipse.jgit.test</artifactId> diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java index 2a553ce1a2..f8a6632918 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolStreamTypeUtilTest.java @@ -81,14 +81,17 @@ public class EolStreamTypeUtilTest { testCheckout(TEXT_CRLF, AUTO_CRLF, "\n", "\r\n"); testCheckout(TEXT_CRLF, AUTO_CRLF, "\r\n", "\r\n"); - testCheckout(TEXT_CRLF, AUTO_CRLF, "\n\r", "\r\n\r"); + testCheckout(TEXT_CRLF, null, "\n\r", "\r\n\r"); + testCheckout(null, AUTO_CRLF, "\n\r", "\n\r"); // Lone CR - testCheckout(TEXT_CRLF, AUTO_CRLF, "\n\r\n", "\r\n\r\n"); + testCheckout(null, AUTO_CRLF, "\n\r\n", "\n\r\n"); + testCheckout(TEXT_CRLF, null, "\n\r\n", "\r\n\r\n"); testCheckout(TEXT_CRLF, AUTO_CRLF, "\r\n\r", "\r\n\r"); testCheckout(TEXT_CRLF, AUTO_CRLF, "a\nb\n", "a\r\nb\r\n"); testCheckout(TEXT_CRLF, AUTO_CRLF, "a\rb\r", "a\rb\r"); - testCheckout(TEXT_CRLF, AUTO_CRLF, "a\n\rb\n\r", "a\r\n\rb\r\n\r"); + testCheckout(TEXT_CRLF, null, "a\n\rb\n\r", "a\r\n\rb\r\n\r"); + testCheckout(null, AUTO_CRLF, "a\n\rb\n\r", "a\n\rb\n\r"); // Lone CR testCheckout(TEXT_CRLF, AUTO_CRLF, "a\r\nb\r\n", "a\r\nb\r\n"); } @@ -198,7 +201,8 @@ public class EolStreamTypeUtilTest { testCheckin(TEXT_LF, AUTO_LF, "\n\r", "\n\r"); testCheckin(TEXT_LF, AUTO_LF, "\n\r\n", "\n\n"); - testCheckin(TEXT_LF, AUTO_LF, "\r\n\r", "\n\r"); + testCheckin(TEXT_LF, null, "\r\n\r", "\n\r"); + testCheckin(null, AUTO_LF, "\r\n\r", "\r\n\r"); // Lone CR testCheckin(TEXT_LF, AUTO_LF, "a\nb\n", "a\nb\n"); testCheckin(TEXT_LF, AUTO_LF, "a\rb\r", "a\rb\r"); @@ -213,14 +217,16 @@ public class EolStreamTypeUtilTest { testCheckin(TEXT_CRLF, AUTO_CRLF, "\n", "\r\n"); testCheckin(TEXT_CRLF, AUTO_CRLF, "\r\n", "\r\n"); - testCheckin(TEXT_CRLF, AUTO_CRLF, "\n\r", "\r\n\r"); + testCheckin(TEXT_CRLF, null, "\n\r", "\r\n\r"); + testCheckin(null, AUTO_CRLF, "\n\r", "\n\r"); // Lone CR testCheckin(TEXT_CRLF, AUTO_CRLF, "\n\r\n", "\r\n\r\n"); testCheckin(TEXT_CRLF, AUTO_CRLF, "\r\n\r", "\r\n\r"); testCheckin(TEXT_CRLF, AUTO_CRLF, "a\nb\n", "a\r\nb\r\n"); testCheckin(TEXT_CRLF, AUTO_CRLF, "a\rb\r", "a\rb\r"); - testCheckin(TEXT_CRLF, AUTO_CRLF, "a\n\rb\n\r", "a\r\n\rb\r\n\r"); + testCheckin(TEXT_CRLF, null, "a\n\rb\n\r", "a\r\n\rb\r\n\r"); + testCheckin(null, AUTO_CRLF, "a\n\rb\n\r", "a\n\rb\n\r"); // Lone CR testCheckin(TEXT_CRLF, AUTO_CRLF, "a\r\nb\r\n", "a\r\nb\r\n"); } @@ -256,47 +262,55 @@ public class EolStreamTypeUtilTest { byte[] inputBytes = input.getBytes(UTF_8); byte[] expectedConversionBytes = expectedConversion.getBytes(UTF_8); - // test using input text and assuming it was declared TEXT - try (InputStream in = EolStreamTypeUtil.wrapInputStream( - new ByteArrayInputStream(inputBytes), - streamTypeText)) { - byte[] b = new byte[1024]; - int len = IO.readFully(in, b, 0); - assertArrayEquals(expectedConversionBytes, Arrays.copyOf(b, len)); + if (streamTypeText != null) { + // test using input text and assuming it was declared TEXT + try (InputStream in = EolStreamTypeUtil.wrapInputStream( + new ByteArrayInputStream(inputBytes), streamTypeText)) { + byte[] b = new byte[1024]; + int len = IO.readFully(in, b, 0); + assertArrayEquals(expectedConversionBytes, + Arrays.copyOf(b, len)); + } } - // test using input text and assuming it was declared AUTO, using binary - // detection - try (InputStream in = EolStreamTypeUtil.wrapInputStream( - new ByteArrayInputStream(inputBytes), - streamTypeWithBinaryCheck)) { - byte[] b = new byte[1024]; - int len = IO.readFully(in, b, 0); - assertArrayEquals(expectedConversionBytes, Arrays.copyOf(b, len)); + if (streamTypeWithBinaryCheck != null) { + // test using input text and assuming it was declared AUTO, using + // binary detection + try (InputStream in = EolStreamTypeUtil.wrapInputStream( + new ByteArrayInputStream(inputBytes), + streamTypeWithBinaryCheck)) { + byte[] b = new byte[1024]; + int len = IO.readFully(in, b, 0); + assertArrayEquals(expectedConversionBytes, + Arrays.copyOf(b, len)); + } } - // now pollute input text with some binary bytes inputBytes = extendWithBinaryData(inputBytes); expectedConversionBytes = extendWithBinaryData(expectedConversionBytes); - // again, test using input text and assuming it was declared TEXT - try (InputStream in = EolStreamTypeUtil.wrapInputStream( - new ByteArrayInputStream(inputBytes), streamTypeText)) { - byte[] b = new byte[1024]; - int len = IO.readFully(in, b, 0); - assertArrayEquals(expectedConversionBytes, Arrays.copyOf(b, len)); + if (streamTypeText != null) { + // again, test using input text and assuming it was declared TEXT + try (InputStream in = EolStreamTypeUtil.wrapInputStream( + new ByteArrayInputStream(inputBytes), streamTypeText)) { + byte[] b = new byte[1024]; + int len = IO.readFully(in, b, 0); + assertArrayEquals(expectedConversionBytes, + Arrays.copyOf(b, len)); + } } - // again, test using input text and assuming it was declared AUTO, using - // binary - // detection - try (InputStream in = EolStreamTypeUtil.wrapInputStream( - new ByteArrayInputStream(inputBytes), - streamTypeWithBinaryCheck)) { - byte[] b = new byte[1024]; - int len = IO.readFully(in, b, 0); - // expect no conversion - assertArrayEquals(inputBytes, Arrays.copyOf(b, len)); + if (streamTypeWithBinaryCheck != null) { + // again, test using input text and assuming it was declared AUTO, + // using binary detection + try (InputStream in = EolStreamTypeUtil.wrapInputStream( + new ByteArrayInputStream(inputBytes), + streamTypeWithBinaryCheck)) { + byte[] b = new byte[1024]; + int len = IO.readFully(in, b, 0); + // expect no conversion + assertArrayEquals(inputBytes, Arrays.copyOf(b, len)); + } } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GarbageCollectCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GarbageCollectCommandTest.java index 623cdde7b7..f98db3497b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GarbageCollectCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GarbageCollectCommandTest.java @@ -39,7 +39,7 @@ public class GarbageCollectCommandTest extends RepositoryTestCase { Date expire = GitDateParser.parse("now", null, SystemReader .getInstance().getLocale()); Properties res = git.gc().setExpire(expire).call(); - assertTrue(res.size() == 7); + assertTrue(res.size() == 8); } @Test @@ -57,6 +57,6 @@ public class GarbageCollectCommandTest extends RepositoryTestCase { .setExpire( GitDateParser.parse("now", null, SystemReader .getInstance().getLocale())).call(); - assertTrue(res.size() == 7); + assertTrue(res.size() == 8); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java index 5ddc16aaaa..a786065561 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java @@ -324,7 +324,7 @@ public class PushCommandTest extends RepositoryTestCase { // run a gc to ensure we have a bitmap index Properties res = git1.gc().setExpire(null).call(); - assertEquals(7, res.size()); + assertEquals(8, res.size()); // create another commit so we have something else to push writeTrashFile("b", "content of b"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java index b694f4aaf7..a093cc78de 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java @@ -608,7 +608,7 @@ public class DiffFormatterTest extends RepositoryTestCase { public void testDiffAutoCrlfMediumFile() throws Exception { String content = mediumCrLfString(); String expectedDiff = "diff --git a/test.txt b/test.txt\n" - + "index 215c502..c10f08c 100644\n" // + + "index 6d9ffed..50d7b5a 100644\n" // + "--- a/test.txt\n" // + "+++ b/test.txt\n" // + "@@ -1,4 +1,5 @@\n" // @@ -624,7 +624,7 @@ public class DiffFormatterTest extends RepositoryTestCase { public void testDiffAutoCrlfLargeFile() throws Exception { String content = largeCrLfString(); String expectedDiff = "diff --git a/test.txt b/test.txt\n" - + "index 7014942..c0487a7 100644\n" // + + "index d6399a1..de26ce5 100644\n" // + "--- a/test.txt\n" // + "+++ b/test.txt\n" // + "@@ -1,4 +1,5 @@\n" @@ -665,9 +665,9 @@ public class DiffFormatterTest extends RepositoryTestCase { private static String largeCrLfString() { String line = "012345678901234567890123456789012345678901234567\r\n"; - StringBuilder builder = new StringBuilder( - 2 * RawText.FIRST_FEW_BYTES); - while (builder.length() < 2 * RawText.FIRST_FEW_BYTES) { + int bufferSize = RawText.getBufferSize(); + StringBuilder builder = new StringBuilder(2 * bufferSize); + while (builder.length() < 2 * bufferSize) { builder.append(line); } return builder.toString(); @@ -677,9 +677,9 @@ public class DiffFormatterTest extends RepositoryTestCase { // Create a CR-LF string longer than RawText.FIRST_FEW_BYTES whose // canonical representation is shorter than RawText.FIRST_FEW_BYTES. String line = "01234567\r\n"; // 10 characters - StringBuilder builder = new StringBuilder( - RawText.FIRST_FEW_BYTES + line.length()); - while (builder.length() <= RawText.FIRST_FEW_BYTES) { + int bufferSize = RawText.getBufferSize(); + StringBuilder builder = new StringBuilder(bufferSize + line.length()); + while (builder.length() <= bufferSize) { builder.append(line); } return builder.toString(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/HistogramDiffTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/HistogramDiffTest.java index 0256848e1d..3e288673ff 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/HistogramDiffTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/HistogramDiffTest.java @@ -61,7 +61,8 @@ public class HistogramDiffTest extends AbstractDiffTestCase { hd.setFallbackAlgorithm(null); hd.setMaxChainLength(3); - SequenceComparator<RawText> cmp = new SequenceComparator<RawText>() { + SequenceComparator<RawText> cmp = new SequenceComparator<>() { + @Override public boolean equals(RawText a, int ai, RawText b, int bi) { return RawTextComparator.DEFAULT.equals(a, ai, b, bi); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java index 7e513d2c39..d02bfcd3f6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/indexdiff/IndexDiffWithSymlinkTest.java @@ -59,6 +59,7 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; +import java.lang.reflect.InaccessibleObjectException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.nio.file.Files; @@ -227,7 +228,8 @@ public class IndexDiffWithSymlinkTest extends LocalDiskRepositoryTestCase { return (byte[]) method.invoke(p); } } catch (NoSuchMethodException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException e) { + | IllegalArgumentException | InvocationTargetException + | InaccessibleObjectException e) { // Ignore and fall through. } return null; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/BitmappedObjectReachabilityTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/BitmappedObjectReachabilityTest.java index f2f74050b9..d5744280eb 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/BitmappedObjectReachabilityTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/BitmappedObjectReachabilityTest.java @@ -23,7 +23,7 @@ public class BitmappedObjectReachabilityTest // GC generates the bitmaps GC gc = new GC(repository.getRepository()); gc.setAuto(false); - gc.gc(); + gc.gc().get(); return new BitmappedObjectReachabilityChecker( repository.getRevWalk().toObjectWalkWithSameObjects()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/BitmappedReachabilityCheckerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/BitmappedReachabilityCheckerTest.java index 5833c7a81b..253246eecd 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/BitmappedReachabilityCheckerTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/revwalk/BitmappedReachabilityCheckerTest.java @@ -25,7 +25,7 @@ public class BitmappedReachabilityCheckerTest // GC generates the bitmaps GC gc = new GC(repo.getRepository()); gc.setAuto(false); - gc.gc(); + gc.gc().get(); // This is null when the test didn't create any branch assertNotNull("Probably the test didn't define any ref", diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheTest.java index cea00daad8..4f1314057f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsBlockCacheTest.java @@ -10,19 +10,28 @@ package org.eclipse.jgit.internal.storage.dfs; +import static java.util.concurrent.TimeUnit.MILLISECONDS; import static org.eclipse.jgit.lib.Constants.OBJ_BLOB; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.LongStream; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import org.eclipse.jgit.internal.storage.pack.PackExt; +import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.junit.TestRng; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectInserter; import org.eclipse.jgit.lib.ObjectReader; +import org.eclipse.jgit.revwalk.RevCommit; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -33,10 +42,12 @@ public class DfsBlockCacheTest { public TestName testName = new TestName(); private TestRng rng; private DfsBlockCache cache; + private ExecutorService pool; @Before public void setUp() { rng = new TestRng(testName.getMethodName()); + pool = Executors.newFixedThreadPool(10); resetCache(); } @@ -103,10 +114,222 @@ public class DfsBlockCacheTest { } } + @SuppressWarnings("resource") + @Test + public void hasCacheHotMap() throws Exception { + Map<PackExt, Integer> cacheHotMap = new HashMap<>(); + // Pack index will be kept in cache longer. + cacheHotMap.put(PackExt.INDEX, Integer.valueOf(3)); + DfsBlockCache.reconfigure(new DfsBlockCacheConfig().setBlockSize(512) + .setBlockLimit(512 * 4).setCacheHotMap(cacheHotMap)); + cache = DfsBlockCache.getInstance(); + + DfsRepositoryDescription repo = new DfsRepositoryDescription("test"); + InMemoryRepository r1 = new InMemoryRepository(repo); + byte[] content = rng.nextBytes(424242); + ObjectId id; + try (ObjectInserter ins = r1.newObjectInserter()) { + id = ins.insert(OBJ_BLOB, content); + ins.flush(); + } + + try (ObjectReader rdr = r1.newObjectReader()) { + byte[] actual = rdr.open(id, OBJ_BLOB).getBytes(); + assertTrue(Arrays.equals(content, actual)); + } + // All cache entries are hot and cache is at capacity. + assertTrue(LongStream.of(cache.getHitCount()).sum() > 0); + assertEquals(99, cache.getFillPercentage()); + + InMemoryRepository r2 = new InMemoryRepository(repo); + content = rng.nextBytes(424242); + try (ObjectInserter ins = r2.newObjectInserter()) { + ins.insert(OBJ_BLOB, content); + ins.flush(); + } + assertEquals(0, LongStream.of(cache.getMissCount()).sum()); + assertTrue(cache.getEvictions()[PackExt.PACK.getPosition()] > 0); + assertEquals(0, cache.getEvictions()[PackExt.INDEX.getPosition()]); + } + + @SuppressWarnings("resource") + @Test + public void noConcurrencySerializedReads_oneRepo() throws Exception { + InMemoryRepository r1 = createRepoWithBitmap("test"); + // Reset cache with concurrency Level at 1 i.e. no concurrency. + resetCache(1); + + DfsReader reader = (DfsReader) r1.newObjectReader(); + for (DfsPackFile pack : r1.getObjectDatabase().getPacks()) { + // Only load non-garbage pack with bitmap. + if (pack.isGarbage()) { + continue; + } + asyncRun(() -> pack.getBitmapIndex(reader)); + asyncRun(() -> pack.getPackIndex(reader)); + asyncRun(() -> pack.getBitmapIndex(reader)); + } + waitForExecutorPoolTermination(); + + assertEquals(1, cache.getMissCount()[PackExt.BITMAP_INDEX.ordinal()]); + assertEquals(1, cache.getMissCount()[PackExt.INDEX.ordinal()]); + // Reverse index has no pack extension, it defaults to 0. + assertEquals(1, cache.getMissCount()[0]); + } + + @SuppressWarnings("resource") + @Test + public void noConcurrencySerializedReads_twoRepos() throws Exception { + InMemoryRepository r1 = createRepoWithBitmap("test1"); + InMemoryRepository r2 = createRepoWithBitmap("test2"); + resetCache(1); + + DfsReader reader = (DfsReader) r1.newObjectReader(); + DfsPackFile[] r1Packs = r1.getObjectDatabase().getPacks(); + DfsPackFile[] r2Packs = r2.getObjectDatabase().getPacks(); + // Safety check that both repos have the same number of packs. + assertEquals(r1Packs.length, r2Packs.length); + + for (int i = 0; i < r1.getObjectDatabase().getPacks().length; ++i) { + DfsPackFile pack1 = r1Packs[i]; + DfsPackFile pack2 = r2Packs[i]; + if (pack1.isGarbage() || pack2.isGarbage()) { + continue; + } + asyncRun(() -> pack1.getBitmapIndex(reader)); + asyncRun(() -> pack2.getBitmapIndex(reader)); + } + + waitForExecutorPoolTermination(); + assertEquals(2, cache.getMissCount()[PackExt.BITMAP_INDEX.ordinal()]); + assertEquals(2, cache.getMissCount()[PackExt.INDEX.ordinal()]); + assertEquals(2, cache.getMissCount()[0]); + } + + @SuppressWarnings("resource") + @Test + public void lowConcurrencyParallelReads_twoRepos() throws Exception { + InMemoryRepository r1 = createRepoWithBitmap("test1"); + InMemoryRepository r2 = createRepoWithBitmap("test2"); + resetCache(2); + + DfsReader reader = (DfsReader) r1.newObjectReader(); + DfsPackFile[] r1Packs = r1.getObjectDatabase().getPacks(); + DfsPackFile[] r2Packs = r2.getObjectDatabase().getPacks(); + // Safety check that both repos have the same number of packs. + assertEquals(r1Packs.length, r2Packs.length); + + for (int i = 0; i < r1.getObjectDatabase().getPacks().length; ++i) { + DfsPackFile pack1 = r1Packs[i]; + DfsPackFile pack2 = r2Packs[i]; + if (pack1.isGarbage() || pack2.isGarbage()) { + continue; + } + asyncRun(() -> pack1.getBitmapIndex(reader)); + asyncRun(() -> pack2.getBitmapIndex(reader)); + } + + waitForExecutorPoolTermination(); + assertEquals(2, cache.getMissCount()[PackExt.BITMAP_INDEX.ordinal()]); + assertEquals(2, cache.getMissCount()[PackExt.INDEX.ordinal()]); + assertEquals(2, cache.getMissCount()[0]); + } + + @SuppressWarnings("resource") + @Test + public void lowConcurrencyParallelReads_twoReposAndIndex() + throws Exception { + InMemoryRepository r1 = createRepoWithBitmap("test1"); + InMemoryRepository r2 = createRepoWithBitmap("test2"); + resetCache(2); + + DfsReader reader = (DfsReader) r1.newObjectReader(); + DfsPackFile[] r1Packs = r1.getObjectDatabase().getPacks(); + DfsPackFile[] r2Packs = r2.getObjectDatabase().getPacks(); + // Safety check that both repos have the same number of packs. + assertEquals(r1Packs.length, r2Packs.length); + + for (int i = 0; i < r1.getObjectDatabase().getPacks().length; ++i) { + DfsPackFile pack1 = r1Packs[i]; + DfsPackFile pack2 = r2Packs[i]; + if (pack1.isGarbage() || pack2.isGarbage()) { + continue; + } + asyncRun(() -> pack1.getBitmapIndex(reader)); + asyncRun(() -> pack1.getPackIndex(reader)); + asyncRun(() -> pack2.getBitmapIndex(reader)); + } + waitForExecutorPoolTermination(); + + assertEquals(2, cache.getMissCount()[PackExt.BITMAP_INDEX.ordinal()]); + // Index is loaded once for each repo. + assertEquals(2, cache.getMissCount()[PackExt.INDEX.ordinal()]); + assertEquals(2, cache.getMissCount()[0]); + } + + @SuppressWarnings("resource") + @Test + public void highConcurrencyParallelReads_oneRepo() throws Exception { + InMemoryRepository r1 = createRepoWithBitmap("test"); + resetCache(); + + DfsReader reader = (DfsReader) r1.newObjectReader(); + for (DfsPackFile pack : r1.getObjectDatabase().getPacks()) { + // Only load non-garbage pack with bitmap. + if (pack.isGarbage()) { + continue; + } + asyncRun(() -> pack.getBitmapIndex(reader)); + asyncRun(() -> pack.getPackIndex(reader)); + asyncRun(() -> pack.getBitmapIndex(reader)); + } + waitForExecutorPoolTermination(); + + assertEquals(1, cache.getMissCount()[PackExt.BITMAP_INDEX.ordinal()]); + assertEquals(1, cache.getMissCount()[PackExt.INDEX.ordinal()]); + assertEquals(1, cache.getMissCount()[0]); + } + private void resetCache() { - DfsBlockCache.reconfigure(new DfsBlockCacheConfig() - .setBlockSize(512) - .setBlockLimit(1 << 20)); + resetCache(32); + } + + private void resetCache(int concurrencyLevel) { + DfsBlockCache.reconfigure(new DfsBlockCacheConfig().setBlockSize(512) + .setConcurrencyLevel(concurrencyLevel).setBlockLimit(1 << 20)); cache = DfsBlockCache.getInstance(); } + + private InMemoryRepository createRepoWithBitmap(String repoName) + throws Exception { + DfsRepositoryDescription repoDesc = new DfsRepositoryDescription( + repoName); + InMemoryRepository repo = new InMemoryRepository(repoDesc); + try (TestRepository<InMemoryRepository> repository = new TestRepository<>( + repo)) { + RevCommit commit = repository.branch("/refs/ref1" + repoName) + .commit().add("blob1", "blob1" + repoName).create(); + repository.branch("/refs/ref2" + repoName).commit() + .add("blob2", "blob2" + repoName).parent(commit).create(); + } + new DfsGarbageCollector(repo).pack(null); + return repo; + } + + private void asyncRun(Callable<?> call) { + pool.execute(() -> { + try { + call.call(); + } catch (Exception e) { + // Ignore. + } + }); + } + + private void waitForExecutorPoolTermination() throws Exception { + pool.shutdown(); + pool.awaitTermination(500, MILLISECONDS); + assertTrue("Threads did not complete, likely due to a deadlock.", + pool.isTerminated()); + } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java index 8dc1ddb9f6..6cad8b6c62 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcBasicPackingTest.java @@ -54,7 +54,7 @@ public class GcBasicPackingTest extends GcTestCase { assertEquals(4, stats.numberOfLooseObjects); assertEquals(0, stats.numberOfPackedObjects); configureGc(gc, aggressive); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertEquals(4, stats.numberOfLooseObjects); assertEquals(0, stats.numberOfPackedObjects); @@ -72,7 +72,7 @@ public class GcBasicPackingTest extends GcTestCase { assertEquals(8, stats.numberOfLooseObjects); assertEquals(0, stats.numberOfPackedObjects); configureGc(gc, aggressive); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertEquals(0, stats.numberOfLooseObjects); assertEquals(8, stats.numberOfPackedObjects); @@ -93,7 +93,7 @@ public class GcBasicPackingTest extends GcTestCase { assertEquals(8, stats.numberOfLooseObjects); assertEquals(0, stats.numberOfPackedObjects); configureGc(gc, aggressive); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertEquals(0, stats.numberOfLooseObjects); assertEquals(8, stats.numberOfPackedObjects); @@ -112,7 +112,7 @@ public class GcBasicPackingTest extends GcTestCase { assertEquals(4, stats.numberOfLooseObjects); assertEquals(0, stats.numberOfPackedObjects); configureGc(gc, aggressive); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertEquals(0, stats.numberOfLooseObjects); assertEquals(4, stats.numberOfPackedObjects); @@ -120,7 +120,7 @@ public class GcBasicPackingTest extends GcTestCase { assertEquals(1, stats.numberOfBitmaps); // Do the gc again and check that it hasn't changed anything - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertEquals(0, stats.numberOfLooseObjects); assertEquals(4, stats.numberOfPackedObjects); @@ -140,7 +140,7 @@ public class GcBasicPackingTest extends GcTestCase { assertEquals(8, stats.numberOfLooseObjects); assertEquals(0, stats.numberOfPackedObjects); configureGc(gc, aggressive); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertEquals(0, stats.numberOfLooseObjects); assertEquals(8, stats.numberOfPackedObjects); @@ -168,7 +168,7 @@ public class GcBasicPackingTest extends GcTestCase { gc.setExpireAgeMillis(0); fsTick(); configureGc(gc, aggressive); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertEquals(0, stats.numberOfLooseObjects); @@ -187,7 +187,7 @@ public class GcBasicPackingTest extends GcTestCase { bb2.commit().message("M").add("M", "M").create(); gc.setExpireAgeMillis(0); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertEquals(0, stats.numberOfLooseObjects); assertEquals(4, stats.numberOfPackedObjects); @@ -207,7 +207,7 @@ public class GcBasicPackingTest extends GcTestCase { // The old packfile is too young to be deleted. We should end up with // two pack files gc.setExpire(new Date(oldPackfile.lastModified() - 1)); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertEquals(0, stats.numberOfLooseObjects); // if objects exist in multiple packFiles then they are counted multiple @@ -218,7 +218,7 @@ public class GcBasicPackingTest extends GcTestCase { // repack again but now without a grace period for loose objects. Since // we don't have loose objects anymore this shouldn't change anything gc.setExpireAgeMillis(0); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertEquals(0, stats.numberOfLooseObjects); // if objects exist in multiple packFiles then they are counted multiple @@ -233,7 +233,7 @@ public class GcBasicPackingTest extends GcTestCase { // we want to keep newly-loosened objects though gc.setExpireAgeMillis(-1); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertEquals(1, stats.numberOfLooseObjects); // if objects exist in multiple packFiles then they are counted multiple @@ -252,7 +252,7 @@ public class GcBasicPackingTest extends GcTestCase { bb2.commit().message("M").add("M", "M").create(); gc.setExpireAgeMillis(0); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); fsTick(); @@ -273,7 +273,7 @@ public class GcBasicPackingTest extends GcTestCase { //And we don't want to keep packs full of dead objects gc.setPackExpireAgeMillis(0); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertEquals(0, stats.numberOfLooseObjects); assertEquals(6, stats.numberOfPackedObjects); @@ -284,7 +284,7 @@ public class GcBasicPackingTest extends GcTestCase { public void testPreserveAndPruneOldPacks() throws Exception { testPreserveOldPacks(); configureGc(gc, false).setPrunePreserved(true); - gc.gc(); + gc.gc().get(); assertFalse(repo.getObjectDatabase().getPreservedDirectory().exists()); } @@ -295,7 +295,7 @@ public class GcBasicPackingTest extends GcTestCase { // pack loose object into packfile gc.setExpireAgeMillis(0); - gc.gc(); + gc.gc().get(); PackFile oldPackfile = tr.getRepository().getObjectDatabase().getPacks() .iterator().next().getPackFile(); assertTrue(oldPackfile.exists()); @@ -308,7 +308,7 @@ public class GcBasicPackingTest extends GcTestCase { // preserved directory gc.setPackExpireAgeMillis(0); configureGc(gc, false).setPreserveOldPacks(true); - gc.gc(); + gc.gc().get(); File preservedPackFile = oldPackfile.createPreservedForDirectory( repo.getObjectDatabase().getPreservedDirectory()); @@ -330,7 +330,7 @@ public class GcBasicPackingTest extends GcTestCase { configureGc(gc, false); gc.setExpireAgeMillis(0); gc.setPackExpireAgeMillis(0); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertEquals(0, stats.numberOfLooseObjects); assertEquals(4, stats.numberOfPackedObjects); @@ -347,7 +347,7 @@ public class GcBasicPackingTest extends GcTestCase { // Repack with only orphaned commit, so packfile will be pruned configureGc(gc, false).setPreserveOldPacks(true); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertEquals(0, stats.numberOfLooseObjects); assertEquals(0, stats.numberOfPackedObjects); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcConcurrentTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcConcurrentTest.java index 5cac1e3429..2c5f1a8eba 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcConcurrentTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcConcurrentTest.java @@ -110,7 +110,7 @@ public class GcConcurrentTest extends GcTestCase { test.commit().add("a", "a").create(); GC gc1 = new GC(tr.getRepository()); gc1.setPackExpireAgeMillis(0); - gc1.gc(); + gc1.gc().get(); test.commit().add("b", "b").create(); // Create a new Repository instance and trigger a gc @@ -120,7 +120,7 @@ public class GcConcurrentTest extends GcTestCase { tr.getRepository().getDirectory()); GC gc2 = new GC(r2); gc2.setPackExpireAgeMillis(0); - gc2.gc(); + gc2.gc().get(); new GC(tr.getRepository()).getStatistics(); } @@ -133,7 +133,7 @@ public class GcConcurrentTest extends GcTestCase { GC gc1 = new GC(tr.getRepository()); gc1.setPackExpireAgeMillis(0); - gc1.gc(); + gc1.gc().get(); RevCommit b = test.commit().add("b", "b").create(); @@ -141,7 +141,7 @@ public class GcConcurrentTest extends GcTestCase { tr.getRepository().getDirectory()); GC gc2 = new GC(r2); gc2.setPackExpireAgeMillis(0); - gc2.gc(); + gc2.gc().get(); // Simulate parts of an UploadPack. This is the situation on // server side (e.g. gerrit) when clients are @@ -172,7 +172,7 @@ public class GcConcurrentTest extends GcTestCase { FileRepository repository = tr.getRepository(); GC gc1 = new GC(repository); gc1.setPackExpireAgeMillis(0); - gc1.gc(); + gc1.gc().get(); String oldPackName = getSinglePack(repository).getPackName(); RevCommit b = test.commit().add("b", "b").create(); @@ -180,7 +180,7 @@ public class GcConcurrentTest extends GcTestCase { FileRepository repository2 = new FileRepository(repository.getDirectory()); GC gc2 = new GC(repository2); gc2.setPackExpireAgeMillis(0); - gc2.gc(); + gc2.gc().get(); String newPackName = getSinglePack(repository2).getPackName(); // make sure gc() has caused creation of a new packfile assertNotEquals(oldPackName, newPackName); @@ -210,7 +210,7 @@ public class GcConcurrentTest extends GcTestCase { long start = System.currentTimeMillis(); System.out.println("starting gc"); latch.countDown(); - Collection<Pack> r = gc.gc(); + Collection<Pack> r = gc.gc().get(); System.out.println( "gc took " + (System.currentTimeMillis() - start) + " ms"); return r; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcDeleteEmptyRefsFoldersTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcDeleteEmptyRefsFoldersTest.java index 564f8abfee..39aafc8efa 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcDeleteEmptyRefsFoldersTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcDeleteEmptyRefsFoldersTest.java @@ -48,7 +48,7 @@ public class GcDeleteEmptyRefsFoldersTest extends GcTestCase { setLastModifiedTime(fileTime, heads, REF_FOLDER_02); assertTrue(refDir01.toFile().exists()); assertTrue(refDir02.toFile().exists()); - gc.gc(); + gc.gc().get(); assertFalse(refDir01.toFile().exists()); assertFalse(refDir01.getParent().toFile().exists()); @@ -68,7 +68,7 @@ public class GcDeleteEmptyRefsFoldersTest extends GcTestCase { setLastModifiedTime(fileTime, heads, REF_FOLDER_02); assertTrue(refDir01.toFile().exists()); assertTrue(refDir02.toFile().exists()); - gc.gc(); + gc.gc().get(); assertTrue(Files.exists(refFile)); } @@ -88,7 +88,7 @@ public class GcDeleteEmptyRefsFoldersTest extends GcTestCase { Path refDir02 = Files.createDirectories(heads.resolve(REF_FOLDER_02)); assertTrue(refDir01.toFile().exists()); assertTrue(refDir02.toFile().exists()); - gc.gc(); + gc.gc().get(); assertTrue(refDir01.toFile().exists()); assertTrue(refDir02.toFile().exists()); @@ -104,7 +104,7 @@ public class GcDeleteEmptyRefsFoldersTest extends GcTestCase { assertTrue(refDir02.toFile().exists()); assertTrue(ref01.toFile().exists()); assertTrue(ref02.toFile().exists()); - gc.gc(); + gc.gc().get(); assertTrue(refDir01.toFile().exists()); assertTrue(refDir02.toFile().exists()); assertTrue(ref01.toFile().exists()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcDirCacheSavesObjectsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcDirCacheSavesObjectsTest.java index a4dff26ba6..a51b0c2d27 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcDirCacheSavesObjectsTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcDirCacheSavesObjectsTest.java @@ -25,7 +25,7 @@ public class GcDirCacheSavesObjectsTest extends GcTestCase { stats = gc.getStatistics(); assertEquals(9, stats.numberOfLooseObjects); assertEquals(0, stats.numberOfPackedObjects); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertEquals(1, stats.numberOfLooseObjects); assertEquals(8, stats.numberOfPackedObjects); @@ -43,7 +43,7 @@ public class GcDirCacheSavesObjectsTest extends GcTestCase { assertEquals(0, stats.numberOfPackedObjects); gc.setExpireAgeMillis(0); fsTick(); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertEquals(0, stats.numberOfLooseObjects); assertEquals(8, stats.numberOfPackedObjects); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcKeepFilesTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcKeepFilesTest.java index 5fcdd37575..840c09896d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcKeepFilesTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcKeepFilesTest.java @@ -30,7 +30,7 @@ public class GcKeepFilesTest extends GcTestCase { assertEquals(4, stats.numberOfLooseObjects); assertEquals(0, stats.numberOfPackedObjects); assertEquals(0, stats.numberOfPackFiles); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertEquals(0, stats.numberOfLooseObjects); assertEquals(4, stats.numberOfPackedObjects); @@ -48,7 +48,7 @@ public class GcKeepFilesTest extends GcTestCase { assertEquals(4, stats.numberOfLooseObjects); assertEquals(4, stats.numberOfPackedObjects); assertEquals(1, stats.numberOfPackFiles); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertEquals(0, stats.numberOfLooseObjects); assertEquals(8, stats.numberOfPackedObjects); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcOrphanFilesTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcOrphanFilesTest.java index c5c316d357..620aedf20f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcOrphanFilesTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcOrphanFilesTest.java @@ -50,7 +50,7 @@ public class GcOrphanFilesTest extends GcTestCase { createFileInPackFolder(BITMAP_File_1); createFileInPackFolder(IDX_File_2); createFileInPackFolder(PACK_File_3); - gc.gc(); + gc.gc().get(); assertFalse(new File(packDir, BITMAP_File_1).exists()); assertFalse(new File(packDir, IDX_File_2).exists()); assertTrue(new File(packDir, PACK_File_3).exists()); @@ -62,7 +62,7 @@ public class GcOrphanFilesTest extends GcTestCase { createFileInPackFolder(IDX_File_2); createFileInPackFolder(PACK_File_2); createFileInPackFolder(PACK_File_3); - gc.gc(); + gc.gc().get(); assertFalse(new File(packDir, BITMAP_File_1).exists()); assertTrue(new File(packDir, IDX_File_2).exists()); assertTrue(new File(packDir, PACK_File_2).exists()); @@ -72,7 +72,7 @@ public class GcOrphanFilesTest extends GcTestCase { @Test public void malformedIdxNotDeleted() throws Exception { createFileInPackFolder(IDX_File_malformed); - gc.gc(); + gc.gc().get(); assertTrue(new File(packDir, IDX_File_malformed).exists()); } @@ -84,7 +84,7 @@ public class GcOrphanFilesTest extends GcTestCase { createFileInPackFolder(BITMAP_File_2); createFileInPackFolder(KEEP_File_2); createFileInPackFolder(PACK_File_3); - gc.gc(); + gc.gc().get(); assertFalse(new File(packDir, BITMAP_File_1).exists()); assertTrue(new File(packDir, BITMAP_File_2).exists()); assertTrue(new File(packDir, IDX_File_2).exists()); @@ -102,6 +102,6 @@ public class GcOrphanFilesTest extends GcTestCase { @Test public void noSuchPackFolder() throws Exception { assertTrue(packDir.delete()); - gc.gc(); + gc.gc().get(); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPruneNonReferencedTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPruneNonReferencedTest.java index 7386621204..ca0f6842fc 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPruneNonReferencedTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPruneNonReferencedTest.java @@ -80,7 +80,7 @@ public class GcPruneNonReferencedTest extends GcTestCase { assertEquals(0, stats.numberOfPackedObjects); gc.setExpireAgeMillis(0); fsTick(); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertNoEmptyFanoutDirectories(); assertEquals(0, stats.numberOfLooseObjects); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcReflogTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcReflogTest.java index 0901d8648b..e6c1ee5fd6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcReflogTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcReflogTest.java @@ -59,7 +59,7 @@ public class GcReflogTest extends GcTestCase { .create(); // make sure HEAD exists Git.wrap(repo).checkout().setName("refs/heads/master").call(); - gc.gc(); + gc.gc().get(); } @Test @@ -78,7 +78,7 @@ public class GcReflogTest extends GcTestCase { FileUtils.delete( new File(repo.getDirectory(), "logs/refs/heads/master"), FileUtils.RETRY | FileUtils.SKIP_MISSING); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertEquals(4, stats.numberOfLooseObjects); @@ -104,7 +104,7 @@ public class GcReflogTest extends GcTestCase { new File(repo.getDirectory(), "logs/refs/heads/master"), FileUtils.RETRY | FileUtils.SKIP_MISSING); gc.setExpireAgeMillis(0); - gc.gc(); + gc.gc().get(); stats = gc.getStatistics(); assertEquals(0, stats.numberOfLooseObjects); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcTemporaryFilesTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcTemporaryFilesTest.java index 16bde19f27..1a7dd5e75c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcTemporaryFilesTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcTemporaryFilesTest.java @@ -50,7 +50,7 @@ public class GcTemporaryFilesTest extends GcTestCase { - 24 * 60 * 62 * 1000; tempIndex.setLastModified(_24HoursBefore); tempPack.setLastModified(_24HoursBefore); - gc.gc(); + gc.gc().get(); assertFalse(tempIndex.exists()); assertFalse(tempPack.exists()); } @@ -66,7 +66,7 @@ public class GcTemporaryFilesTest extends GcTestCase { assertTrue(tempIndex.createNewFile()); assertTrue(tempIndex.exists()); assertTrue(tempPack.exists()); - gc.gc(); + gc.gc().get(); assertTrue(tempIndex.exists()); assertTrue(tempPack.exists()); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java index 316e33639d..1a3b3787b1 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java @@ -126,7 +126,7 @@ public class ObjectDirectoryTest extends RepositoryTestCase { // setup a repo which has at least one pack file and trigger // scanning of the packs directory ObjectId id = commitFile("file.txt", "test", "master").getId(); - gc.gc(); + gc.gc().get(); assertFalse(receivingDB.getObjectDatabase().has(unknownID)); assertTrue(receivingDB.getObjectDatabase().hasPackedObject(id)); @@ -155,7 +155,7 @@ public class ObjectDirectoryTest extends RepositoryTestCase { // trigger a gc. This will create packfiles which have likely the // same mtime than the packfolder - gc.gc(); + gc.gc().get(); // To deal with racy-git situations JGit's Filesnapshot class will // report a file/folder potentially dirty if diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileSnapshotTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileSnapshotTest.java index 7c32ce7cea..3de015bd25 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileSnapshotTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackFileSnapshotTest.java @@ -25,8 +25,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.nio.file.StandardOpenOption; -//import java.nio.file.attribute.BasicFileAttributes; -import java.text.ParseException; import java.time.Instant; import java.util.Collection; import java.util.Iterator; @@ -281,8 +279,7 @@ public class PackFileSnapshotTest extends RepositoryTestCase { } private Pack repackAndCheck(int compressionLevel, String oldName, - Long oldLength, AnyObjectId oldChkSum) - throws IOException, ParseException { + Long oldLength, AnyObjectId oldChkSum) throws Exception { Pack p = getSinglePack(gc(compressionLevel)); File pf = p.getPackFile(); // The following two assumptions should not cause the test to fail. If @@ -305,8 +302,7 @@ public class PackFileSnapshotTest extends RepositoryTestCase { return p; } - private Collection<Pack> gc(int compressionLevel) - throws IOException, ParseException { + private Collection<Pack> gc(int compressionLevel) throws Exception { GC gc = new GC(db); PackConfig pc = new PackConfig(db.getConfig()); pc.setCompressionLevel(compressionLevel); @@ -322,7 +318,7 @@ public class PackFileSnapshotTest extends RepositoryTestCase { gc.setPackConfig(pc); gc.setExpireAgeMillis(0); gc.setPackExpireAgeMillis(0); - return gc.gc(); + return gc.gc().get(); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java index 71aca9d80c..1ff2264f67 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java @@ -28,7 +28,6 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.text.ParseException; import java.time.Duration; import java.util.ArrayList; import java.util.Arrays; @@ -232,15 +231,13 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { * Use a repo with bitmap indexes because then PackWriter will use * PackWriterBitmapWalker which had problems with this situation. * - * @throws IOException - * @throws ParseException + * @throws Exception */ @Test - public void testIgnoreNonExistingObjectsWithBitmaps() throws IOException, - ParseException { + public void testIgnoreNonExistingObjectsWithBitmaps() throws Exception { final ObjectId nonExisting = ObjectId .fromString("0000000000000000000000000000000000000001"); - new GC(db).gc(); + new GC(db).gc().get(); createVerifyOpenPack(NONE, haves(nonExisting), false, true, true); // shouldn't throw anything } @@ -732,11 +729,11 @@ public class PackWriterTest extends SampleDataRepositoryTestCase { gc.setPackExpireAgeMillis(Long.MAX_VALUE); gc.setExpireAgeMillis(Long.MAX_VALUE); // Creates packfile P1 (containing C1, T1) - gc.gc(); + gc.gc().get(); // Creates 1 object (C2 commit) git.commit().setMessage("Second commit").call(); // Creates packfile P2 (containing C1, T1, C2) - gc.gc(); + gc.gc().get(); // Create 1 object (C3 commit) git.commit().setMessage("Third commit").call(); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/pack/GcCommitSelectionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/pack/GcCommitSelectionTest.java index cc826c30bd..bb56c84e8e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/pack/GcCommitSelectionTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/pack/GcCommitSelectionTest.java @@ -74,7 +74,7 @@ public class GcCommitSelectionTest extends GcTestCase { gc.setPackExpireAgeMillis(0); // immediately delete old packs gc.setExpireAgeMillis(0); - gc.gc(); + gc.gc().get(); assertEquals(currentCommits * 3, // commit/tree/object gc.getStatistics().numberOfPackedObjects); assertEquals(currentCommits + " commits: ", expectedBitmapCount, @@ -138,7 +138,7 @@ public class GcCommitSelectionTest extends GcTestCase { gc.setPackExpireAgeMillis(0); // immediately delete old packs gc.setExpireAgeMillis(0); - gc.gc(); + gc.gc().get(); assertEquals(currentCommits + " commits: ", expectedBitmapCount, gc.getStatistics().numberOfBitmaps); } @@ -179,7 +179,7 @@ public class GcCommitSelectionTest extends GcTestCase { // Excessive branch history pruning, one old branch. gc.setPackExpireAgeMillis(0); // immediately delete old packs gc.setExpireAgeMillis(0); - gc.gc(); + gc.gc().get(); assertEquals( commitsForSparseBranch + commitsForFullBranch + commitsForShallowBranches, diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/ssh/OpenSshConfigFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/ssh/OpenSshConfigFileTest.java new file mode 100644 index 0000000000..11741b41aa --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/transport/ssh/OpenSshConfigFileTest.java @@ -0,0 +1,636 @@ +/* + * Copyright (C) 2008, 2021 Google Inc. and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +package org.eclipse.jgit.internal.transport.ssh; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.time.Instant; +import java.util.concurrent.TimeUnit; + +import org.eclipse.jgit.junit.RepositoryTestCase; +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.transport.SshConfigStore.HostConfig; +import org.eclipse.jgit.transport.SshConstants; +import org.eclipse.jgit.util.FS; +import org.eclipse.jgit.util.FileUtils; +import org.eclipse.jgit.util.SystemReader; +import org.junit.Before; +import org.junit.Test; + +public class OpenSshConfigFileTest extends RepositoryTestCase { + + private File home; + + private File configFile; + + private OpenSshConfigFile osc; + + @Override + @Before + public void setUp() throws Exception { + super.setUp(); + + home = new File(trash, "home"); + FileUtils.mkdir(home); + + configFile = new File(new File(home, ".ssh"), Constants.CONFIG); + FileUtils.mkdir(configFile.getParentFile()); + + mockSystemReader.setProperty(Constants.OS_USER_NAME_KEY, "jex_junit"); + mockSystemReader.setProperty("TST_VAR", "TEST"); + osc = new OpenSshConfigFile(home, configFile, "jex_junit"); + } + + private void config(String data) throws IOException { + FS fs = FS.DETECTED; + long resolution = FS.getFileStoreAttributes(configFile.toPath()) + .getFsTimestampResolution().toNanos(); + Instant lastMtime = fs.lastModifiedInstant(configFile); + do { + try (final OutputStreamWriter fw = new OutputStreamWriter( + new FileOutputStream(configFile), UTF_8)) { + fw.write(data); + TimeUnit.NANOSECONDS.sleep(resolution); + } catch (InterruptedException e) { + Thread.interrupted(); + } + } while (lastMtime.equals(fs.lastModifiedInstant(configFile))); + } + + private HostConfig lookup(String hostname) { + return osc.lookupDefault(hostname, 0, null); + } + + private void assertHost(String expected, HostConfig h) { + assertEquals(expected, h.getValue(SshConstants.HOST_NAME)); + } + + private void assertUser(String expected, HostConfig h) { + assertEquals(expected, h.getValue(SshConstants.USER)); + } + + private void assertPort(int expected, HostConfig h) { + assertEquals(expected, + OpenSshConfigFile.positive(h.getValue(SshConstants.PORT))); + } + + private void assertIdentity(File expected, HostConfig h) { + String actual = h.getValue(SshConstants.IDENTITY_FILE); + if (expected == null) { + assertNull(actual); + } else { + assertEquals(expected, new File(actual)); + } + } + + private void assertAttempts(int expected, HostConfig h) { + assertEquals(expected, OpenSshConfigFile + .positive(h.getValue(SshConstants.CONNECTION_ATTEMPTS))); + } + + @Test + public void testNoConfig() { + final HostConfig h = lookup("repo.or.cz"); + assertNotNull(h); + assertHost("repo.or.cz", h); + assertUser("jex_junit", h); + assertPort(22, h); + assertAttempts(1, h); + assertIdentity(null, h); + } + + @Test + public void testSeparatorParsing() throws Exception { + config("Host\tfirst\n" + + "\tHostName\tfirst.tld\n" + + "\n" + + "Host second\n" + + " HostName\tsecond.tld\n" + + "Host=third\n" + + "HostName=third.tld\n\n\n" + + "\t Host = fourth\n\n\n" + + " \t HostName\t=fourth.tld\n" + + "Host\t = last\n" + + "HostName \t last.tld"); + assertNotNull(lookup("first")); + assertHost("first.tld", lookup("first")); + assertNotNull(lookup("second")); + assertHost("second.tld", lookup("second")); + assertNotNull(lookup("third")); + assertHost("third.tld", lookup("third")); + assertNotNull(lookup("fourth")); + assertHost("fourth.tld", lookup("fourth")); + assertNotNull(lookup("last")); + assertHost("last.tld", lookup("last")); + } + + @Test + public void testQuoteParsing() throws Exception { + config("Host \"good\"\n" + + " HostName=\"good.tld\"\n" + + " Port=\"6007\"\n" + + " User=\"gooduser\"\n" + + "Host multiple unquoted and \"quoted\" \"hosts\"\n" + + " Port=\"2222\"\n" + + "Host \"spaced\"\n" + + "# Bad host name, but testing preservation of spaces\n" + + " HostName=\" spaced\ttld \"\n" + + "# Misbalanced quotes\n" + + "Host \"bad\"\n" + + "# OpenSSH doesn't allow this but ...\n" + + " HostName=bad.tld\"\n"); + assertHost("good.tld", lookup("good")); + assertUser("gooduser", lookup("good")); + assertPort(6007, lookup("good")); + assertPort(2222, lookup("multiple")); + assertPort(2222, lookup("quoted")); + assertPort(2222, lookup("and")); + assertPort(2222, lookup("unquoted")); + assertPort(2222, lookup("hosts")); + assertHost(" spaced\ttld ", lookup("spaced")); + assertHost("bad.tld", lookup("bad")); + } + + @Test + public void testAdvancedParsing() throws Exception { + // Escaped quotes, and line comments + config("Host foo\n" + + " HostName=\"foo\\\"d.tld\"\n" + + " User= someone#foo\n" + + "Host bar\n" + + " User ' some one#two' # Comment\n" + + " GlobalKnownHostsFile '/a folder/with spaces/hosts' '/other/more hosts' # Comment\n" + + "Host foobar\n" + + " User a\\ u\\ thor\n" + + "Host backslash\n" + + " User some\\one\\\\\\ foo\n" + + "Host backslash_before_quote\n" + + " User \\\"someone#\"el#se\" #Comment\n" + + "Host backslash_in_quote\n" + + " User 'some\\one\\\\\\ foo'\n"); + assertHost("foo\"d.tld", lookup("foo")); + assertUser("someone#foo", lookup("foo")); + HostConfig c = lookup("bar"); + assertUser(" some one#two", c); + assertArrayEquals( + new Object[] { "/a folder/with spaces/hosts", + "/other/more hosts" }, + c.getValues("GlobalKnownHostsFile").toArray()); + assertUser("a u thor", lookup("foobar")); + assertUser("some\\one\\ foo", lookup("backslash")); + assertUser("\"someone#el#se", lookup("backslash_before_quote")); + assertUser("some\\one\\\\ foo", lookup("backslash_in_quote")); + } + + @Test + public void testCaseInsensitiveKeyLookup() throws Exception { + config("Host orcz\n" + "Port 29418\n" + + "\tHostName repo.or.cz\nStrictHostKeyChecking yes\n"); + final HostConfig c = lookup("orcz"); + String exactCase = c.getValue("StrictHostKeyChecking"); + assertEquals("yes", exactCase); + assertEquals(exactCase, c.getValue("stricthostkeychecking")); + assertEquals(exactCase, c.getValue("STRICTHOSTKEYCHECKING")); + assertEquals(exactCase, c.getValue("sTrIcThostKEYcheckING")); + assertNull(c.getValue("sTrIcThostKEYcheckIN")); + } + + @Test + public void testAlias_DoesNotMatch() throws Exception { + config("Host orcz\n" + "Port 29418\n" + + "\tHostName repo.or.cz\n"); + final HostConfig h = lookup("repo.or.cz"); + assertNotNull(h); + assertHost("repo.or.cz", h); + assertUser("jex_junit", h); + assertPort(22, h); + assertIdentity(null, h); + final HostConfig h2 = lookup("orcz"); + assertHost("repo.or.cz", h); + assertUser("jex_junit", h); + assertPort(29418, h2); + assertIdentity(null, h); + } + + @Test + public void testAlias_OptionsSet() throws Exception { + config("Host orcz\n" + "\tHostName repo.or.cz\n" + "\tPort 2222\n" + + "\tUser jex\n" + "\tIdentityFile .ssh/id_jex\n" + + "\tForwardX11 no\n"); + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertHost("repo.or.cz", h); + assertUser("jex", h); + assertPort(2222, h); + assertIdentity(new File(home, ".ssh/id_jex"), h); + } + + @Test + public void testAlias_OptionsKeywordCaseInsensitive() throws Exception { + config("hOsT orcz\n" + "\thOsTnAmE repo.or.cz\n" + "\tPORT 2222\n" + + "\tuser jex\n" + "\tidentityfile .ssh/id_jex\n" + + "\tForwardX11 no\n"); + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertHost("repo.or.cz", h); + assertUser("jex", h); + assertPort(2222, h); + assertIdentity(new File(home, ".ssh/id_jex"), h); + } + + @Test + public void testAlias_OptionsInherit() throws Exception { + config("Host orcz\n" + "\tHostName repo.or.cz\n" + "\n" + "Host *\n" + + "\tHostName not.a.host.example.com\n" + "\tPort 2222\n" + + "\tUser jex\n" + "\tIdentityFile .ssh/id_jex\n" + + "\tForwardX11 no\n"); + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertHost("repo.or.cz", h); + assertUser("jex", h); + assertPort(2222, h); + assertIdentity(new File(home, ".ssh/id_jex"), h); + } + + @Test + public void testAlias_PreferredAuthenticationsDefault() throws Exception { + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertNull(h.getValue(SshConstants.PREFERRED_AUTHENTICATIONS)); + } + + @Test + public void testAlias_PreferredAuthentications() throws Exception { + config("Host orcz\n" + "\tPreferredAuthentications publickey\n"); + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertEquals("publickey", + h.getValue(SshConstants.PREFERRED_AUTHENTICATIONS)); + } + + @Test + public void testAlias_InheritPreferredAuthentications() throws Exception { + config("Host orcz\n" + "\tHostName repo.or.cz\n" + "\n" + "Host *\n" + + "\tPreferredAuthentications 'publickey, hostbased'\n"); + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertEquals("publickey,hostbased", + h.getValue(SshConstants.PREFERRED_AUTHENTICATIONS)); + } + + @Test + public void testAlias_BatchModeDefault() throws Exception { + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertNull(h.getValue(SshConstants.BATCH_MODE)); + } + + @Test + public void testAlias_BatchModeYes() throws Exception { + config("Host orcz\n" + "\tBatchMode yes\n"); + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertTrue(OpenSshConfigFile.flag(h.getValue(SshConstants.BATCH_MODE))); + } + + @Test + public void testAlias_InheritBatchMode() throws Exception { + config("Host orcz\n" + "\tHostName repo.or.cz\n" + "\n" + "Host *\n" + + "\tBatchMode yes\n"); + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertTrue(OpenSshConfigFile.flag(h.getValue(SshConstants.BATCH_MODE))); + } + + @Test + public void testAlias_ConnectionAttemptsDefault() throws Exception { + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertAttempts(1, h); + } + + @Test + public void testAlias_ConnectionAttempts() throws Exception { + config("Host orcz\n" + "\tConnectionAttempts 5\n"); + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertAttempts(5, h); + } + + @Test + public void testAlias_invalidConnectionAttempts() throws Exception { + config("Host orcz\n" + "\tConnectionAttempts -1\n"); + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertAttempts(1, h); + } + + @Test + public void testAlias_badConnectionAttempts() throws Exception { + config("Host orcz\n" + "\tConnectionAttempts xxx\n"); + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertAttempts(1, h); + } + + @Test + public void testDefaultBlock() throws Exception { + config("ConnectionAttempts 5\n\nHost orcz\nConnectionAttempts 3\n"); + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertAttempts(5, h); + } + + @Test + public void testHostCaseInsensitive() throws Exception { + config("hOsT orcz\nConnectionAttempts 3\n"); + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertAttempts(3, h); + } + + @Test + public void testListValueSingle() throws Exception { + config("Host orcz\nUserKnownHostsFile /foo/bar\n"); + final HostConfig c = lookup("orcz"); + assertNotNull(c); + assertEquals("/foo/bar", c.getValue("UserKnownHostsFile")); + } + + @Test + public void testListValueMultiple() throws Exception { + // Tilde expansion occurs within the parser + config("Host orcz\nUserKnownHostsFile \"~/foo/ba z\" /foo/bar \n"); + final HostConfig c = lookup("orcz"); + assertNotNull(c); + assertArrayEquals(new Object[] { new File(home, "foo/ba z").getPath(), + "/foo/bar" }, + c.getValues("UserKnownHostsFile").toArray()); + } + + @Test + public void testRepeatedLookupsWithModification() throws Exception { + config("Host orcz\n" + "\tConnectionAttempts -1\n"); + final HostConfig h1 = lookup("orcz"); + assertNotNull(h1); + assertAttempts(1, h1); + config("Host orcz\n" + "\tConnectionAttempts 5\n"); + final HostConfig h2 = lookup("orcz"); + assertNotNull(h2); + assertNotSame(h1, h2); + assertAttempts(5, h2); + assertAttempts(1, h1); + assertNotSame(h1, h2); + } + + @Test + public void testIdentityFile() throws Exception { + config("Host orcz\nIdentityFile \"~/foo/ba z\"\nIdentityFile /foo/bar"); + final HostConfig h = lookup("orcz"); + assertNotNull(h); + // Does tilde replacement + assertArrayEquals(new Object[] { new File(home, "foo/ba z").getPath(), + "/foo/bar" }, + h.getValues(SshConstants.IDENTITY_FILE).toArray()); + } + + @Test + public void testMultiIdentityFile() throws Exception { + config("IdentityFile \"~/foo/ba z\"\nHost orcz\nIdentityFile /foo/bar\nHOST *\nIdentityFile /foo/baz"); + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertArrayEquals(new Object[] { new File(home, "foo/ba z").getPath(), + "/foo/bar", "/foo/baz" }, + h.getValues(SshConstants.IDENTITY_FILE).toArray()); + } + + @Test + public void testNegatedPattern() throws Exception { + config("Host repo.or.cz\nIdentityFile ~/foo/bar\nHOST !*.or.cz\nIdentityFile /foo/baz"); + final HostConfig h = lookup("repo.or.cz"); + assertNotNull(h); + assertIdentity(new File(home, "foo/bar"), h); + assertArrayEquals(new Object[] { new File(home, "foo/bar").getPath() }, + h.getValues(SshConstants.IDENTITY_FILE).toArray()); + } + + @Test + public void testPattern() throws Exception { + config("Host repo.or.cz\nIdentityFile ~/foo/bar\nHOST *.or.cz\nIdentityFile /foo/baz"); + final HostConfig h = lookup("repo.or.cz"); + assertNotNull(h); + assertIdentity(new File(home, "foo/bar"), h); + assertArrayEquals(new Object[] { new File(home, "foo/bar").getPath(), + "/foo/baz" }, + h.getValues(SshConstants.IDENTITY_FILE).toArray()); + } + + @Test + public void testMultiHost() throws Exception { + config("Host orcz *.or.cz\nIdentityFile ~/foo/bar\nHOST *.or.cz\nIdentityFile /foo/baz"); + final HostConfig h1 = lookup("repo.or.cz"); + assertNotNull(h1); + assertIdentity(new File(home, "foo/bar"), h1); + assertArrayEquals(new Object[] { new File(home, "foo/bar").getPath(), + "/foo/baz" }, + h1.getValues(SshConstants.IDENTITY_FILE).toArray()); + final HostConfig h2 = lookup("orcz"); + assertNotNull(h2); + assertIdentity(new File(home, "foo/bar"), h2); + assertArrayEquals(new Object[] { new File(home, "foo/bar").getPath() }, + h2.getValues(SshConstants.IDENTITY_FILE).toArray()); + } + + @Test + public void testEqualsSign() throws Exception { + config("Host=orcz\n\tConnectionAttempts = 5\n\tUser=\t foobar\t\n"); + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertAttempts(5, h); + assertUser("foobar", h); + } + + @Test + public void testMissingArgument() throws Exception { + config("Host=orcz\n\tSendEnv\nIdentityFile\t\nForwardX11\n\tUser=\t foobar\t\n"); + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertUser("foobar", h); + assertEquals("[]", h.getValues("SendEnv").toString()); + assertIdentity(null, h); + assertNull(h.getValue("ForwardX11")); + } + + @Test + public void testHomeDirUserReplacement() throws Exception { + config("Host=orcz\n\tIdentityFile %d/.ssh/%u_id_dsa"); + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertIdentity(new File(new File(home, ".ssh"), "jex_junit_id_dsa"), h); + } + + @Test + public void testHostnameReplacement() throws Exception { + config("Host=orcz\nHost *.*\n\tHostname %h\nHost *\n\tHostname %h.example.org"); + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertHost("orcz.example.org", h); + } + + @Test + public void testRemoteUserReplacement() throws Exception { + config("Host=orcz\n\tUser foo\n" + "Host *.*\n\tHostname %h\n" + + "Host *\n\tHostname %h.ex%%20ample.org\n\tIdentityFile ~/.ssh/%h_%r_id_dsa"); + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertIdentity( + new File(new File(home, ".ssh"), + "orcz.ex%20ample.org_foo_id_dsa"), + h); + } + + @Test + public void testLocalhostFQDNReplacement() throws Exception { + String localhost = SystemReader.getInstance().getHostname(); + config("Host=orcz\n\tIdentityFile ~/.ssh/%l_id_dsa"); + final HostConfig h = lookup("orcz"); + assertNotNull(h); + assertIdentity( + new File(new File(home, ".ssh"), localhost + "_id_dsa"), + h); + } + + @Test + public void testPubKeyAcceptedAlgorithms() throws Exception { + config("Host=orcz\n\tPubkeyAcceptedAlgorithms ^ssh-rsa"); + HostConfig h = lookup("orcz"); + assertEquals("^ssh-rsa", + h.getValue(SshConstants.PUBKEY_ACCEPTED_ALGORITHMS)); + assertEquals("^ssh-rsa", h.getValue("PubkeyAcceptedKeyTypes")); + } + + @Test + public void testPubKeyAcceptedKeyTypes() throws Exception { + config("Host=orcz\n\tPubkeyAcceptedKeyTypes ^ssh-rsa"); + HostConfig h = lookup("orcz"); + assertEquals("^ssh-rsa", + h.getValue(SshConstants.PUBKEY_ACCEPTED_ALGORITHMS)); + assertEquals("^ssh-rsa", h.getValue("PubkeyAcceptedKeyTypes")); + } + + @Test + public void testEolComments() throws Exception { + config("#Comment\nHost=orcz #Comment\n\tPubkeyAcceptedAlgorithms ^ssh-rsa # Comment\n#Comment"); + HostConfig h = lookup("orcz"); + assertNotNull(h); + assertEquals("^ssh-rsa", + h.getValue(SshConstants.PUBKEY_ACCEPTED_ALGORITHMS)); + } + + @Test + public void testEnVarSubstitution() throws Exception { + config("Host orcz\nIdentityFile /tmp/${TST_VAR}\n" + + "CertificateFile /tmp/${}/foo\nUser ${TST_VAR}\nIdentityAgent /tmp/${TST_VAR/bar"); + HostConfig h = lookup("orcz"); + assertNotNull(h); + assertEquals("/tmp/TEST", + h.getValue(SshConstants.IDENTITY_FILE)); + // No variable name + assertEquals("/tmp/${}/foo", h.getValue(SshConstants.CERTIFICATE_FILE)); + // User doesn't get env var substitution: + assertUser("${TST_VAR}", h); + // Unterminated: + assertEquals("/tmp/${TST_VAR/bar", + h.getValue(SshConstants.IDENTITY_AGENT)); + } + + @Test + public void testNegativeMatch() throws Exception { + config("Host foo.bar !foobar.baz *.baz\n" + "Port 29418\n"); + HostConfig h = lookup("foo.bar"); + assertNotNull(h); + assertPort(29418, h); + h = lookup("foobar.baz"); + assertNotNull(h); + assertPort(22, h); + h = lookup("foo.baz"); + assertNotNull(h); + assertPort(29418, h); + } + + @Test + public void testNegativeMatch2() throws Exception { + // Negative match after the positive match. + config("Host foo.bar *.baz !foobar.baz\n" + "Port 29418\n"); + HostConfig h = lookup("foo.bar"); + assertNotNull(h); + assertPort(29418, h); + h = lookup("foobar.baz"); + assertNotNull(h); + assertPort(22, h); + h = lookup("foo.baz"); + assertNotNull(h); + assertPort(29418, h); + } + + @Test + public void testNoMatch() throws Exception { + config("Host !host1 !host2\n" + "Port 29418\n"); + HostConfig h = lookup("host1"); + assertNotNull(h); + assertPort(22, h); + h = lookup("host2"); + assertNotNull(h); + assertPort(22, h); + h = lookup("host3"); + assertNotNull(h); + assertPort(22, h); + } + + @Test + public void testMultipleMatch() throws Exception { + config("Host foo.bar\nPort 29418\nIdentityFile /foo\n\n" + + "Host *.bar\nPort 22\nIdentityFile /bar\n" + + "Host foo.bar\nPort 47\nIdentityFile /baz\n"); + HostConfig h = lookup("foo.bar"); + assertNotNull(h); + assertPort(29418, h); + assertArrayEquals(new Object[] { "/foo", "/bar", "/baz" }, + h.getValues(SshConstants.IDENTITY_FILE).toArray()); + } + + @Test + public void testWhitespace() throws Exception { + config("Host foo \tbar baz\nPort 29418\n"); + HostConfig h = lookup("foo"); + assertNotNull(h); + assertPort(29418, h); + h = lookup("bar"); + assertNotNull(h); + assertPort(29418, h); + h = lookup("baz"); + assertNotNull(h); + assertPort(29418, h); + h = lookup("\tbar"); + assertNotNull(h); + assertPort(22, h); + } +} diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java new file mode 100644 index 0000000000..6dbe30af2d --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2021 SAP SE and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +package org.eclipse.jgit.lib; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.jgit.errors.ConfigInvalidException; +import org.eclipse.jgit.junit.JGitTestUtil; +import org.eclipse.jgit.storage.file.FileRepositoryBuilder; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +/* + * This test was moved from ConfigTest to allow skipping it when running the + * test using bazel which doesn't allow tests to create files in the home + * directory + */ +public class CommitTemplateConfigTest { + + @Rule + public TemporaryFolder tmp = new TemporaryFolder(); + + @Test + public void testCommitTemplatePathInHomeDirecory() + throws ConfigInvalidException, IOException { + Config config = new Config(null); + File tempFile = tmp.newFile("testCommitTemplate-"); + File workTree = tmp.newFolder("dummy-worktree"); + Repository repo = FileRepositoryBuilder.create(workTree); + String templateContent = "content of the template"; + JGitTestUtil.write(tempFile, templateContent); + // proper evaluation of the ~/ directory + String homeDir = System.getProperty("user.home"); + File tempFileInHomeDirectory = File.createTempFile("fileInHomeFolder", + ".tmp", new File(homeDir)); + tempFileInHomeDirectory.deleteOnExit(); + JGitTestUtil.write(tempFileInHomeDirectory, templateContent); + String expectedTemplatePath = tempFileInHomeDirectory.getPath() + .replace(homeDir, "~"); + config = ConfigTest + .parse("[commit]\n\ttemplate = " + expectedTemplatePath + "\n"); + String templatePath = config.get(CommitConfig.KEY) + .getCommitTemplatePath(); + assertEquals(expectedTemplatePath, templatePath); + assertEquals(templateContent, + config.get(CommitConfig.KEY).getCommitTemplateContent(repo)); + } +} diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java index fe3c1db502..9b82c2afd6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java @@ -55,6 +55,7 @@ import org.eclipse.jgit.junit.JGitTestUtil; import org.eclipse.jgit.junit.MockSystemReader; import org.eclipse.jgit.merge.MergeConfig; import org.eclipse.jgit.storage.file.FileBasedConfig; +import org.eclipse.jgit.storage.file.FileRepositoryBuilder; import org.eclipse.jgit.transport.RefSpec; import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.SystemReader; @@ -1176,7 +1177,7 @@ public class ConfigTest { assertEquals(exp, c.getLong("s", null, "a", 0L)); } - private static Config parse(String content) + static Config parse(String content) throws ConfigInvalidException { return parse(content, null); } @@ -1471,14 +1472,17 @@ public class ConfigTest { // no values defined nowhere Config config = new Config(null); assertNull(config.get(CommitConfig.KEY).getCommitTemplatePath()); - assertNull(config.get(CommitConfig.KEY).getCommitTemplateContent()); + assertNull(config.get(CommitConfig.KEY) + .getCommitTemplateContent(null)); } @Test public void testCommitTemplateConfig() throws ConfigInvalidException, IOException { + File workTree = tmp.newFolder("dummy-worktree"); File tempFile = tmp.newFile("testCommitTemplate-"); + Repository repo = FileRepositoryBuilder.create(workTree); String templateContent = "content of the template"; JGitTestUtil.write(tempFile, templateContent); String expectedTemplatePath = tempFile.getPath(); @@ -1492,78 +1496,86 @@ public class ConfigTest { .getCommitEncoding(); assertEquals(expectedTemplatePath, templatePath); assertEquals(templateContent, - config.get(CommitConfig.KEY).getCommitTemplateContent()); + config.get(CommitConfig.KEY).getCommitTemplateContent(repo)); assertNull("no commitEncoding has been set so it must be null", commitEncoding); } @Test - public void testCommitTemplateEncoding() + public void testCommitTemplateConfigRelativePath() throws ConfigInvalidException, IOException { - Config config = new Config(null); + + File workTree = tmp.newFolder("dummy-worktree"); File tempFile = tmp.newFile("testCommitTemplate-"); String templateContent = "content of the template"; JGitTestUtil.write(tempFile, templateContent); - String expectedTemplatePath = tempFile.getPath(); - config = parse("[i18n]\n\tcommitEncoding = utf-8\n" - + "[commit]\n\ttemplate = " + expectedTemplatePath + "\n"); - assertEquals(templateContent, - config.get(CommitConfig.KEY).getCommitTemplateContent()); + String expectedTemplatePath = "../" + tempFile.getName(); + + Config config = parse( + "[commit]\n\ttemplate = " + expectedTemplatePath + "\n"); + + String templatePath = config.get(CommitConfig.KEY) + .getCommitTemplatePath(); String commitEncoding = config.get(CommitConfig.KEY) .getCommitEncoding(); - assertEquals("commitEncoding has been set to utf-8 it must be utf-8", - "utf-8", commitEncoding); + assertEquals(expectedTemplatePath, templatePath); + assertEquals(templateContent, config.get(CommitConfig.KEY) + .getCommitTemplateContent( + new RepositoryBuilder().setWorkTree(workTree).build())); + assertNull("no commitEncoding has been set so it must be null", + commitEncoding); } @Test - public void testCommitTemplatePathInHomeDirecory() + public void testCommitTemplateEncoding() throws ConfigInvalidException, IOException { Config config = new Config(null); + File workTree = tmp.newFolder("dummy-worktree"); + Repository repo = FileRepositoryBuilder.create(workTree); File tempFile = tmp.newFile("testCommitTemplate-"); String templateContent = "content of the template"; JGitTestUtil.write(tempFile, templateContent); - // proper evaluation of the ~/ directory - String homeDir = System.getProperty("user.home"); - File tempFileInHomeDirectory = File.createTempFile("fileInHomeFolder", - ".tmp", new File(homeDir)); - tempFileInHomeDirectory.deleteOnExit(); - JGitTestUtil.write(tempFileInHomeDirectory, templateContent); - String expectedTemplatePath = tempFileInHomeDirectory.getPath() - .replace(homeDir, "~"); - config = parse("[commit]\n\ttemplate = " + expectedTemplatePath + "\n"); - String templatePath = config.get(CommitConfig.KEY) - .getCommitTemplatePath(); - assertEquals(expectedTemplatePath, templatePath); + String expectedTemplatePath = tempFile.getPath(); + config = parse("[i18n]\n\tcommitEncoding = utf-8\n" + + "[commit]\n\ttemplate = " + expectedTemplatePath + "\n"); assertEquals(templateContent, - config.get(CommitConfig.KEY).getCommitTemplateContent()); + config.get(CommitConfig.KEY).getCommitTemplateContent(repo)); + String commitEncoding = config.get(CommitConfig.KEY) + .getCommitEncoding(); + assertEquals("commitEncoding has been set to utf-8 it must be utf-8", + "utf-8", commitEncoding); } @Test(expected = ConfigInvalidException.class) public void testCommitTemplateWithInvalidEncoding() throws ConfigInvalidException, IOException { Config config = new Config(null); + File workTree = tmp.newFolder("dummy-worktree"); File tempFile = tmp.newFile("testCommitTemplate-"); + Repository repo = FileRepositoryBuilder.create(workTree); String templateContent = "content of the template"; JGitTestUtil.write(tempFile, templateContent); config = parse("[i18n]\n\tcommitEncoding = invalidEcoding\n" + "[commit]\n\ttemplate = " + tempFile.getPath() + "\n"); - config.get(CommitConfig.KEY).getCommitTemplateContent(); + config.get(CommitConfig.KEY).getCommitTemplateContent(repo); } @Test(expected = FileNotFoundException.class) public void testCommitTemplateWithInvalidPath() throws ConfigInvalidException, IOException { Config config = new Config(null); + File workTree = tmp.newFolder("dummy-worktree"); File tempFile = tmp.newFile("testCommitTemplate-"); + Repository repo = FileRepositoryBuilder.create(workTree); String templateContent = "content of the template"; JGitTestUtil.write(tempFile, templateContent); // commit message encoding - String expectedTemplatePath = "nonExistingTemplate"; + String expectedTemplatePath = "/nonExistingTemplate"; config = parse("[commit]\n\ttemplate = " + expectedTemplatePath + "\n"); String templatePath = config.get(CommitConfig.KEY) .getCommitTemplatePath(); assertEquals(expectedTemplatePath, templatePath); - config.get(CommitConfig.KEY).getCommitTemplateContent(); + config.get(CommitConfig.KEY).getCommitTemplateContent(repo); } private static void assertValueRoundTrip(String value) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java index b943486b1b..af8a58f6f0 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java @@ -337,6 +337,34 @@ public class DirCacheCheckoutTest extends RepositoryTestCase { "first line\r\nsecond line\r\n", "f text=auto eol=crlf"); } + @Test + public void testCheckoutMixedAutoEolCrLf() throws Exception { + checkoutLineEndings("first line\nsecond line\r\n", + "first line\nsecond line\r\n", "f text=auto eol=crlf"); + } + + @Test + public void testCheckoutMixedAutoEolLf() throws Exception { + checkoutLineEndings("first line\nsecond line\r\n", + "first line\nsecond line\r\n", "f text=auto eol=lf"); + } + + @Test + public void testCheckoutMixedTextCrLf() throws Exception { + // Huh? Is this a bug in git? Both git 2.18.0 and git 2.33.0 do + // write the file with CRLF (and consequently report the file as + // modified in "git status" after check-out), however the CRLF in the + // repository is _not_ replaced by LF with eol=lf (see test below). + checkoutLineEndings("first line\nsecond line\r\n", + "first line\r\nsecond line\r\n", "f text eol=crlf"); + } + + @Test + public void testCheckoutMixedTextLf() throws Exception { + checkoutLineEndings("first line\nsecond line\r\nfoo", + "first line\nsecond line\r\nfoo", "f text eol=lf"); + } + private DirCacheCheckout resetHard(RevCommit commit) throws NoWorkTreeException, CorruptObjectException, IOException { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java index 6cbb4a89b2..dd8573d2bc 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergerTest.java @@ -33,6 +33,7 @@ import org.eclipse.jgit.api.RebaseResult; import org.eclipse.jgit.api.errors.CheckoutConflictException; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.JGitInternalException; +import org.eclipse.jgit.diff.RawText; import org.eclipse.jgit.dircache.DirCache; import org.eclipse.jgit.dircache.DirCacheEditor; import org.eclipse.jgit.dircache.DirCacheEntry; @@ -826,6 +827,8 @@ public class MergerTest extends RepositoryTestCase { RevCommit sideCommit = git.commit().setAll(true) .setMessage("modified file l 1500").call(); + int originalBufferSize = RawText.getBufferSize(); + int smallBufferSize = RawText.setBufferSize(8000); try (ObjectInserter ins = db.newObjectInserter()) { // Check that we don't read the large blobs. ObjectInserter forbidInserter = new ObjectInserter.Filter() { @@ -836,7 +839,8 @@ public class MergerTest extends RepositoryTestCase { @Override public ObjectReader newReader() { - return new BigReadForbiddenReader(super.newReader(), 8000); + return new BigReadForbiddenReader(super.newReader(), + smallBufferSize); } }; @@ -844,6 +848,8 @@ public class MergerTest extends RepositoryTestCase { (ResolveMerger) strategy.newMerger(forbidInserter, db.getConfig()); boolean noProblems = merger.merge(masterCommit, sideCommit); assertFalse(noProblems); + } finally { + RawText.setBufferSize(originalBufferSize); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java index 7f0bfefbe7..b964e97752 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileBasedConfigTest.java @@ -19,6 +19,7 @@ import static org.junit.Assert.assertFalse; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardOpenOption; @@ -276,7 +277,8 @@ public class FileBasedConfigTest { throws IOException { AtomicBoolean userConfigTimeRead = new AtomicBoolean(false); - Path userConfigFile = createFile(CONTENT1.getBytes(), "home"); + Path userConfigFile = createFile( + CONTENT1.getBytes(StandardCharsets.UTF_8), "home"); mockSystemReader.setUserGitConfig( new FileBasedConfig(userConfigFile.toFile(), FS.DETECTED) { @@ -289,7 +291,8 @@ public class FileBasedConfigTest { } }); - Path file = createFile(CONTENT2.getBytes(), "repo"); + Path file = createFile(CONTENT2.getBytes(StandardCharsets.UTF_8), + "repo"); FileBasedConfig fileBasedConfig = new FileBasedConfig(file.toFile(), FS.DETECTED); fileBasedConfig.save(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java index ffea980f11..d1e5446827 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java @@ -142,7 +142,7 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas rp.setAdvertiseRefsHook(new AdvertiseRefsHook() { @Override public void advertiseRefs(ReceivePack rp2) - throws ServiceMayNotContinueException { + throws IOException { rp.setAdvertisedRefs(rp.getRepository().getAllRefs(), null); new HidePrivateHook().advertiseRefs(rp); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java index 127711ff91..7131905850 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java @@ -34,7 +34,6 @@ import org.eclipse.jgit.errors.TransportException; import org.eclipse.jgit.internal.storage.dfs.DfsGarbageCollector; import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription; import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository; -import org.eclipse.jgit.internal.storage.file.PackLock; import org.eclipse.jgit.internal.storage.pack.CachedPack; import org.eclipse.jgit.internal.storage.pack.CachedPackUriProvider; import org.eclipse.jgit.junit.TestRepository; diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FSTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FSTest.java index 8de7ba6c1d..171d80c3da 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FSTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/FSTest.java @@ -19,7 +19,6 @@ import static org.junit.Assume.assumeTrue; import java.io.File; import java.io.IOException; -import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.InvalidPathException; import java.nio.file.Path; @@ -182,7 +181,7 @@ public class FSTest { FS.readPipe(fs.userHome(), new String[] { "/bin/sh", "-c", "exit 1" }, - Charset.defaultCharset().name()); + SystemReader.getInstance().getDefaultCharset().name()); } @Test(expected = CommandFailedException.class) @@ -192,7 +191,7 @@ public class FSTest { FS.readPipe(fs.userHome(), new String[] { "this-command-does-not-exist" }, - Charset.defaultCharset().name()); + SystemReader.getInstance().getDefaultCharset().name()); } @Test diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/StringUtilsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/StringUtilsTest.java index 82c0afec5f..aa7247e105 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/StringUtilsTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/StringUtilsTest.java @@ -12,6 +12,7 @@ package org.eclipse.jgit.util; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import org.junit.Test; @@ -70,4 +71,86 @@ public class StringUtilsTest { assertEquals("a b c d", StringUtils.replaceLineBreaksWithSpace("a\r\nb\nc d")); } + + @Test + public void testFormatWithSuffix() { + assertEquals("1023", StringUtils.formatWithSuffix(1023)); + assertEquals("1k", StringUtils.formatWithSuffix(1024)); + assertEquals("1025", StringUtils.formatWithSuffix(1025)); + assertEquals("1048575", StringUtils.formatWithSuffix(1024 * 1024 - 1)); + assertEquals("1m", StringUtils.formatWithSuffix(1024 * 1024)); + assertEquals("1048577", StringUtils.formatWithSuffix(1024 * 1024 + 1)); + assertEquals("1073741823", + StringUtils.formatWithSuffix(1024 * 1024 * 1024 - 1)); + assertEquals("1g", StringUtils.formatWithSuffix(1024 * 1024 * 1024)); + assertEquals("1073741825", + StringUtils.formatWithSuffix(1024 * 1024 * 1024 + 1)); + assertEquals("3k", StringUtils.formatWithSuffix(3 * 1024)); + assertEquals("3m", StringUtils.formatWithSuffix(3 * 1024 * 1024)); + assertEquals("2050k", + StringUtils.formatWithSuffix(2 * 1024 * 1024 + 2048)); + assertEquals("3g", + StringUtils.formatWithSuffix(3L * 1024 * 1024 * 1024)); + assertEquals("3000", StringUtils.formatWithSuffix(3000)); + assertEquals("3000000", StringUtils.formatWithSuffix(3_000_000)); + assertEquals("1953125k", StringUtils.formatWithSuffix(2_000_000_000)); + assertEquals("2000000010", StringUtils.formatWithSuffix(2_000_000_010)); + assertEquals("3000000000", + StringUtils.formatWithSuffix(3_000_000_000L)); + } + + @Test + public void testParseWithSuffix() { + assertEquals(1024, StringUtils.parseIntWithSuffix("1k", true)); + assertEquals(1024, StringUtils.parseIntWithSuffix("1 k", true)); + assertEquals(1024, StringUtils.parseIntWithSuffix("1 k", true)); + assertEquals(1024, StringUtils.parseIntWithSuffix(" \t1 k \n", true)); + assertEquals(1024, StringUtils.parseIntWithSuffix("1k", false)); + assertEquals(1024, StringUtils.parseIntWithSuffix("1K", false)); + assertEquals(1024 * 1024, StringUtils.parseIntWithSuffix("1m", false)); + assertEquals(1024 * 1024, StringUtils.parseIntWithSuffix("1M", false)); + assertEquals(-1024 * 1024, + StringUtils.parseIntWithSuffix("-1M", false)); + assertEquals(1_000_000, + StringUtils.parseIntWithSuffix(" 1000000\r\n", false)); + assertEquals(1024 * 1024 * 1024, + StringUtils.parseIntWithSuffix("1g", false)); + assertEquals(1024 * 1024 * 1024, + StringUtils.parseIntWithSuffix("1G", false)); + assertEquals(3L * 1024 * 1024 * 1024, + StringUtils.parseLongWithSuffix("3g", false)); + assertEquals(3L * 1024 * 1024 * 1024, + StringUtils.parseLongWithSuffix("3G", false)); + assertThrows(NumberFormatException.class, + () -> StringUtils.parseIntWithSuffix("2G", false)); + assertEquals(2L * 1024 * 1024 * 1024, + StringUtils.parseLongWithSuffix("2G", false)); + assertThrows(NumberFormatException.class, + () -> StringUtils.parseLongWithSuffix("-1m", true)); + assertThrows(NumberFormatException.class, + () -> StringUtils.parseLongWithSuffix("-1000", true)); + assertThrows(StringIndexOutOfBoundsException.class, + () -> StringUtils.parseLongWithSuffix("", false)); + assertThrows(StringIndexOutOfBoundsException.class, + () -> StringUtils.parseLongWithSuffix(" \t \n", false)); + assertThrows(StringIndexOutOfBoundsException.class, + () -> StringUtils.parseLongWithSuffix("k", false)); + assertThrows(StringIndexOutOfBoundsException.class, + () -> StringUtils.parseLongWithSuffix("m", false)); + assertThrows(StringIndexOutOfBoundsException.class, + () -> StringUtils.parseLongWithSuffix("g", false)); + assertThrows(NumberFormatException.class, + () -> StringUtils.parseLongWithSuffix("1T", false)); + assertThrows(NumberFormatException.class, + () -> StringUtils.parseLongWithSuffix("1t", false)); + assertThrows(NumberFormatException.class, + () -> StringUtils.parseLongWithSuffix("Nonumber", false)); + assertThrows(NumberFormatException.class, + () -> StringUtils.parseLongWithSuffix("0x001f", false)); + assertThrows(NumberFormatException.class, + () -> StringUtils.parseLongWithSuffix("beef", false)); + assertThrows(NumberFormatException.class, + () -> StringUtils.parseLongWithSuffix("8000000000000000000G", + false)); + } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java index ae8c7ec7a7..94429924b0 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFInputStreamTest.java @@ -17,6 +17,7 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import org.eclipse.jgit.diff.RawText; import org.junit.Assert; import org.junit.Test; @@ -29,16 +30,17 @@ public class AutoCRLFInputStreamTest { assertNoCrLf("\r\n", "\n"); assertNoCrLf("\r\n", "\r\n"); assertNoCrLf("\r\r", "\r\r"); - assertNoCrLf("\r\n\r", "\n\r"); + assertNoCrLf("\n\r", "\n\r"); // Lone CR assertNoCrLf("\r\n\r\r", "\r\n\r\r"); assertNoCrLf("\r\n\r\n", "\r\n\r\n"); - assertNoCrLf("\r\n\r\n\r", "\n\r\n\r"); + assertNoCrLf("\n\r\n\r", "\n\r\n\r"); // Lone CR assertNoCrLf("\0\n", "\0\n"); } @Test public void testBoundary() throws IOException { - for (int i = AutoCRLFInputStream.BUFFER_SIZE - 10; i < AutoCRLFInputStream.BUFFER_SIZE + 10; i++) { + int boundary = RawText.getBufferSize(); + for (int i = boundary - 10; i < boundary + 10; i++) { String s1 = Strings.repeat("a", i); assertNoCrLf(s1, s1); String s2 = Strings.repeat("\0", i); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java index 85ce5381f3..791727f734 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/AutoCRLFOutputStreamTest.java @@ -19,6 +19,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import org.eclipse.jgit.diff.RawText; import org.junit.Assert; import org.junit.Test; @@ -31,16 +32,17 @@ public class AutoCRLFOutputStreamTest { assertNoCrLf("\r\n", "\n"); assertNoCrLf("\r\n", "\r\n"); assertNoCrLf("\r\r", "\r\r"); - assertNoCrLf("\r\n\r", "\n\r"); + assertNoCrLf("\n\r", "\n\r"); // Lone CR assertNoCrLf("\r\n\r\r", "\r\n\r\r"); assertNoCrLf("\r\n\r\n", "\r\n\r\n"); - assertNoCrLf("\r\n\r\n\r", "\n\r\n\r"); + assertNoCrLf("\n\r\n\r", "\n\r\n\r"); assertNoCrLf("\0\n", "\0\n"); } @Test public void testBoundary() throws IOException { - for (int i = AutoCRLFOutputStream.BUFFER_SIZE - 10; i < AutoCRLFOutputStream.BUFFER_SIZE + 10; i++) { + int bufferSize = RawText.getBufferSize(); + for (int i = bufferSize - 10; i < bufferSize + 10; i++) { String s1 = Strings.repeat("a", i); assertNoCrLf(s1, s1); String s2 = Strings.repeat("\0", i); |