docs: add doc comment to cmd_gitlog()
Add detailed function documentation for cmd_gitlog() matching the existing style used throughout zynk.c. Describes the fork/exec pattern for running git log, output handling, rate limiting, and clamping behavior for the count argument. Updated CHANGELOG.md 0.36.0 entry to reflect this addition.
This commit is contained in:
parent
01a51c17e5
commit
b17e1ae1c2
2 changed files with 24 additions and 1 deletions
24
zynk.c
24
zynk.c
|
|
@ -53,6 +53,7 @@ enum {
|
|||
RATE_LIMIT_MAX = 8,
|
||||
MAX_HISTORY = 100,
|
||||
GITLOG_COUNT = 5,
|
||||
GITLOG_MAX = 20,
|
||||
};
|
||||
|
||||
/* ---- IRC session ---- */
|
||||
|
|
@ -3009,6 +3010,27 @@ static int cmd_tell(Session *s, const char *msg, const char *reply_target, const
|
|||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* cmd_gitlog - Handle the "!gitlog [count]" command.
|
||||
*
|
||||
* Displays recent git commits of the zynk project by forking a child
|
||||
* process that runs "git log --oneline -n <count>". Each commit line
|
||||
* is sent as a separate IRC PRIVMSG to the reply target. The commit
|
||||
* count defaults to GITLOG_COUNT (5) when no argument is provided,
|
||||
* and is clamped to GITLOG_MAX (20) if the user requests more.
|
||||
* Rate-limited per-nick. If git is not installed or the working
|
||||
* directory is not a git repository, an appropriate error message is
|
||||
* sent. If no commits exist (e.g. fresh repo), reports that no commits
|
||||
* were found.
|
||||
*
|
||||
* Parameters:
|
||||
* s - The IRC session.
|
||||
* msg - The raw IRC message text.
|
||||
* reply_target - Channel or nick to send the response to.
|
||||
* src_nick - The IRC nick of the user who issued the command.
|
||||
*
|
||||
* Returns: 1 if the command was matched, 0 otherwise.
|
||||
*/
|
||||
static int cmd_gitlog(Session *s, const char *msg, const char *reply_target, const char *src_nick) {
|
||||
if (strncmp(msg, "!gitlog", 7) != 0) return 0;
|
||||
if (msg[7] != ' ' && msg[7] != '\0') return 0;
|
||||
|
|
@ -3019,7 +3041,7 @@ static int cmd_gitlog(Session *s, const char *msg, const char *reply_target, con
|
|||
if (*rest) {
|
||||
count = atoi(rest);
|
||||
if (count <= 0) count = GITLOG_COUNT;
|
||||
if (count > 20) count = 20;
|
||||
if (count > GITLOG_MAX) count = GITLOG_MAX;
|
||||
}
|
||||
int out_pipe[2];
|
||||
if (pipe(out_pipe) < 0) { irc_msg(s, reply_target, "gitlog: internal error"); return 1; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue