patch 8.0.1514: getting the list of changes is not easy

Problem:    Getting the list of changes is not easy.
Solution:   Add the getchangelist() function. (Yegappan Lakshmanan,
            closes #2634)
diff --git a/src/Makefile b/src/Makefile
index 7cd501e..f814c83 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -2127,6 +2127,7 @@
 	test_cd \
 	test_cdo \
 	test_changedtick \
+	test_changelist \
 	test_channel \
 	test_charsearch \
 	test_charsearch_utf8 \
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 7ea106b..daef9a8 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -165,6 +165,7 @@
 static void f_getbufinfo(typval_T *argvars, typval_T *rettv);
 static void f_getbufline(typval_T *argvars, typval_T *rettv);
 static void f_getbufvar(typval_T *argvars, typval_T *rettv);
+static void f_getchangelist(typval_T *argvars, typval_T *rettv);
 static void f_getchar(typval_T *argvars, typval_T *rettv);
 static void f_getcharmod(typval_T *argvars, typval_T *rettv);
 static void f_getcharsearch(typval_T *argvars, typval_T *rettv);
@@ -607,6 +608,7 @@
     {"getbufinfo",	0, 1, f_getbufinfo},
     {"getbufline",	2, 3, f_getbufline},
     {"getbufvar",	2, 3, f_getbufvar},
+    {"getchangelist",	1, 1, f_getchangelist},
     {"getchar",		0, 1, f_getchar},
     {"getcharmod",	0, 0, f_getcharmod},
     {"getcharsearch",	0, 0, f_getcharsearch},
@@ -4347,6 +4349,58 @@
 }
 
 /*
+ * "getchangelist()" function
+ */
+    static void
+f_getchangelist(typval_T *argvars, typval_T *rettv)
+{
+#ifdef FEAT_JUMPLIST
+    buf_T	*buf;
+    int		i;
+    list_T	*l;
+    dict_T	*d;
+#endif
+
+    if (rettv_list_alloc(rettv) != OK)
+	return;
+
+#ifdef FEAT_JUMPLIST
+    buf = find_buffer(&argvars[0]);
+    if (buf == NULL)
+	return;
+
+    l = list_alloc();
+    if (l == NULL)
+	return;
+
+    if (list_append_list(rettv->vval.v_list, l) == FAIL)
+	return;
+    /*
+     * The current window change list index tracks only the position in the
+     * current buffer change list. For other buffers, use the change list
+     * length as the current index.
+     */
+    list_append_number(rettv->vval.v_list,
+	    (varnumber_T)((buf == curwin->w_buffer)
+		? curwin->w_changelistidx : buf->b_changelistlen));
+
+    for (i = 0; i < buf->b_changelistlen; ++i)
+    {
+	if (buf->b_changelist[i].lnum == 0)
+	    continue;
+	if ((d = dict_alloc()) == NULL)
+	    return;
+	if (list_append_dict(l, d) == FAIL)
+	    return;
+	dict_add_nr_str(d, "lnum", (long)buf->b_changelist[i].lnum, NULL);
+	dict_add_nr_str(d, "col", (long)buf->b_changelist[i].col, NULL);
+# ifdef FEAT_VIRTUALEDIT
+	dict_add_nr_str(d, "coladd", (long)buf->b_changelist[i].coladd, NULL);
+# endif
+    }
+#endif
+}
+/*
  * "getchar()" function
  */
     static void
diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak
index 2d98fa6..e3230c5 100644
--- a/src/testdir/Make_all.mak
+++ b/src/testdir/Make_all.mak
@@ -75,6 +75,7 @@
 	    test_breakindent.res \
 	    test_bufwintabinfo.res \
 	    test_cdo.res \
+	    test_changelist.res \
 	    test_channel.res \
 	    test_charsearch.res \
 	    test_cindent.res \
diff --git a/src/testdir/test_changelist.vim b/src/testdir/test_changelist.vim
new file mode 100644
index 0000000..0880fce
--- /dev/null
+++ b/src/testdir/test_changelist.vim
@@ -0,0 +1,48 @@
+" Tests for the changelist functionality
+
+" Tests for the getchangelist() function
+func Test_getchangelist()
+  if !has("jumplist")
+    return
+  endif
+
+  bwipe!
+  enew
+  call assert_equal([], getchangelist(10))
+  call assert_equal([[], 0], getchangelist(bufnr('%')))
+
+  call writefile(['line1', 'line2', 'line3'], 'Xfile1.txt')
+  call writefile(['line1', 'line2', 'line3'], 'Xfile2.txt')
+
+  edit Xfile1.txt
+  exe "normal 1Goline\<C-G>u1.1"
+  exe "normal 3Goline\<C-G>u2.1"
+  exe "normal 5Goline\<C-G>u3.1"
+  normal g;
+  call assert_equal([[
+	      \ {'lnum' : 2, 'col' : 4, 'coladd' : 0},
+	      \ {'lnum' : 4, 'col' : 4, 'coladd' : 0},
+	      \ {'lnum' : 6, 'col' : 4, 'coladd' : 0}], 2],
+	      \ getchangelist(bufnr('%')))
+
+  hide edit Xfile2.txt
+  exe "normal 1GOline\<C-G>u1.0"
+  exe "normal 2Goline\<C-G>u2.0"
+  call assert_equal([[
+	      \ {'lnum' : 1, 'col' : 6, 'coladd' : 0},
+	      \ {'lnum' : 3, 'col' : 6, 'coladd' : 0}], 2],
+	      \ getchangelist(bufnr('%')))
+  hide enew
+
+  call assert_equal([[
+	      \ {'lnum' : 2, 'col' : 4, 'coladd' : 0},
+	      \ {'lnum' : 4, 'col' : 4, 'coladd' : 0},
+	      \ {'lnum' : 6, 'col' : 4, 'coladd' : 0}], 3], getchangelist(2))
+  call assert_equal([[
+	      \ {'lnum' : 1, 'col' : 6, 'coladd' : 0},
+	      \ {'lnum' : 3, 'col' : 6, 'coladd' : 0}], 2], getchangelist(3))
+
+  bwipe!
+  call delete('Xfile1.txt')
+  call delete('Xfile2.txt')
+endfunc
diff --git a/src/version.c b/src/version.c
index e4f6f96..adedd85 100644
--- a/src/version.c
+++ b/src/version.c
@@ -772,6 +772,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1514,
+/**/
     1513,
 /**/
     1512,