Skip to content

Commit

Permalink
use history_number in json output
Browse files Browse the repository at this point in the history
Signed-off-by: Nishant Bansal <[email protected]>
  • Loading branch information
NishantBansal2003 committed Feb 6, 2025
1 parent c5428ad commit cda87f2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion vector/v.info/local_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ void print_shell(struct Map_info *, const char *, enum OutputFormat,
JSON_Object *);
void parse_history_line(const char *, char *, char *, char *, char *, char *,
char *, char *);
void add_record_to_json(char *, char *, char *, char *, JSON_Array *);
void add_record_to_json(char *, char *, char *, char *, JSON_Array *, int);
void print_history(struct Map_info *, enum OutputFormat);
11 changes: 9 additions & 2 deletions vector/v.info/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,8 @@ void parse_history_line(const char *buf, char *command, char *gisdbase,
*/
void add_record_to_json(char *command, char *user, char *date,
char *mapset_path, JSON_Array *record_array)
char *mapset_path, JSON_Array *record_array,
int history_number)
{

JSON_Value *info_value = json_value_init_object();
Expand All @@ -819,6 +820,7 @@ void add_record_to_json(char *command, char *user, char *date,
}
JSON_Object *info_object = json_object(info_value);

json_object_set_number(info_object, "history_number", history_number);
json_object_set_string(info_object, "command", command);
json_object_set_string(info_object, "mapset_path", mapset_path);
json_object_set_string(info_object, "user", user);
Expand All @@ -834,6 +836,8 @@ void add_record_to_json(char *command, char *user, char *date,
*/
void print_history(struct Map_info *Map, enum OutputFormat format)
{
int history_number = 0;

char buf[STR_LEN] = {0};
char command[STR_LEN] = {0}, gisdbase[STR_LEN] = {0};
char location[STR_LEN] = {0}, mapset[STR_LEN] = {0};
Expand Down Expand Up @@ -872,8 +876,11 @@ void print_history(struct Map_info *Map, enum OutputFormat format)
date, mapset_path);
if (command[0] != '\0' && mapset_path[0] != '\0' &&
user[0] != '\0' && date[0] != '\0') {
// Increment history counter
history_number++;

add_record_to_json(command, user, date, mapset_path,
record_array);
record_array, history_number);
}
break;
}
Expand Down
2 changes: 2 additions & 0 deletions vector/v.info/testsuite/test_vinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,11 @@ def test_json_histroy(self):
expected_json = {
"records": [
{
"history_number": 1,
"command": 'v.random output="test_vinfo_with_hist" npoints=5 layer="-1" zmin=0 zmax=100 column_type="double precision"',
},
{
"history_number": 2,
"command": 'v.mkgrid map="test_vinfo_with_hist" grid=10,10 type="point"',
},
]
Expand Down

0 comments on commit cda87f2

Please sign in to comment.