shithub: front

Download patch

ref: b95ec908375919c15d5c3e10b3c08dda1a501235
parent: 6d53af9408f199aea5c2440cb23f2467359d0c25
author: Jacob Moody <moody@posixcafe.org>
date: Tue Aug 5 06:59:31 EDT 2025

git: cleanup git/hist

* -n flag for limiting commit output
* fix usage when not in gitroot
* diff delimiters
* document in man page

--- a/sys/man/1/git
+++ b/sys/man/1/git
@@ -2,7 +2,7 @@
 .SH NAME
 git, git/conf, git/query, git/walk, git/clone, git/branch,
 git/commit, git/diff, git/init, git/log, git/merge, git/push,
-git/pull, git/rm, git/serve \- manage git repositories
+git/pull, git/rm, git/serve, git/hist \- manage git repositories
 .SH SYNOPSIS
 .B git/add
 [
@@ -186,6 +186,13 @@
 [
 .I file ...
 ]
+.PP
+.B git/hist
+[
+.B -n
+.I count
+]
+.I files...
 .SH DESCRIPTION
 Git is a distributed version control system.
 This means that each repository contains a full copy of the history.
@@ -561,6 +568,16 @@
 commands to run tools like
 .I go get
 but not much more.
+.PP
+.I Git/hist
+provides the diffs of specific
+.I files
+in reverse chronological order.
+The
+.B -n
+flag may be used to limit the output to the last
+.I count
+commits.
 .SH REF SYNTAX
 Refs are specified with a simple query syntax.
 A bare hash always evaluates to itself.
--- a/sys/src/cmd/git/hist
+++ b/sys/src/cmd/git/hist
@@ -4,6 +4,10 @@
 . /sys/lib/git/common.rc
 gitup
 
+flagfmt='n:num count'; args='files...'
+eval `''{aux/getflags $*} || exec aux/usage
+if(~ $#* 0) exec aux/usage
+
 fn dodiff {
 	while(t=`{read}){
 		h=$t(1)
@@ -23,12 +27,14 @@
 				prev=/dev/null
 			diff -u $prev $curr
 		}
+		echo --' '
+		echo ⑨
 		echo
 	}
 }
 
-if(~ $#* 0)
-	die usage: $0 files...
-
-files=`{cleanname $gitrel/$*}
-git/log -s $files | dodiff
+files=`{cleanname $*}
+args=(-s $files)
+if(! ~ $#num 0)
+	args=(-n $num $args)
+git/log $args | dodiff
--