Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] Result.LOCK_FAILURE on RefUpdate for conflicting refs

Hi all,
I have a question about a misleading (IMHO) behaviour on the RefUpdate.

See below the code fragment:

        private Result updateImpl(final RevWalk walk, final Store store)
                        throws IOException {
                RevObject newObj;
                RevObject oldObj;

                // don't make expensive conflict check if this is an existing Ref
                if (oldValue == null && checkConflicting && getRefDatabase().isNameConflicting(getName()))
                        return Result.LOCK_FAILURE;
                try {
                        if (!tryLock(true))
                                return Result.LOCK_FAILURE;
                        if (expValue != null) {
                                final ObjectId o;
                                o = oldValue != null ? oldValue : ObjectId.zeroId();
                                if (!AnyObjectId.equals(expValue, o))
                                        return Result.LOCK_FAILURE;

When trying to add a new ref BUT there is a genuine ref-name conflicts (I want to add ref/changes/41/5541/1 but an equivalent branch already exist), the following happens:

1) The code highlighted in RED is not used (but it should IMHO): oldValue is NOT null but a set of zeros ID ... and thus we don't check for conflicting names. Should we give as well a more descriptive reason code other than LOCK_FAILURE in this case ?
2) The code highlighted in GREEN is used (the real compare-and-swap lock check) even if there is not really any lock contention.

I would opt for changing this behaviour and:

a) Introduce a more descriptive result in case of conflicting ref names 
b) Add the check for ObjectId.zeroId() on the RED part

--- * ---

Any input / suggestion is more than welcome :-)


Back to the top