Monitoring commits on all branches

Mathieu Arnold mat at freebsd.org
Tue Nov 24 16:33:24 UTC 2020


On Thu, Nov 19, 2020 at 12:45:14PM -0500, Dan Langille wrote:
> > On Nov 19, 2020, at 3:52 AM, Mathieu Arnold <mat at FreeBSD.org> wrote:
> > 
> > On Wed, Nov 18, 2020 at 08:49:46PM -0500, Dan Langille wrote:
> >> How can a repo be monitored for commits on all branches?
> >> 
> >> I know how to ask a given branch: do you have any commits after foo_hash?
> >> 
> >> How do I:
> >> 
> >> * get a list of all commits since foo_hash
> > 
> > All commits on the branch foo_hash is:
> > 
> > git log $foo_hash...branch_name
> 
> So, branch_name, not HEAD as others have mentioned?
> 
> e.g. : git log $foo_hash..HEAD

From what I understood, freshports never needs to be able to access
files on the top of a branch, it only needs to access the files on
specific commits (the fact that a commit is at the top of the branch is
only an artefact of the process). So, you never need to checkout any
branches, you only need to checkout commits.  So you never have a HEAD
that points to a branch, HEAD is always in a detached state and points
to a commit.

So what you need to do is, git clone the repository, and then, each time
the script runs, do (in somewhat shell script):

#############################
NAME_OF_REMOTE=origin
NAME_OF_HEAD=main

cd /where/the/repo/is

git fetch

# get all references (so, branches, tags, and so one) and keep only
# branches (named commits here) that the remote repository has

git for-each-ref --format '%(objecttype) %(refname)' \
  | sed -n 's/^commit refs\/remotes\///p'
  | while read -r type refname
do

  # If we don't have the tag, it means we have not encountered the
  # branch yet.
  if ! git tag -l freshports/$refname
  then

    # get the first commit of that branch and create a tag.
    git tag -m "first known commit of $refname" -f freshports/$refname $(git merge-base $NAME_OF_REMOTE/$NAME_OF_HEAD $refname)
  fi

  # Get the list of commits between the last known one and the tip of
  # the branch, list may be empty.
  git rev-list freshports/$refname..$refname | while read commithash
  do
    # checkout that commit (with -f so that if some file got changed, we
    # overwrite everything
    git checkout -f $commithash

    # process the commit
  done

  # Store the last known commit that we just processed.
  git tag -m "last known commit of $refname" -f freshports/$refname $refname
done
#############################

That's all, you never need to merge or pull or whatever else.

> > 
> >> * know which branch each of those commits was on (e.g. master, branches/2020Q4)
> > 
> > You will need to keep track of the latest commit on each branch
> > separately, because there is absolutely no relation or ordering
> > possible between branches.
> 
> Yes, I agree. FreshPorts is keeping track of the last commit on each branch.
> 
> Thank you.

-- 
Mathieu Arnold
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 963 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-git/attachments/20201124/7064ac28/attachment.sig>


More information about the freebsd-git mailing list