GitLabgitlab-org

cli

main
ply8 git calls212 ms98 KiB5 cachedprotocol v2
169 lines4.8 KiBexecutableRaw
1#!/bin/sh
2#
3# Copyright (c) 2006, 2008 Junio C Hamano
4#
5# The "pre-rebase" hook is run just before "git rebase" starts doing
6# its job, and can prevent the command from running by exiting with
7# non-zero status.
8#
9# The hook is called with the following parameters:
11# $1 -- the upstream the series was forked from.
12# $2 -- the branch being rebased (or empty when rebasing the current branch).
14# This sample shows how to prevent topic branches that are already
15# merged to 'next' branch from getting rebased, because allowing it
16# would result in rebasing already published history.
18publish=next
19basebranch="$1"
20if test "$#" = 2
21then
22 topic="refs/heads/$2"
23else
24 topic=`git symbolic-ref HEAD` ||
25 exit 0 ;# we do not interrupt rebasing detached HEAD
26fi
28case "$topic" in
29refs/heads/??/*)
30 ;;
31*)
32 exit 0 ;# we do not interrupt others.
33 ;;
34esac
36# Now we are dealing with a topic branch being rebased
37# on top of master. Is it OK to rebase it?
39# Does the topic really exist?
40git show-ref -q "$topic" || {
41 echo >&2 "No such branch $topic"
42 exit 1
45# Is topic fully merged to master?
46not_in_master=`git rev-list --pretty=oneline ^master "$topic"`
47if test -z "$not_in_master"
48then
49 echo >&2 "$topic is fully merged to master; better remove it."
50 exit 1 ;# we could allow it, but there is no point.
51fi
53# Is topic ever merged to next? If so you should not be rebasing it.
54only_next_1=`git rev-list ^master "^$topic" ${publish} | sort`
55only_next_2=`git rev-list ^master ${publish} | sort`
56if test "$only_next_1" = "$only_next_2"
57then
58 not_in_topic=`git rev-list "^$topic" master`
59 if test -z "$not_in_topic"
60 then
61 echo >&2 "$topic is already up to date with master"
62 exit 1 ;# we could allow it, but there is no point.
63 else
64 exit 0
65 fi
66else
67 not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"`
68 /usr/bin/perl -e '
69 my $topic = $ARGV[0];
70 my $msg = "* $topic has commits already merged to public branch:\n";
71 my (%not_in_next) = map {
72 /^([0-9a-f]+) /;
73 ($1 => 1);
74 } split(/\n/, $ARGV[1]);
75 for my $elem (map {
76 /^([0-9a-f]+) (.*)$/;
77 [$1 => $2];
78 } split(/\n/, $ARGV[2])) {
79 if (!exists $not_in_next{$elem->[0]}) {
80 if ($msg) {
81 print STDERR $msg;
82 undef $msg;
83 }
84 print STDERR " $elem->[1]\n";
85 }
86 }
87 ' "$topic" "$not_in_next" "$not_in_master"
88 exit 1
89fi
91<<\DOC_END
93This sample hook safeguards topic branches that have been
94published from being rewound.
96The workflow assumed here is:
98 * Once a topic branch forks from "master", "master" is never
99 merged into it again (either directly or indirectly).
101 * Once a topic branch is fully cooked and merged into "master",
102 it is deleted. If you need to build on top of it to correct
103 earlier mistakes, a new topic branch is created by forking at
104 the tip of the "master". This is not strictly necessary, but
105 it makes it easier to keep your history simple.
107 * Whenever you need to test or publish your changes to topic
108 branches, merge them into "next" branch.
110The script, being an example, hardcodes the publish branch name
111to be "next", but it is trivial to make it configurable via
112$GIT_DIR/config mechanism.
114With this workflow, you would want to know:
116(1) ... if a topic branch has ever been merged to "next". Young
117 topic branches can have stupid mistakes you would rather
118 clean up before publishing, and things that have not been
119 merged into other branches can be easily rebased without
120 affecting other people. But once it is published, you would
121 not want to rewind it.
123(2) ... if a topic branch has been fully merged to "master".
124 Then you can delete it. More importantly, you should not
125 build on top of it -- other people may already want to
126 change things related to the topic as patches against your
127 "master", so if you need further changes, it is better to
128 fork the topic (perhaps with the same name) afresh from the
129 tip of "master".
131Let's look at this example:
133 o---o---o---o---o---o---o---o---o---o "next"
134 / / / /
135 / a---a---b A / /
136 / / / /
137 / / c---c---c---c B /
138 / / / \ /
139 / / / b---b C \ /
140 / / / / \ /
141 ---o---o---o---o---o---o---o---o---o---o---o "master"
144A, B and C are topic branches.
146 * A has one fix since it was merged up to "next".
148 * B has finished. It has been fully merged up to "master" and "next",
149 and is ready to be deleted.
151 * C has not merged to "next" at all.
153We would want to allow C to be rebased, refuse A, and encourage
154B to be deleted.
156To compute (1):
158 git rev-list ^master ^topic next
159 git rev-list ^master next
161 if these match, topic has not merged in next at all.
163To compute (2):
165 git rev-list master..topic
167 if this is empty, it is fully merged to "master".
169DOC_END
Diagnostics8 git calls · 212 ms
CallStatusSizeTime0212 ms
discover200185 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=185
git.server.agent=git/2.56.g1891de4-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=185
git.pkt.payload.max=35
ls-refs20058 KiB3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=59849
git.response.cache=UPDATING
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=731
git.pkt.data=730
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=59849
git.pkt.payload.max=143
git.ls_refs.count=730
git.ls_refs.head=refs/heads/main
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=combine:blob:none+tree:2
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=1
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4273
git.pkt.payload.max=4173
git.sideband.band1.bytes=4173
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=11
git.pack.bytes=4173
git.fetch.wide.objects=11
git.fetch.wide.extra_bytes=3930
git.fetch.wide.blobs=0
fetchtree:0 · deepen 1020032 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=22
git.pkt.data=20
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=32926
git.pkt.payload.max=32046
git.sideband.band1.bytes=32046
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=80
git.pack.bytes=32046
git.pack.ofs_delta=36
git.pack.ref_delta=0
git.pack.chain.max=2
git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91
git.pack.full=44
Open pack map
fetchtree:0200269 B · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=269
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=03418b1543b5ed53722e5f33e3b74e146f53f68d
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=269
git.pkt.payload.max=242
git.sideband.band1.bytes=242
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=242
git.pack.trailer=026c020e1be62d2b2c6d8f3a03f3525b7a86efd1
Open pack map
fetchtree:0200474 B · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=474
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=7c3f97bfb728c74316598d2bbce58b3fb8dd3080
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=474
git.pkt.payload.max=447
git.sideband.band1.bytes=447
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=447
git.pack.trailer=8479fc10eb7e3b4ab926685ee5a551ec5eb00e71
Open pack map
fetchtree:0200459 B · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=199
git.response.bytes=459
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
git.fetch.wants=2f6bc382bc7a73c9331b843ccc187e6ce8618d73
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=459
git.pkt.payload.max=432
git.sideband.band1.bytes=432
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=432
git.pack.trailer=fc2e9690b01682f106088547b32fb83e09704b92
Open pack map
fetch2002.0 KiB199 ms
git.upload-pack fetch
http.response.status_code=200
git.response.bytes=2083
git.response.cache=MISS
git.response.duration_ms=199
git.fetch.wants=6cbef5c370d8c3486ca85423dd70440c5e0a2aa2
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=2083
git.pkt.payload.max=2056
git.sideband.band1.bytes=2056
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://gitlab.com/gitlab-org/cli
Ref
refs/heads/main
Commit
0dd7574dce9e385c5c30540e6c15657adc6bdce9
cf-ray
a5e18dbf6f4d5e37
Request
9c66452d…
Protocol
v2 · sha1
Agent
git/2.56.g1891de4-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format