Skip to content

Commit

Permalink
Support for SmartLocks
Browse files Browse the repository at this point in the history
  • Loading branch information
juliomaqueda committed Nov 8, 2023
1 parent b4d149e commit 10096ad
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 28 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ This add-on integrates the essentials of Unity Version Control into Blender, let

## Requirements

* [Blender](https://www.blender.org/download/) >= 2.8.0 (last tested with 3.3.1 LTS)
* [Unity Version Control](https://www.plasticscm.com/download)
* [Blender](https://www.blender.org/download/) >= 2.8.0 (tested up to 3.6.5 LTS)
* [Unity Version Control](https://www.plasticscm.com/download) >= 11.0.16.8101

> ℹ️   The add-on will use your local configuration of Unity Version Control automatically, no matter if you connect to an on-premise server or if you have a [cloud subscription](https://service-store.unity.com/order) _(**first 3 seats and 5 GB are free**)_.
Expand Down Expand Up @@ -73,9 +73,9 @@ Checking out files is the way to tell the Unity Version Control server your inte

### Lock / unlock

Depending on the server configuration, your checkout operations may entail exclusive locks on the involved files.
Depending on the server configuration, your checkout operations may entail exclusive locks.

This capability will allow you to easily lock and unlock files, while informing you of the current lock owner (if any).
This functionality empowers you to effortlessly manage file locks, providing real-time updates on the lock status, if applicable.

### Create new branches

Expand Down
2 changes: 1 addition & 1 deletion ui/operators/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def execute(self, context):
checkout_error_log = client.checkout()

if checkout_error_log is None:
if client.get_lock_owner() is None:
if client.get_lock_info() is None:
common.show_error_message('Lock failed', ['The current file doesn\'t meet the locking criteria.'])
else:
common.show_error_log('Checkout failed', 'It was not possible to checkout the file.', checkout_error_log)
Expand Down
18 changes: 13 additions & 5 deletions ui/sections/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,31 @@ def draw(layout, panel_settings):
row.prop(panel_settings, 'checkout_menu_active', text='Checkout / Locking', icon=icon, translate=False)

if panel_settings.checkout_menu_active:
lock_info = client.get_lock_info()

box = layout.box()

row = box.row()
row.label(text='Checkout status: ' + ('Checked-out' if client.is_checked_out() else 'Not checked-out'), translate=False)

row = box.row()
row.label(text='Lock status: ' + ('Locked' if client.get_lock_owner() is not None else 'Not locked'), translate=False)
if lock_info is not None:
row = box.row()
row.label(text='Lock status: ' + lock_info.type, translate=False)

if client.get_lock_owner() is not None:
row = box.row()
row.label(text='Lock owner: ' + client.get_lock_owner(), translate=False)
row.label(text='Lock owner: ' + lock_info.owner, translate=False)

row = box.row()
row.label(text='Lock branch: ' + lock_info.branch, translate=False)
else:
row = box.row()
row.label(text='Lock status: Not locked', translate=False)

row = box.row()

row.operator('uvcs.checkout', text='Checkout' if not client.is_checked_out() else 'Checked-out', icon='IMPORT', translate=False)

if client.get_lock_owner() is not None:
if lock_info is not None:
row.operator('uvcs.unlock', text='Unlock', icon='UNLOCKED', translate=False)
else:
row.operator('uvcs.lock', text='Lock', icon='LOCKED', translate=False)
3 changes: 2 additions & 1 deletion uvcs/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def checkin(comment):
checkin_error_log = checkin_operations.checkin(comment)

if checkin_error_log is None:
checkout_operations.clear_cache()
history_operations.clear_cache()
refresh_file_info()

Expand Down Expand Up @@ -126,7 +127,7 @@ def checkout():

return checkout_error_log

def get_lock_owner(): return checkout_operations.get_lock_owner()
def get_lock_info(): return checkout_operations.get_lock_info()

def unlock(): return checkout_operations.unlock()

Expand Down
11 changes: 11 additions & 0 deletions uvcs/models/lock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class LockEntry():
guid = None
owner = None
branch = None
type = None

def __init__(self, guid, owner, branch, type):
self.guid = guid
self.owner = owner
self.branch = branch
self.type = type
43 changes: 26 additions & 17 deletions uvcs/operations/checkout.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
import bpy

from . import command
from ..models import lock
from ... import common

__LOCK_FIELD_SEPARATOR = ','

__lock_owner = None
__locked_file_guid = None
__lock_info = None
__lock_loaded = False

def __load_active_lock():
global __lock_owner, __locked_file_guid
__lock_owner = None
__locked_file_guid = None
global __lock_info
__lock_info = None

lock_result = command.execute([
'lock',
'list',
'--machinereadable',
'--anystatus',
'--smartlocks',
'--fieldseparator=' + __LOCK_FIELD_SEPARATOR,
common.quote(bpy.data.filepath)
])

if lock_result.success and lock_result.output[0] != '':
lock_info = lock_result.output[0].split(__LOCK_FIELD_SEPARATOR)

if len(lock_info) == 4:
__lock_owner = lock_info[1]
__locked_file_guid = lock_info[0]
if len(lock_info) == 12:
__lock_info = lock.LockEntry(
lock_info[2],
lock_info[9],
lock_info[6],
lock_info[8]
)

def add():
command_result = command.execute(['add', '--silent', common.quote(bpy.data.filepath)])
Expand All @@ -42,25 +47,29 @@ def checkout():

return None if command_result.success else command_result.output

def get_lock_owner():
def get_lock_info():
global __lock_loaded

if not __lock_loaded:
__lock_loaded = True
__load_active_lock()

return __lock_owner
return __lock_info

def unlock():
command_result = command.execute(['lock', 'unlock', __locked_file_guid])
if __lock_info is not None:
command_result = command.execute(['lock', 'unlock', __lock_info.guid])

if command_result.success:
clear_cache()
if command_result.success:
clear_cache()

return None if command_result.success else command_result.output
return None if command_result.success else command_result.output

clear_cache()

return None

def clear_cache():
global __lock_owner, __locked_file_guid, __lock_loaded
__lock_owner = None
__locked_file_guid = None
global __lock_info, __lock_loaded
__lock_info = None
__lock_loaded = False

0 comments on commit 10096ad

Please sign in to comment.