Skip to content

Commit cda87f2

Browse files
use history_number in json output
Signed-off-by: Nishant Bansal <[email protected]>
1 parent c5428ad commit cda87f2

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

vector/v.info/local_proto.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ void print_shell(struct Map_info *, const char *, enum OutputFormat,
2727
JSON_Object *);
2828
void parse_history_line(const char *, char *, char *, char *, char *, char *,
2929
char *, char *);
30-
void add_record_to_json(char *, char *, char *, char *, JSON_Array *);
30+
void add_record_to_json(char *, char *, char *, char *, JSON_Array *, int);
3131
void print_history(struct Map_info *, enum OutputFormat);

vector/v.info/print.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,8 @@ void parse_history_line(const char *buf, char *command, char *gisdbase,
810810
811811
*/
812812
void add_record_to_json(char *command, char *user, char *date,
813-
char *mapset_path, JSON_Array *record_array)
813+
char *mapset_path, JSON_Array *record_array,
814+
int history_number)
814815
{
815816

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

823+
json_object_set_number(info_object, "history_number", history_number);
822824
json_object_set_string(info_object, "command", command);
823825
json_object_set_string(info_object, "mapset_path", mapset_path);
824826
json_object_set_string(info_object, "user", user);
@@ -834,6 +836,8 @@ void add_record_to_json(char *command, char *user, char *date,
834836
*/
835837
void print_history(struct Map_info *Map, enum OutputFormat format)
836838
{
839+
int history_number = 0;
840+
837841
char buf[STR_LEN] = {0};
838842
char command[STR_LEN] = {0}, gisdbase[STR_LEN] = {0};
839843
char location[STR_LEN] = {0}, mapset[STR_LEN] = {0};
@@ -872,8 +876,11 @@ void print_history(struct Map_info *Map, enum OutputFormat format)
872876
date, mapset_path);
873877
if (command[0] != '\0' && mapset_path[0] != '\0' &&
874878
user[0] != '\0' && date[0] != '\0') {
879+
// Increment history counter
880+
history_number++;
881+
875882
add_record_to_json(command, user, date, mapset_path,
876-
record_array);
883+
record_array, history_number);
877884
}
878885
break;
879886
}

vector/v.info/testsuite/test_vinfo.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,11 @@ def test_json_histroy(self):
295295
expected_json = {
296296
"records": [
297297
{
298+
"history_number": 1,
298299
"command": 'v.random output="test_vinfo_with_hist" npoints=5 layer="-1" zmin=0 zmax=100 column_type="double precision"',
299300
},
300301
{
302+
"history_number": 2,
301303
"command": 'v.mkgrid map="test_vinfo_with_hist" grid=10,10 type="point"',
302304
},
303305
]

0 commit comments

Comments
 (0)