[GSoC RFC PATCH 4/5] repo-info: add field layout.bare

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add the field layout.bare to the repo-info command. The data
retrieved in this field is the same that currently is obtained by
running `git rev-parse --is-bare-repository`.

Mentored-by: Karthik Nayak <karthik.188@xxxxxxxxx>
Mentored-by Patrick Steinhardt <ps@xxxxxx>
Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@xxxxxxxxx>
---
 builtin/repo-info.c  | 35 ++++++++++++++++++++++++++++++++++-
 t/t1518-repo-info.sh | 12 ++++++++++--
 2 files changed, 44 insertions(+), 3 deletions(-)

diff --git a/builtin/repo-info.c b/builtin/repo-info.c
index a1c9d3942e..bc25a0809f 100644
--- a/builtin/repo-info.c
+++ b/builtin/repo-info.c
@@ -1,4 +1,7 @@
+#define USE_THE_REPOSITORY_VARIABLE
+
 #include "builtin.h"
+#include "environment.h"
 #include "hash.h"
 #include "json-writer.h"
 #include "parse-options.h"
@@ -10,17 +13,22 @@ enum output_format {
 };
 
 enum repo_info_category {
-	CATEGORY_REFERENCES = 1
+	CATEGORY_REFERENCES = 1,
+	CATEGORY_LAYOUT = 1 << 1
 };
 
 enum repo_info_references_field {
 	FIELD_REFERENCES_FORMAT = 1
 };
 
+enum repo_info_layout_field { FIELD_LAYOUT_BARE = 1
+};
+
 struct repo_info_field {
 	enum repo_info_category category;
 	union {
 		enum repo_info_references_field references;
+		enum repo_info_layout_field layout;
 	} field;
 };
 
@@ -33,6 +41,7 @@ struct repo_info {
 
 const char *default_fields[] = {
 	"references.format",
+	"layout.bare"
 };
 
 static void repo_info_init(struct repo_info *repo_info,
@@ -68,6 +77,10 @@ static void repo_info_init(struct repo_info *repo_info,
 			field->category = CATEGORY_REFERENCES;
 			field->field.references = FIELD_REFERENCES_FORMAT;
 		}
+		else if (!strcmp(arg, "layout.bare")) {
+			field->category = CATEGORY_LAYOUT;
+			field->field.layout = FIELD_LAYOUT_BARE;
+		}
 		else {
 			die("invalid field '%s'", arg);
 		}
@@ -92,6 +105,13 @@ static void repo_info_print_plaintext(struct repo_info *repo_info) {
 				break;
 			}
 			break;
+		case CATEGORY_LAYOUT:
+			switch (field->field.layout) {
+			case FIELD_LAYOUT_BARE:
+				puts(is_bare_repository() ? "true" : "false");
+				break;
+			}
+			break;
 		}
 	}
 }
@@ -102,6 +122,7 @@ static void repo_info_print_json(struct repo_info *repo_info)
 	int i;
 	unsigned int categories = 0;
 	unsigned int references_fields = 0;
+	unsigned int layout_fields = 0;
 	struct repository *repo = repo_info->repo;
 
 	for (i = 0; i < repo_info->n_fields; i++) {
@@ -111,6 +132,9 @@ static void repo_info_print_json(struct repo_info *repo_info)
 		case CATEGORY_REFERENCES:
 			references_fields |= field->field.references;
 			break;
+		case CATEGORY_LAYOUT:
+			layout_fields |= field->field.layout;
+			break;
 		}
 	}
 
@@ -127,6 +151,15 @@ static void repo_info_print_json(struct repo_info *repo_info)
 		}
 		jw_end(&jw);
 	}
+
+	if (categories & CATEGORY_LAYOUT) {
+		jw_object_inline_begin_object(&jw, "layout");
+		if (layout_fields & FIELD_LAYOUT_BARE) {
+			jw_object_bool(&jw, "bare",
+				       is_bare_repository());
+		}
+		jw_end(&jw);
+	}
 	jw_end(&jw);
 
 	puts(jw.json.buf);
diff --git a/t/t1518-repo-info.sh b/t/t1518-repo-info.sh
index a99198b0f6..1831b74551 100755
--- a/t/t1518-repo-info.sh
+++ b/t/t1518-repo-info.sh
@@ -6,7 +6,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
 . ./test-lib.sh
 
-DEFAULT_NUMBER_OF_FIELDS=1
+DEFAULT_NUMBER_OF_FIELDS=2
 
 parse_json () {
 	tr '\n' ' ' | "$PERL_PATH" "$TEST_DIRECTORY/t0019/parse_json.perl"
@@ -22,7 +22,7 @@ test_repo_info () {
 		test_when_finished 'rm -rf repo' &&
 		git init $init_args repo &&
 		cd repo &&
-		echo '$expected_value' >expect &&
+		echo '$expected_value' | sed 's/^false$/0/' | sed 's/^true$/1/' >expect &&
 		git repo-info '$key'| parse_json >output &&
 		grep -F 'row[0].$key' output | cut -d ' ' -f 2 >actual &&
 		test_cmp expect actual
@@ -56,6 +56,14 @@ test_repo_info 'ref format reftable is retrieved correctly' \
 	'--ref-format=reftable' \
 	'references.format' 'reftable'
 
+test_repo_info 'bare repository = false is retrieved correctly' \
+	'' \
+	'layout.bare' 'false'
+
+test_repo_info 'bare repository = true is retrieved correctly' \
+	'--bare' \
+	'layout.bare' 'true'
+
 test_expect_success 'plaintext: output all default fields' "
 	git repo-info --format=plaintext >actual &&
 	test_line_count = $DEFAULT_NUMBER_OF_FIELDS actual
-- 
2.39.5 (Apple Git-154)





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux