summaryrefslogtreecommitdiff
path: root/line-range.h
diff options
context:
space:
mode:
authorBo Yang <struggleyb.nku@gmail.com>2013-03-28 16:47:30 (GMT)
committerJunio C Hamano <gitster@pobox.com>2013-03-28 17:28:41 (GMT)
commit25ed3412f86b136efb17689b6712d9e546cac388 (patch)
treefdb5d94dcd935ce30be00a616ff1619752421179 /line-range.h
parent443d803e0dacd0a1c6700503689f3cd95751aba1 (diff)
downloadgit-25ed3412f86b136efb17689b6712d9e546cac388.zip
git-25ed3412f86b136efb17689b6712d9e546cac388.tar.gz
git-25ed3412f86b136efb17689b6712d9e546cac388.tar.bz2
Refactor parse_loc
We want to use the same style of -L n,m argument for 'git log -L' as for git-blame. Refactor the argument parsing of the range arguments from builtin/blame.c to the (new) file that will hold the 'git log -L' logic. To accommodate different data structures in blame and log -L, the file contents are abstracted away; parse_range_arg takes a callback that it uses to get the contents of a line of the (notional) file. The new test is for a case that made me pause during debugging: the 'blame -L with invalid end' test was the only one that noticed an outright failure to parse the end *at all*. So make a more explicit test for that. Signed-off-by: Bo Yang <struggleyb.nku@gmail.com> Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'line-range.h')
-rw-r--r--line-range.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/line-range.h b/line-range.h
new file mode 100644
index 0000000..830f25b
--- /dev/null
+++ b/line-range.h
@@ -0,0 +1,24 @@
+#ifndef LINE_RANGE_H
+#define LINE_RANGE_H
+
+/*
+ * Parse one item in an -L begin,end option w.r.t. the notional file
+ * object 'cb_data' consisting of 'lines' lines.
+ *
+ * The 'nth_line_cb' callback is used to determine the start of the
+ * line 'lno' inside the 'cb_data'. The caller is expected to already
+ * have a suitable map at hand to make this a constant-time lookup.
+ *
+ * Returns 0 in case of success and -1 if there was an error. The
+ * actual range is stored in *begin and *end. The counting starts
+ * at 1! In case of error, the caller should show usage message.
+ */
+
+typedef const char *(*nth_line_fn_t)(void *data, long lno);
+
+extern int parse_range_arg(const char *arg,
+ nth_line_fn_t nth_line_cb,
+ void *cb_data, long lines,
+ long *begin, long *end);
+
+#endif /* LINE_RANGE_H */