[git] Swallow clone 과 브랜치

Swallow Clone 은 git 저장소에 커밋된 기록중 일부만 사용하는 기술 있다. 그런데 브랜치를 추가하면 원격지와 클론한 저장소에서 탐색이 안되는 단점이 있다. 여기서 swallow clone 에서 branch를 사용하는 방법을 요약한다.

Swallow Clone 에서 branch를 사용하자.

기본적으로 swallow clone 을 사용하면 원격 저장소의 branch 를 모두 볼 수 없다. 이것은 .git/config 를 보면 refs/remotes/origin/master 로 구성되어 있어서이다. 그래서 swallow clone 한 저장소는 원격 저장소의 master 브랜치만 보게 된다.

다음은 .git/config 의 일부이다.

1
2
3
[remote "origin"]
url = git@github.com:repository/YOUR_REPO.git
fetch = +refs/heads/*:refs/remotes/origin/master

master 브랜치 대신 브랜치 트리 모두를 보려면 아래 같은 단계로 처리해 준다.

  1. 다음 같이 원격 저장소의 모든 브랜치를 대상으로 처리해 준다.
1
git remote set-branches origin '*'

origin 의 브랜치를 master에서 * 로 지정하면 .git/config가 아래 같이 수정된다.

1
2
3
[remote "origin"]
url = git@github.com:repository/YOUR_REPO.git
fetch = +refs/heads/*:refs/remotes/origin/*
  1. 이어서 원격 레포지토리를 업데이트 하면 관련한 브랜치 정보를 갱신한다.
1
2
3
4
5
6
7
8
9
10
11
$ git remote update
Fetching origin
remote: Enumerating objects: 306, done.
remote: Counting objects: 100% (306/306), done.
remote: Compressing objects: 100% (283/283), done.
remote: Total 285 (delta 161), reused 6 (delta 0), pack-reused 0
Receiving objects: 100% (285/285), 8.59 MiB | 4.35 MiB/s, done.
Resolving deltas: 100% (161/161), completed with 16 local objects.
From git@github.com:repository/YOUR_REPO.git
* [new branch] 1024_dev -> origin/1024_dev
* [new branch] gt_master -> origin/gt_master
  1. 업데이트 한 후에 원격 브랜치만 검색해도 잘 나타난다.
1
2
3
4
5
$ git branch -r
origin/1024_dev
origin/HEAD -> origin/master
origin/gt_master
origin/master
  1. 원격지 브랜치를 체크아웃해서 사용하면 된다.
1
$ git checkout -b t origin/1024_dev

함께 보면 유용한 git 명령

간단하게 빌드/테스트 를 하기위함 이라면 `Sparse-checkout`` 과 함께 이용하면 좋다.

  1. [git] Sparse Checkout
  2. Swallow Clone

MariaDB - json type Tutorial

MariaDB / MySQL 에서 json data type을 사용할 수 있다.

MariaDB json tutorial

https://mariadb.com/ko/resources/blog/using-json-in-mariadb/

USE lecture;

CREATE TABLE locations (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(100) NOT NULL,
type CHAR(1) NOT NULL,
latitude DECIMAL(9,6) NOT NULL,
longitude DECIMAL(9,6) NOT NULL,
attr JSON,
PRIMARY KEY (id)
);

DESC locations;

INSERT INTO locations (type, name, latitude, longitude, attr) VALUES
(‘R’, ‘Lou Malnatis’, 42.0021628, -87.7255662,
‘{ “details”: {
“foodType”: “Pizza”,
“menu”: “https://www.loumalnatis.com/our-menu
},
“favorites”: [{“description”: “Pepperoni deep dish”, “price”: 18.75},
{“description”: “The Lou”, “price”: 24.75}]}’);

SELECT * FROM locations;

– scala value
SELECT NAME, latitude, longitude,
JSON_VALUE(attr, ‘$.details.foodType’) AS Food
FROM locations;

– return object
SELECT NAME, latitude, longitude,
JSON_QUERY(attr, ‘$.details’) AS details
FROM locations;

SELECT NAME, latitude, longitude,
JSON_QUERY(attr, ‘$.favorites’) AS details
FROM locations;

– return values
SELECT NAME, latitude, longitude,
JSON_EXTRACT(attr, ‘$.details’) AS details
FROM locations;

creating INDEX

– virtual colunn 을 이용해 json_oject의 요소를 컬럼으로 만들고
– 이것을 인덱스로 지정한다.

ALTER TABLE locations ADD COLUMN
food_type VARCHAR(25) AS ( JSON_VALUE( attr, ‘$.details.foodType’)) VIRTUAL;
DESC locations;

CREATE INDEX foottypes ON locations(food_type);

modifying json data

– JSON_INSERT(): inserting new object
UPDATE locations
SET attr = JSON_INSERT(attr, ‘$.nickname’, ‘oh ben’)
WHERE id=1;
SELECT JSON_QUERY(attr, ‘$.nickname’) FROM locations;
SELECT JSON_EXTRACT(attr, ‘$.nickname’) FROM locations;

SELECT * FROM locations;

UPDATE locations
SET attr = JSON_INSERT(attr, ‘$.foodTypes’,
JSON_ARRAY(‘Asian’, ‘Mexican’))
WHERE id = 1;

SELECT JSON_EXTRACT(attr, ‘$.foodTypes’) FROM locations;

– JSON_ARRAY_APPEND() : adding array elements
UPDATE locations
SET attr = JSON_ARRAY_APPEND(attr, ‘$.foodTypes’, ‘German’)
WHERE id = 1;

SELECT JSON_QUERY(attr, ‘$.foodTypes’) FROM locations;
SELECT JSON_EXTRACT(attr, ‘$.foodTypes’) FROM locations;

– JSON_REMOVE(): REMOVING ARRAY ELEMENTS

UPDATE locations
SET attr = JSON_REMOVE(attr, ‘$.foodTypes[2]’) – German
WHERE id = 1;

SELECT JSON_EXTRACT(attr, ‘$.foodTypes’) FROM locations;

Hybrid querhying: sql, json 장점

– json object 생성
SELECT
JSON_OBJECT(‘name’, name, ‘latitude’, latitude, ‘longitude’, longitude) AS data
FROM locations;

– merging
SELECT JSON_MERGE(
JSON_OBJECT(
‘name’, name,
‘latitude’, latitude,
‘Longitude’, longitude),
attr) AS DATA
FROM locations;

– JSON TO TABULAR DATA
– Server 10.6 the JSON_TABLE()

SELECT JSON_EXTRACT(attr, ‘$’) FROM locations;

SELECT l.name, d.food_type, d.menu
FROM locations AS l,
JSON_TABLE( l.attr,
‘$’ COLUMNS(
food_type VARCHAR(25) PATH ‘$.foodType’,
menu VARCHAR(200) PATH ‘$.menu’
)
) AS d
WHERE id=1;

ALTER TABLE locations ADD CONSTRAINT check_attr
CHECK(
type != ‘S’ OR (type = ‘S’ AND
JSON_TYPE(JSON_QUERY(attr, ‘$.details’)) = ‘OBJECT’ AND
JSON_TYPE(JSON_QUERY(attr, ‘$.details.events’)) = ‘ARRAY’ AND
JSON_TYPE(JSON_VALUE(attr, ‘$.details.yearOpened’)) = ‘INTEGER’ AND
JSON_TYPE(JSON_VALUE(attr, ‘$.details.capacity’)) = ‘INTEGER’ AND
JSON_EXISTS(attr, ‘$.details.yearOpened’) = 1 AND
JSON_EXISTS(attr, ‘$.details.capacity’) = 1 AND
JSON_LENGTH(JSON_QUERY(attr, ‘$.details.events’)) > 0));

DROP TABLE locations;


  1. jsonpath-expressions: https://mariadb.com/kb/en/jsonpath-expressions/
  2. Json type tutorials : Using-json-in-mariadb