Merge branch 'stable'

* stable:
  Automatically install Gerrit Code Review's commit-msg hook
  Fail sync when encountering "N commits behind."
  Check that we are not overwriting a local repository when syncing.
  Honor url.insteadOf when setting up SSH control master connection
  sync: Fix split call on malformed email addresses
  Fixing project renaming bug.

Conflicts:
	hooks/commit-msg
	project.py
	subcmds/sync.py

Change-Id: I5eaf8fef8cbe4a95d124368112293a9ca64325bf
This commit is contained in:
Shawn O. Pearce 2010-03-06 19:29:56 -08:00
commit 69b1e8aa65
4 changed files with 83 additions and 30 deletions

View File

@ -461,8 +461,30 @@ class Remote(object):
self._Get('fetch', all=True)) self._Get('fetch', all=True))
self._review_protocol = None self._review_protocol = None
def _InsteadOf(self):
globCfg = GitConfig.ForUser()
urlList = globCfg.GetSubSections('url')
longest = ""
longestUrl = ""
for url in urlList:
key = "url." + url + ".insteadOf"
insteadOfList = globCfg.GetString(key, all=True)
for insteadOf in insteadOfList:
if self.url.startswith(insteadOf) \
and len(insteadOf) > len(longest):
longest = insteadOf
longestUrl = url
if len(longest) == 0:
return self.url
return self.url.replace(longest, longestUrl, 1)
def PreConnectFetch(self): def PreConnectFetch(self):
return _preconnect(self.url) connectionUrl = self._InsteadOf()
return _preconnect(connectionUrl)
@property @property
def ReviewProtocol(self): def ReviewProtocol(self):

View File

@ -1,5 +1,5 @@
#!/bin/sh #!/bin/sh
# From Gerrit Code Review v2.0.19.1-4-g21d307b # From Gerrit Code Review 2.1.2-rc2-33-g7e30c72
# #
# Part of Gerrit Code Review (http://code.google.com/p/gerrit/) # Part of Gerrit Code Review (http://code.google.com/p/gerrit/)
# #
@ -18,6 +18,7 @@
# limitations under the License. # limitations under the License.
# #
CHANGE_ID_AFTER="Bug|Issue"
MSG="$1" MSG="$1"
# Check for, and add if missing, a unique Change-Id # Check for, and add if missing, a unique Change-Id
@ -42,22 +43,43 @@ add_ChangeId() {
fi fi
id=$(_gen_ChangeId) id=$(_gen_ChangeId)
out="$MSG.OUT" perl -e '
ftt="$MSG.FTT" $MSG = shift;
sed -e '2,${ $id = shift;
/^[A-Za-z][A-Za-z0-9-]*: /,$d $CHANGE_ID_AFTER = shift;
}' <"$MSG" >"$out"
sed -ne '2,${ undef $/;
/^[A-Za-z][A-Za-z0-9-]*: /,$p open(I, $MSG); $_ = <I>; close I;
}' <"$MSG" >"$ftt" s|^diff --git a/.*||ms;
if ! test -s "$ftt" s|^#.*$||mg;
then exit unless $_;
echo >>"$out"
fi @message = split /\n/;
echo "Change-Id: I$id" >>"$out" $haveFooter = 0;
cat "$ftt" >>"$out" $startFooter = @message;
mv -f "$out" "$MSG" for($line = @message - 1; $line >= 0; $line--) {
rm -f "$out" "$ftt" $_ = $message[$line];
($haveFooter++, next) if /^[a-zA-Z0-9-]+:/;
next if /^[ []/;
$startFooter = $line if ($haveFooter && /^\r?$/);
last;
}
@footer = @message[$startFooter+1..@message];
@message = @message[0..$startFooter];
push(@footer, "") unless @footer;
for ($line = 0; $line < @footer; $line++) {
$_ = $footer[$line];
next if /^($CHANGE_ID_AFTER):/i;
last;
}
splice(@footer, $line, 0, "Change-Id: I$id");
$_ = join("\n", @message, @footer);
open(O, ">$MSG"); print O; close O;
' "$MSG" "$id" "$CHANGE_ID_AFTER"
} }
_gen_ChangeIdInput() { _gen_ChangeIdInput() {
echo "tree $(git write-tree)" echo "tree $(git write-tree)"

View File

@ -706,10 +706,9 @@ class Project(object):
# commits are not yet merged upstream. We do not want # commits are not yet merged upstream. We do not want
# to rewrite the published commits so we punt. # to rewrite the published commits so we punt.
# #
syncbuf.info(self, syncbuf.fail(self,
"branch %s is published but is now %d commits behind", "branch %s is published (but not merged) and is now %d commits behind"
branch.name, % (branch.name, len(upstream_gain)))
len(upstream_gain))
return return
elif pub == head: elif pub == head:
# All published commits are merged, and thus we are a # All published commits are merged, and thus we are a
@ -728,7 +727,7 @@ class Project(object):
last_mine = None last_mine = None
cnt_mine = 0 cnt_mine = 0
for commit in local_changes: for commit in local_changes:
commit_id, committer_email = commit.split(' ', 2) commit_id, committer_email = commit.split(' ', 1)
if committer_email == self.UserEmail: if committer_email == self.UserEmail:
last_mine = commit_id last_mine = commit_id
cnt_mine += 1 cnt_mine += 1
@ -1132,7 +1131,10 @@ class Project(object):
dst = os.path.join(dotgit, name) dst = os.path.join(dotgit, name)
if relink: if relink:
os.remove(dst) os.remove(dst)
os.symlink(relpath(src, dst), dst) if os.path.islink(dst) or not os.path.exists(dst):
os.symlink(relpath(src, dst), dst)
else:
raise GitError('cannot overwrite a local work tree')
except OSError, e: except OSError, e:
if e.errno == errno.EPERM: if e.errno == errno.EPERM:
raise GitError('filesystem must support symlinks') raise GitError('filesystem must support symlinks')

View File

@ -111,7 +111,6 @@ later is required to fix a server side protocol bug.
pm = Progress('Fetching projects', len(projects)) pm = Progress('Fetching projects', len(projects))
for project in projects: for project in projects:
pm.update() pm.update()
if project.Sync_NetworkHalf(): if project.Sync_NetworkHalf():
fetched.add(project.gitdir) fetched.add(project.gitdir)
else: else:
@ -194,6 +193,15 @@ uncommitted changes are present' % project.relpath
if opt.repo_upgraded: if opt.repo_upgraded:
_PostRepoUpgrade(self.manifest) _PostRepoUpgrade(self.manifest)
if not opt.local_only:
mp.Sync_NetworkHalf()
if mp.HasChanges:
syncbuf = SyncBuffer(mp.config)
mp.Sync_LocalHalf(syncbuf)
if not syncbuf.Finish():
sys.exit(1)
self.manifest._Unload()
all = self.GetProjects(args, missing_ok=True) all = self.GetProjects(args, missing_ok=True)
if not opt.local_only: if not opt.local_only:
@ -201,7 +209,6 @@ uncommitted changes are present' % project.relpath
now = time.time() now = time.time()
if (24 * 60 * 60) <= (now - rp.LastFetch): if (24 * 60 * 60) <= (now - rp.LastFetch):
to_fetch.append(rp) to_fetch.append(rp)
to_fetch.append(mp)
to_fetch.extend(all) to_fetch.extend(all)
fetched = self._Fetch(to_fetch) fetched = self._Fetch(to_fetch)