You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo.go 67 kB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
9 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
9 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
9 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
9 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
9 years ago
10 years ago
10 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
10 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
11 years ago
10 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
9 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
9 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
9 years ago
Squashed commit of the following: commit 0afcb843d7ffd596991c4885cab768273a6eb42c Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 17:13:29 2016 -0600 Removed Upload stats as the upload table is just a temporary table commit 7ecd73ff5535612d79d471409173ee7f1fcfa157 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:42:41 2016 -0600 Fix for CodeMirror mode commit c29b9ab531e2e7af0fb5db24dc17e51027dd1174 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 08:03:33 2016 -0600 Made tabbing in editor use spaces commit 23af384c53206a8a40e11e45bf49d7a149c4adcd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:56:46 2016 -0600 Fix for data-url commit cfb8a97591cb6fc0a92e49563b7b764c524db0e9 Merge: 7fc8a89 991ce42 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:42:53 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit 7fc8a89cb495478225b02d613e647f99a1489634 Merge: fd3d86c c03d040 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:40:00 2016 -0600 Merge branch 'feature-create-and-edit-repo-file' of github.com:richmahn/gogs into feature-create-and-edit-repo-file commit fd3d86ca6bbc02cfda566a504ffd6b03db4f75ef Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Sun Jul 31 07:39:44 2016 -0600 Code cleanup commit c03d0401c1049eeeccc32ab1f9c3303c130be5ee Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 29 15:38:23 2016 -0600 Code cleanup commit 98e1206ccf9f9a4503c020e3a7830cf9f861dfae Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:36:01 2016 -0600 Code cleanup and fixes commit c2895dc742f25f8412879c9fa15e18f27f42f194 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 18:24:04 2016 -0600 Fixes per Unknwon's requests commit 6aa7e46b21ad4c96e562daa2eac26a8fb408f8ef Merge: 889e9fa ad7ea88 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Thu Jul 28 17:13:43 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go modules/setting/setting.go commit 889e9faf1bd8559a4979c8f46005d488c1a234d4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:09:18 2016 -0600 Fix in gogs.js commit 47603edf223f147b114be65f3bd27bc1e88827a5 Merge: bb57912 cf85e9e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:07:36 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go public/js/gogs.js commit bb5791255867a71c11a77b639db050ad09c597a4 Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 22 14:02:18 2016 -0600 Update for using CodeMirror mode addon commit d10d128c51039be19e2af9c66c63db66a9f2ec6d Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 16:12:57 2016 -0600 Update for Edit commit 34a34982025144e3225e389f7849eb6273c1d576 Merge: fa1b752 1c7dcdd Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Tue Jul 19 11:52:02 2016 -0600 Merge remote-tracking branch 'gogits/develop' into feature-create-and-edit-repo-file Conflicts: modules/bindata/bindata.go commit fa1b752be29cd455c5184ddac2ffe80b3489763e Author: Richard Mahn <richard_mahn@wycliffeassociates.org> Date: Fri Jul 15 18:35:42 2016 -0600 Feature for editing, creating, uploading and deleting files
9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "bytes"
  7. "errors"
  8. "fmt"
  9. "html/template"
  10. "io/ioutil"
  11. "os"
  12. "os/exec"
  13. "path"
  14. "path/filepath"
  15. "regexp"
  16. "sort"
  17. "strings"
  18. "time"
  19. "github.com/Unknwon/cae/zip"
  20. "github.com/Unknwon/com"
  21. "github.com/go-xorm/xorm"
  22. "github.com/mcuadros/go-version"
  23. "gopkg.in/ini.v1"
  24. git "github.com/gogits/git-module"
  25. api "github.com/gogits/go-gogs-client"
  26. "github.com/gogits/gogs/modules/bindata"
  27. "github.com/gogits/gogs/modules/log"
  28. "github.com/gogits/gogs/modules/markdown"
  29. "github.com/gogits/gogs/modules/process"
  30. "github.com/gogits/gogs/modules/setting"
  31. "github.com/gogits/gogs/modules/sync"
  32. )
  33. const (
  34. _TPL_UPDATE_HOOK = "#!/usr/bin/env %s\n%s update $1 $2 $3 --config='%s'\n"
  35. )
  36. var repoWorkingPool = sync.NewSingleInstancePool()
  37. var (
  38. ErrRepoFileNotExist = errors.New("Repository file does not exist")
  39. ErrRepoFileNotLoaded = errors.New("Repository file not loaded")
  40. ErrMirrorNotExist = errors.New("Mirror does not exist")
  41. ErrInvalidReference = errors.New("Invalid reference specified")
  42. ErrNameEmpty = errors.New("Name is empty")
  43. )
  44. var (
  45. Gitignores, Licenses, Readmes, LabelTemplates []string
  46. // Maximum items per page in forks, watchers and stars of a repo
  47. ItemsPerPage = 40
  48. )
  49. func LoadRepoConfig() {
  50. // Load .gitignore and license files and readme templates.
  51. types := []string{"gitignore", "license", "readme", "label"}
  52. typeFiles := make([][]string, 4)
  53. for i, t := range types {
  54. files, err := bindata.AssetDir("conf/" + t)
  55. if err != nil {
  56. log.Fatal(4, "Fail to get %s files: %v", t, err)
  57. }
  58. customPath := path.Join(setting.CustomPath, "conf", t)
  59. if com.IsDir(customPath) {
  60. customFiles, err := com.StatDir(customPath)
  61. if err != nil {
  62. log.Fatal(4, "Fail to get custom %s files: %v", t, err)
  63. }
  64. for _, f := range customFiles {
  65. if !com.IsSliceContainsStr(files, f) {
  66. files = append(files, f)
  67. }
  68. }
  69. }
  70. typeFiles[i] = files
  71. }
  72. Gitignores = typeFiles[0]
  73. Licenses = typeFiles[1]
  74. Readmes = typeFiles[2]
  75. LabelTemplates = typeFiles[3]
  76. sort.Strings(Gitignores)
  77. sort.Strings(Licenses)
  78. sort.Strings(Readmes)
  79. sort.Strings(LabelTemplates)
  80. // Filter out invalid names and promote preferred licenses.
  81. sortedLicenses := make([]string, 0, len(Licenses))
  82. for _, name := range setting.Repository.PreferredLicenses {
  83. if com.IsSliceContainsStr(Licenses, name) {
  84. sortedLicenses = append(sortedLicenses, name)
  85. }
  86. }
  87. for _, name := range Licenses {
  88. if !com.IsSliceContainsStr(setting.Repository.PreferredLicenses, name) {
  89. sortedLicenses = append(sortedLicenses, name)
  90. }
  91. }
  92. Licenses = sortedLicenses
  93. }
  94. func NewRepoContext() {
  95. zip.Verbose = false
  96. // Check Git installation.
  97. if _, err := exec.LookPath("git"); err != nil {
  98. log.Fatal(4, "Fail to test 'git' command: %v (forgotten install?)", err)
  99. }
  100. // Check Git version.
  101. gitVer, err := git.BinVersion()
  102. if err != nil {
  103. log.Fatal(4, "Fail to get Git version: %v", err)
  104. }
  105. log.Info("Git Version: %s", gitVer)
  106. if version.Compare("1.7.1", gitVer, ">") {
  107. log.Fatal(4, "Gogs requires Git version greater or equal to 1.7.1")
  108. }
  109. // Git requires setting user.name and user.email in order to commit changes.
  110. for configKey, defaultValue := range map[string]string{"user.name": "Gogs", "user.email": "gogs@fake.local"} {
  111. if stdout, stderr, err := process.Exec("NewRepoContext(get setting)", "git", "config", "--get", configKey); err != nil || strings.TrimSpace(stdout) == "" {
  112. // ExitError indicates this config is not set
  113. if _, ok := err.(*exec.ExitError); ok || strings.TrimSpace(stdout) == "" {
  114. if _, stderr, gerr := process.Exec("NewRepoContext(set "+configKey+")", "git", "config", "--global", configKey, defaultValue); gerr != nil {
  115. log.Fatal(4, "Fail to set git %s(%s): %s", configKey, gerr, stderr)
  116. }
  117. log.Info("Git config %s set to %s", configKey, defaultValue)
  118. } else {
  119. log.Fatal(4, "Fail to get git %s(%s): %s", configKey, err, stderr)
  120. }
  121. }
  122. }
  123. // Set git some configurations.
  124. if _, stderr, err := process.Exec("NewRepoContext(git config --global core.quotepath false)",
  125. "git", "config", "--global", "core.quotepath", "false"); err != nil {
  126. log.Fatal(4, "Fail to execute 'git config --global core.quotepath false': %s", stderr)
  127. }
  128. RemoveAllWithNotice("Clean up repository temporary data", filepath.Join(setting.AppDataPath, "tmp"))
  129. }
  130. // Repository represents a git repository.
  131. type Repository struct {
  132. ID int64 `xorm:"pk autoincr"`
  133. OwnerID int64 `xorm:"UNIQUE(s)"`
  134. Owner *User `xorm:"-"`
  135. LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"`
  136. Name string `xorm:"INDEX NOT NULL"`
  137. Description string
  138. Website string
  139. DefaultBranch string
  140. NumWatches int
  141. NumStars int
  142. NumForks int
  143. NumIssues int
  144. NumClosedIssues int
  145. NumOpenIssues int `xorm:"-"`
  146. NumPulls int
  147. NumClosedPulls int
  148. NumOpenPulls int `xorm:"-"`
  149. NumMilestones int `xorm:"NOT NULL DEFAULT 0"`
  150. NumClosedMilestones int `xorm:"NOT NULL DEFAULT 0"`
  151. NumOpenMilestones int `xorm:"-"`
  152. NumTags int `xorm:"-"`
  153. IsPrivate bool
  154. IsBare bool
  155. IsMirror bool
  156. *Mirror `xorm:"-"`
  157. // Advanced settings
  158. EnableWiki bool `xorm:"NOT NULL DEFAULT true"`
  159. EnableExternalWiki bool
  160. ExternalWikiURL string
  161. EnableIssues bool `xorm:"NOT NULL DEFAULT true"`
  162. EnableExternalTracker bool
  163. ExternalTrackerFormat string
  164. ExternalTrackerStyle string
  165. ExternalMetas map[string]string `xorm:"-"`
  166. EnablePulls bool `xorm:"NOT NULL DEFAULT true"`
  167. IsFork bool `xorm:"NOT NULL DEFAULT false"`
  168. ForkID int64
  169. BaseRepo *Repository `xorm:"-"`
  170. Created time.Time `xorm:"-"`
  171. CreatedUnix int64
  172. Updated time.Time `xorm:"-"`
  173. UpdatedUnix int64
  174. }
  175. func (repo *Repository) BeforeInsert() {
  176. repo.CreatedUnix = time.Now().Unix()
  177. repo.UpdatedUnix = repo.CreatedUnix
  178. }
  179. func (repo *Repository) BeforeUpdate() {
  180. repo.UpdatedUnix = time.Now().Unix()
  181. }
  182. func (repo *Repository) AfterSet(colName string, _ xorm.Cell) {
  183. switch colName {
  184. case "default_branch":
  185. // FIXME: use models migration to solve all at once.
  186. if len(repo.DefaultBranch) == 0 {
  187. repo.DefaultBranch = "master"
  188. }
  189. case "num_closed_issues":
  190. repo.NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
  191. case "num_closed_pulls":
  192. repo.NumOpenPulls = repo.NumPulls - repo.NumClosedPulls
  193. case "num_closed_milestones":
  194. repo.NumOpenMilestones = repo.NumMilestones - repo.NumClosedMilestones
  195. case "external_tracker_style":
  196. if len(repo.ExternalTrackerStyle) == 0 {
  197. repo.ExternalTrackerStyle = markdown.ISSUE_NAME_STYLE_NUMERIC
  198. }
  199. case "created_unix":
  200. repo.Created = time.Unix(repo.CreatedUnix, 0).Local()
  201. case "updated_unix":
  202. repo.Updated = time.Unix(repo.UpdatedUnix, 0)
  203. }
  204. }
  205. // MustOwner always returns a valid *User object to avoid
  206. // conceptually impossible error handling.
  207. // It creates a fake object that contains error deftail
  208. // when error occurs.
  209. func (repo *Repository) MustOwner() *User {
  210. return repo.mustOwner(x)
  211. }
  212. func (repo *Repository) FullName() string {
  213. return repo.MustOwner().Name + "/" + repo.Name
  214. }
  215. func (repo *Repository) HTMLURL() string {
  216. return setting.AppUrl + repo.FullName()
  217. }
  218. // Arguments that are allowed to be nil: permission
  219. func (repo *Repository) APIFormat(permission *api.Permission) *api.Repository {
  220. cloneLink := repo.CloneLink()
  221. return &api.Repository{
  222. ID: repo.ID,
  223. Owner: repo.Owner.APIFormat(),
  224. Name: repo.Name,
  225. FullName: repo.FullName(),
  226. Description: repo.Description,
  227. Private: repo.IsPrivate,
  228. Fork: repo.IsFork,
  229. HTMLURL: repo.HTMLURL(),
  230. SSHURL: cloneLink.SSH,
  231. CloneURL: cloneLink.HTTPS,
  232. Website: repo.Website,
  233. Stars: repo.NumStars,
  234. Forks: repo.NumForks,
  235. Watchers: repo.NumWatches,
  236. OpenIssues: repo.NumOpenIssues,
  237. DefaultBranch: repo.DefaultBranch,
  238. Created: repo.Created,
  239. Updated: repo.Updated,
  240. Permissions: permission,
  241. }
  242. }
  243. func (repo *Repository) getOwner(e Engine) (err error) {
  244. if repo.Owner != nil {
  245. return nil
  246. }
  247. repo.Owner, err = getUserByID(e, repo.OwnerID)
  248. return err
  249. }
  250. func (repo *Repository) GetOwner() error {
  251. return repo.getOwner(x)
  252. }
  253. func (repo *Repository) mustOwner(e Engine) *User {
  254. if err := repo.getOwner(e); err != nil {
  255. return &User{
  256. Name: "error",
  257. FullName: err.Error(),
  258. }
  259. }
  260. return repo.Owner
  261. }
  262. // ComposeMetas composes a map of metas for rendering external issue tracker URL.
  263. func (repo *Repository) ComposeMetas() map[string]string {
  264. if !repo.EnableExternalTracker {
  265. return nil
  266. } else if repo.ExternalMetas == nil {
  267. repo.ExternalMetas = map[string]string{
  268. "format": repo.ExternalTrackerFormat,
  269. "user": repo.MustOwner().Name,
  270. "repo": repo.Name,
  271. }
  272. switch repo.ExternalTrackerStyle {
  273. case markdown.ISSUE_NAME_STYLE_ALPHANUMERIC:
  274. repo.ExternalMetas["style"] = markdown.ISSUE_NAME_STYLE_ALPHANUMERIC
  275. default:
  276. repo.ExternalMetas["style"] = markdown.ISSUE_NAME_STYLE_NUMERIC
  277. }
  278. }
  279. return repo.ExternalMetas
  280. }
  281. // DeleteWiki removes the actual and local copy of repository wiki.
  282. func (repo *Repository) DeleteWiki() {
  283. wikiPaths := []string{repo.WikiPath(), repo.LocalWikiPath()}
  284. for _, wikiPath := range wikiPaths {
  285. RemoveAllWithNotice("Delete repository wiki", wikiPath)
  286. }
  287. }
  288. func (repo *Repository) getAssignees(e Engine) (_ []*User, err error) {
  289. if err = repo.getOwner(e); err != nil {
  290. return nil, err
  291. }
  292. accesses := make([]*Access, 0, 10)
  293. if err = e.Where("repo_id = ? AND mode >= ?", repo.ID, ACCESS_MODE_WRITE).Find(&accesses); err != nil {
  294. return nil, err
  295. }
  296. // Leave a seat for owner itself to append later, but if owner is an organization
  297. // and just waste 1 unit is cheaper than re-allocate memory once.
  298. users := make([]*User, 0, len(accesses)+1)
  299. if len(accesses) > 0 {
  300. userIDs := make([]int64, len(accesses))
  301. for i := 0; i < len(accesses); i++ {
  302. userIDs[i] = accesses[i].UserID
  303. }
  304. if err = e.In("id", userIDs).Find(&users); err != nil {
  305. return nil, err
  306. }
  307. }
  308. if !repo.Owner.IsOrganization() {
  309. users = append(users, repo.Owner)
  310. }
  311. return users, nil
  312. }
  313. // GetAssignees returns all users that have write access and can be assigned to issues
  314. // of the repository,
  315. func (repo *Repository) GetAssignees() (_ []*User, err error) {
  316. return repo.getAssignees(x)
  317. }
  318. // GetAssigneeByID returns the user that has write access of repository by given ID.
  319. func (repo *Repository) GetAssigneeByID(userID int64) (*User, error) {
  320. return GetAssigneeByID(repo, userID)
  321. }
  322. // GetMilestoneByID returns the milestone belongs to repository by given ID.
  323. func (repo *Repository) GetMilestoneByID(milestoneID int64) (*Milestone, error) {
  324. return GetMilestoneByRepoID(repo.ID, milestoneID)
  325. }
  326. // IssueStats returns number of open and closed repository issues by given filter mode.
  327. func (repo *Repository) IssueStats(uid int64, filterMode int, isPull bool) (int64, int64) {
  328. return GetRepoIssueStats(repo.ID, uid, filterMode, isPull)
  329. }
  330. func (repo *Repository) GetMirror() (err error) {
  331. repo.Mirror, err = GetMirror(repo.ID)
  332. return err
  333. }
  334. func (repo *Repository) GetBaseRepo() (err error) {
  335. if !repo.IsFork {
  336. return nil
  337. }
  338. repo.BaseRepo, err = GetRepositoryByID(repo.ForkID)
  339. return err
  340. }
  341. func (repo *Repository) repoPath(e Engine) string {
  342. return RepoPath(repo.mustOwner(e).Name, repo.Name)
  343. }
  344. func (repo *Repository) RepoPath() string {
  345. return repo.repoPath(x)
  346. }
  347. func (repo *Repository) GitConfigPath() string {
  348. return filepath.Join(repo.RepoPath(), "config")
  349. }
  350. func (repo *Repository) RelLink() string {
  351. return "/" + repo.FullName()
  352. }
  353. func (repo *Repository) Link() string {
  354. return setting.AppSubUrl + "/" + repo.FullName()
  355. }
  356. func (repo *Repository) ComposeCompareURL(oldCommitID, newCommitID string) string {
  357. return fmt.Sprintf("%s/%s/compare/%s...%s", repo.MustOwner().Name, repo.Name, oldCommitID, newCommitID)
  358. }
  359. func (repo *Repository) HasAccess(u *User) bool {
  360. has, _ := HasAccess(u, repo, ACCESS_MODE_READ)
  361. return has
  362. }
  363. func (repo *Repository) IsOwnedBy(userID int64) bool {
  364. return repo.OwnerID == userID
  365. }
  366. // CanBeForked returns true if repository meets the requirements of being forked.
  367. func (repo *Repository) CanBeForked() bool {
  368. return !repo.IsBare
  369. }
  370. // CanEnablePulls returns true if repository meets the requirements of accepting pulls.
  371. func (repo *Repository) CanEnablePulls() bool {
  372. return !repo.IsMirror
  373. }
  374. // AllowPulls returns true if repository meets the requirements of accepting pulls and has them enabled.
  375. func (repo *Repository) AllowsPulls() bool {
  376. return repo.CanEnablePulls() && repo.EnablePulls
  377. }
  378. // CanEnableEditor returns true if repository meets the requirements of web editor.
  379. func (repo *Repository) CanEnableEditor() bool {
  380. return !repo.IsMirror
  381. }
  382. // FIXME: should have a mutex to prevent producing same index for two issues that are created
  383. // closely enough.
  384. func (repo *Repository) NextIssueIndex() int64 {
  385. return int64(repo.NumIssues+repo.NumPulls) + 1
  386. }
  387. var (
  388. DescPattern = regexp.MustCompile(`https?://\S+`)
  389. )
  390. // DescriptionHtml does special handles to description and return HTML string.
  391. func (repo *Repository) DescriptionHtml() template.HTML {
  392. sanitize := func(s string) string {
  393. return fmt.Sprintf(`<a href="%[1]s" target="_blank">%[1]s</a>`, s)
  394. }
  395. return template.HTML(DescPattern.ReplaceAllStringFunc(markdown.Sanitizer.Sanitize(repo.Description), sanitize))
  396. }
  397. func (repo *Repository) LocalCopyPath() string {
  398. return path.Join(setting.AppDataPath, "tmp/local-rpeo", com.ToStr(repo.ID))
  399. }
  400. // UpdateLocalCopy pulls latest changes of given branch from repoPath to localPath.
  401. // It creates a new clone if local copy does not exist.
  402. // This function checks out target branch by default, it is safe to assume subsequent
  403. // operations are operating against target branch when caller has confidence for no race condition.
  404. func UpdateLocalCopyBranch(repoPath, localPath, branch string) error {
  405. if !com.IsExist(localPath) {
  406. if err := git.Clone(repoPath, localPath, git.CloneRepoOptions{
  407. Timeout: time.Duration(setting.Git.Timeout.Clone) * time.Second,
  408. Branch: branch,
  409. }); err != nil {
  410. return fmt.Errorf("git clone %s: %v", branch, err)
  411. }
  412. } else {
  413. if err := git.Checkout(localPath, git.CheckoutOptions{
  414. Branch: branch,
  415. }); err != nil {
  416. return fmt.Errorf("git checkout %s: %v", branch, err)
  417. }
  418. if err := git.Pull(localPath, git.PullRemoteOptions{
  419. Timeout: time.Duration(setting.Git.Timeout.Pull) * time.Second,
  420. Remote: "origin",
  421. Branch: branch,
  422. }); err != nil {
  423. return fmt.Errorf("git pull origin %s: %v", branch, err)
  424. }
  425. }
  426. return nil
  427. }
  428. // UpdateLocalCopyBranch makes sure local copy of repository in given branch is up-to-date.
  429. func (repo *Repository) UpdateLocalCopyBranch(branch string) error {
  430. return UpdateLocalCopyBranch(repo.RepoPath(), repo.LocalCopyPath(), branch)
  431. }
  432. // PatchPath returns corresponding patch file path of repository by given issue ID.
  433. func (repo *Repository) PatchPath(index int64) (string, error) {
  434. if err := repo.GetOwner(); err != nil {
  435. return "", err
  436. }
  437. return filepath.Join(RepoPath(repo.Owner.Name, repo.Name), "pulls", com.ToStr(index)+".patch"), nil
  438. }
  439. // SavePatch saves patch data to corresponding location by given issue ID.
  440. func (repo *Repository) SavePatch(index int64, patch []byte) error {
  441. patchPath, err := repo.PatchPath(index)
  442. if err != nil {
  443. return fmt.Errorf("PatchPath: %v", err)
  444. }
  445. os.MkdirAll(filepath.Dir(patchPath), os.ModePerm)
  446. if err = ioutil.WriteFile(patchPath, patch, 0644); err != nil {
  447. return fmt.Errorf("WriteFile: %v", err)
  448. }
  449. return nil
  450. }
  451. func isRepositoryExist(e Engine, u *User, repoName string) (bool, error) {
  452. has, err := e.Get(&Repository{
  453. OwnerID: u.ID,
  454. LowerName: strings.ToLower(repoName),
  455. })
  456. return has && com.IsDir(RepoPath(u.Name, repoName)), err
  457. }
  458. // IsRepositoryExist returns true if the repository with given name under user has already existed.
  459. func IsRepositoryExist(u *User, repoName string) (bool, error) {
  460. return isRepositoryExist(x, u, repoName)
  461. }
  462. // CloneLink represents different types of clone URLs of repository.
  463. type CloneLink struct {
  464. SSH string
  465. HTTPS string
  466. Git string
  467. }
  468. // ComposeHTTPSCloneURL returns HTTPS clone URL based on given owner and repository name.
  469. func ComposeHTTPSCloneURL(owner, repo string) string {
  470. return fmt.Sprintf("%s%s/%s.git", setting.AppUrl, owner, repo)
  471. }
  472. func (repo *Repository) cloneLink(isWiki bool) *CloneLink {
  473. repoName := repo.Name
  474. if isWiki {
  475. repoName += ".wiki"
  476. }
  477. repo.Owner = repo.MustOwner()
  478. cl := new(CloneLink)
  479. if setting.SSH.Port != 22 {
  480. cl.SSH = fmt.Sprintf("ssh://%s@%s:%d/%s/%s.git", setting.RunUser, setting.SSH.Domain, setting.SSH.Port, repo.Owner.Name, repoName)
  481. } else {
  482. cl.SSH = fmt.Sprintf("%s@%s:%s/%s.git", setting.RunUser, setting.SSH.Domain, repo.Owner.Name, repoName)
  483. }
  484. cl.HTTPS = ComposeHTTPSCloneURL(repo.Owner.Name, repoName)
  485. return cl
  486. }
  487. // CloneLink returns clone URLs of repository.
  488. func (repo *Repository) CloneLink() (cl *CloneLink) {
  489. return repo.cloneLink(false)
  490. }
  491. // Mirror represents a mirror information of repository.
  492. type Mirror struct {
  493. ID int64 `xorm:"pk autoincr"`
  494. RepoID int64
  495. Repo *Repository `xorm:"-"`
  496. Interval int // Hour.
  497. EnablePrune bool `xorm:"NOT NULL DEFAULT true"`
  498. Updated time.Time `xorm:"-"`
  499. UpdatedUnix int64
  500. NextUpdate time.Time `xorm:"-"`
  501. NextUpdateUnix int64
  502. address string `xorm:"-"`
  503. }
  504. func (m *Mirror) BeforeInsert() {
  505. m.NextUpdateUnix = m.NextUpdate.Unix()
  506. }
  507. func (m *Mirror) BeforeUpdate() {
  508. m.UpdatedUnix = time.Now().Unix()
  509. m.NextUpdateUnix = m.NextUpdate.Unix()
  510. }
  511. func (m *Mirror) AfterSet(colName string, _ xorm.Cell) {
  512. var err error
  513. switch colName {
  514. case "repo_id":
  515. m.Repo, err = GetRepositoryByID(m.RepoID)
  516. if err != nil {
  517. log.Error(3, "GetRepositoryByID[%d]: %v", m.ID, err)
  518. }
  519. case "updated_unix":
  520. m.Updated = time.Unix(m.UpdatedUnix, 0).Local()
  521. case "next_updated_unix":
  522. m.NextUpdate = time.Unix(m.NextUpdateUnix, 0).Local()
  523. }
  524. }
  525. func (m *Mirror) readAddress() {
  526. if len(m.address) > 0 {
  527. return
  528. }
  529. cfg, err := ini.Load(m.Repo.GitConfigPath())
  530. if err != nil {
  531. log.Error(4, "Load: %v", err)
  532. return
  533. }
  534. m.address = cfg.Section("remote \"origin\"").Key("url").Value()
  535. }
  536. // HandleCloneUserCredentials replaces user credentials from HTTP/HTTPS URL
  537. // with placeholder <credentials>.
  538. // It will fail for any other forms of clone addresses.
  539. func HandleCloneUserCredentials(url string, mosaics bool) string {
  540. i := strings.Index(url, "@")
  541. if i == -1 {
  542. return url
  543. }
  544. start := strings.Index(url, "://")
  545. if start == -1 {
  546. return url
  547. }
  548. if mosaics {
  549. return url[:start+3] + "<credentials>" + url[i:]
  550. }
  551. return url[:start+3] + url[i+1:]
  552. }
  553. // Address returns mirror address from Git repository config without credentials.
  554. func (m *Mirror) Address() string {
  555. m.readAddress()
  556. return HandleCloneUserCredentials(m.address, false)
  557. }
  558. // FullAddress returns mirror address from Git repository config.
  559. func (m *Mirror) FullAddress() string {
  560. m.readAddress()
  561. return m.address
  562. }
  563. // SaveAddress writes new address to Git repository config.
  564. func (m *Mirror) SaveAddress(addr string) error {
  565. configPath := m.Repo.GitConfigPath()
  566. cfg, err := ini.Load(configPath)
  567. if err != nil {
  568. return fmt.Errorf("Load: %v", err)
  569. }
  570. cfg.Section("remote \"origin\"").Key("url").SetValue(addr)
  571. return cfg.SaveToIndent(configPath, "\t")
  572. }
  573. func getMirror(e Engine, repoId int64) (*Mirror, error) {
  574. m := &Mirror{RepoID: repoId}
  575. has, err := e.Get(m)
  576. if err != nil {
  577. return nil, err
  578. } else if !has {
  579. return nil, ErrMirrorNotExist
  580. }
  581. return m, nil
  582. }
  583. // GetMirror returns mirror object by given repository ID.
  584. func GetMirror(repoId int64) (*Mirror, error) {
  585. return getMirror(x, repoId)
  586. }
  587. func updateMirror(e Engine, m *Mirror) error {
  588. _, err := e.Id(m.ID).AllCols().Update(m)
  589. return err
  590. }
  591. func UpdateMirror(m *Mirror) error {
  592. return updateMirror(x, m)
  593. }
  594. func DeleteMirrorByRepoID(repoID int64) error {
  595. _, err := x.Delete(&Mirror{RepoID: repoID})
  596. return err
  597. }
  598. func createUpdateHook(repoPath string) error {
  599. return git.SetUpdateHook(repoPath,
  600. fmt.Sprintf(_TPL_UPDATE_HOOK, setting.ScriptType, "\""+setting.AppPath+"\"", setting.CustomConf))
  601. }
  602. type MigrateRepoOptions struct {
  603. Name string
  604. Description string
  605. IsPrivate bool
  606. IsMirror bool
  607. RemoteAddr string
  608. }
  609. /*
  610. GitHub, GitLab, Gogs: *.wiki.git
  611. BitBucket: *.git/wiki
  612. */
  613. var commonWikiURLSuffixes = []string{".wiki.git", ".git/wiki"}
  614. // wikiRemoteURL returns accessible repository URL for wiki if exists.
  615. // Otherwise, it returns an empty string.
  616. func wikiRemoteURL(remote string) string {
  617. remote = strings.TrimSuffix(remote, ".git")
  618. for _, suffix := range commonWikiURLSuffixes {
  619. wikiURL := remote + suffix
  620. if git.IsRepoURLAccessible(wikiURL) {
  621. return wikiURL
  622. }
  623. }
  624. return ""
  625. }
  626. // MigrateRepository migrates a existing repository from other project hosting.
  627. func MigrateRepository(u *User, opts MigrateRepoOptions) (*Repository, error) {
  628. repo, err := CreateRepository(u, CreateRepoOptions{
  629. Name: opts.Name,
  630. Description: opts.Description,
  631. IsPrivate: opts.IsPrivate,
  632. IsMirror: opts.IsMirror,
  633. })
  634. if err != nil {
  635. return nil, err
  636. }
  637. // Clone to temprory path and do the init commit.
  638. tmpDir := filepath.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond()))
  639. os.MkdirAll(tmpDir, os.ModePerm)
  640. repoPath := RepoPath(u.Name, opts.Name)
  641. wikiPath := WikiPath(u.Name, opts.Name)
  642. if u.IsOrganization() {
  643. t, err := u.GetOwnerTeam()
  644. if err != nil {
  645. return nil, err
  646. }
  647. repo.NumWatches = t.NumMembers
  648. } else {
  649. repo.NumWatches = 1
  650. }
  651. migrateTimeout := time.Duration(setting.Git.Timeout.Migrate) * time.Second
  652. os.RemoveAll(repoPath)
  653. if err = git.Clone(opts.RemoteAddr, repoPath, git.CloneRepoOptions{
  654. Mirror: true,
  655. Quiet: true,
  656. Timeout: migrateTimeout,
  657. }); err != nil {
  658. return repo, fmt.Errorf("Clone: %v", err)
  659. }
  660. wikiRemotePath := wikiRemoteURL(opts.RemoteAddr)
  661. if len(wikiRemotePath) > 0 {
  662. os.RemoveAll(wikiPath)
  663. if err = git.Clone(wikiRemotePath, wikiPath, git.CloneRepoOptions{
  664. Mirror: true,
  665. Quiet: true,
  666. Timeout: migrateTimeout,
  667. }); err != nil {
  668. log.Info("Clone wiki: %v", err)
  669. }
  670. }
  671. // Check if repository is empty.
  672. _, stderr, err := com.ExecCmdDir(repoPath, "git", "log", "-1")
  673. if err != nil {
  674. if strings.Contains(stderr, "fatal: bad default revision 'HEAD'") {
  675. repo.IsBare = true
  676. } else {
  677. return repo, fmt.Errorf("check bare: %v - %s", err, stderr)
  678. }
  679. }
  680. if !repo.IsBare {
  681. // Try to get HEAD branch and set it as default branch.
  682. gitRepo, err := git.OpenRepository(repoPath)
  683. if err != nil {
  684. return repo, fmt.Errorf("OpenRepository: %v", err)
  685. }
  686. headBranch, err := gitRepo.GetHEADBranch()
  687. if err != nil {
  688. return repo, fmt.Errorf("GetHEADBranch: %v", err)
  689. }
  690. if headBranch != nil {
  691. repo.DefaultBranch = headBranch.Name
  692. }
  693. }
  694. if opts.IsMirror {
  695. if _, err = x.InsertOne(&Mirror{
  696. RepoID: repo.ID,
  697. Interval: setting.Mirror.DefaultInterval,
  698. EnablePrune: true,
  699. NextUpdate: time.Now().Add(time.Duration(setting.Mirror.DefaultInterval) * time.Hour),
  700. }); err != nil {
  701. return repo, fmt.Errorf("InsertOne: %v", err)
  702. }
  703. repo.IsMirror = true
  704. return repo, UpdateRepository(repo, false)
  705. }
  706. return CleanUpMigrateInfo(repo)
  707. }
  708. // cleanUpMigrateGitConfig removes mirror info which prevents "push --all".
  709. // This also removes possible user credentials.
  710. func cleanUpMigrateGitConfig(configPath string) error {
  711. cfg, err := ini.Load(configPath)
  712. if err != nil {
  713. return fmt.Errorf("open config file: %v", err)
  714. }
  715. cfg.DeleteSection("remote \"origin\"")
  716. if err = cfg.SaveToIndent(configPath, "\t"); err != nil {
  717. return fmt.Errorf("save config file: %v", err)
  718. }
  719. return nil
  720. }
  721. // Finish migrating repository and/or wiki with things that don't need to be done for mirrors.
  722. func CleanUpMigrateInfo(repo *Repository) (*Repository, error) {
  723. repoPath := repo.RepoPath()
  724. if err := createUpdateHook(repoPath); err != nil {
  725. return repo, fmt.Errorf("createUpdateHook: %v", err)
  726. }
  727. if repo.HasWiki() {
  728. if err := createUpdateHook(repo.WikiPath()); err != nil {
  729. return repo, fmt.Errorf("createUpdateHook (wiki): %v", err)
  730. }
  731. }
  732. if err := cleanUpMigrateGitConfig(repo.GitConfigPath()); err != nil {
  733. return repo, fmt.Errorf("cleanUpMigrateGitConfig: %v", err)
  734. }
  735. if repo.HasWiki() {
  736. if err := cleanUpMigrateGitConfig(path.Join(repo.WikiPath(), "config")); err != nil {
  737. return repo, fmt.Errorf("cleanUpMigrateGitConfig (wiki): %v", err)
  738. }
  739. }
  740. return repo, UpdateRepository(repo, false)
  741. }
  742. // initRepoCommit temporarily changes with work directory.
  743. func initRepoCommit(tmpPath string, sig *git.Signature) (err error) {
  744. var stderr string
  745. if _, stderr, err = process.ExecDir(-1,
  746. tmpPath, fmt.Sprintf("initRepoCommit (git add): %s", tmpPath),
  747. "git", "add", "--all"); err != nil {
  748. return fmt.Errorf("git add: %s", stderr)
  749. }
  750. if _, stderr, err = process.ExecDir(-1,
  751. tmpPath, fmt.Sprintf("initRepoCommit (git commit): %s", tmpPath),
  752. "git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email),
  753. "-m", "Initial commit"); err != nil {
  754. return fmt.Errorf("git commit: %s", stderr)
  755. }
  756. if _, stderr, err = process.ExecDir(-1,
  757. tmpPath, fmt.Sprintf("initRepoCommit (git push): %s", tmpPath),
  758. "git", "push", "origin", "master"); err != nil {
  759. return fmt.Errorf("git push: %s", stderr)
  760. }
  761. return nil
  762. }
  763. type CreateRepoOptions struct {
  764. Name string
  765. Description string
  766. Gitignores string
  767. License string
  768. Readme string
  769. IsPrivate bool
  770. IsMirror bool
  771. AutoInit bool
  772. }
  773. func getRepoInitFile(tp, name string) ([]byte, error) {
  774. relPath := path.Join("conf", tp, strings.TrimLeft(name, "./"))
  775. // Use custom file when available.
  776. customPath := path.Join(setting.CustomPath, relPath)
  777. if com.IsFile(customPath) {
  778. return ioutil.ReadFile(customPath)
  779. }
  780. return bindata.Asset(relPath)
  781. }
  782. func prepareRepoCommit(repo *Repository, tmpDir, repoPath string, opts CreateRepoOptions) error {
  783. // Clone to temprory path and do the init commit.
  784. _, stderr, err := process.Exec(
  785. fmt.Sprintf("initRepository(git clone): %s", repoPath), "git", "clone", repoPath, tmpDir)
  786. if err != nil {
  787. return fmt.Errorf("git clone: %v - %s", err, stderr)
  788. }
  789. // README
  790. data, err := getRepoInitFile("readme", opts.Readme)
  791. if err != nil {
  792. return fmt.Errorf("getRepoInitFile[%s]: %v", opts.Readme, err)
  793. }
  794. cloneLink := repo.CloneLink()
  795. match := map[string]string{
  796. "Name": repo.Name,
  797. "Description": repo.Description,
  798. "CloneURL.SSH": cloneLink.SSH,
  799. "CloneURL.HTTPS": cloneLink.HTTPS,
  800. }
  801. if err = ioutil.WriteFile(filepath.Join(tmpDir, "README.md"),
  802. []byte(com.Expand(string(data), match)), 0644); err != nil {
  803. return fmt.Errorf("write README.md: %v", err)
  804. }
  805. // .gitignore
  806. if len(opts.Gitignores) > 0 {
  807. var buf bytes.Buffer
  808. names := strings.Split(opts.Gitignores, ",")
  809. for _, name := range names {
  810. data, err = getRepoInitFile("gitignore", name)
  811. if err != nil {
  812. return fmt.Errorf("getRepoInitFile[%s]: %v", name, err)
  813. }
  814. buf.WriteString("# ---> " + name + "\n")
  815. buf.Write(data)
  816. buf.WriteString("\n")
  817. }
  818. if buf.Len() > 0 {
  819. if err = ioutil.WriteFile(filepath.Join(tmpDir, ".gitignore"), buf.Bytes(), 0644); err != nil {
  820. return fmt.Errorf("write .gitignore: %v", err)
  821. }
  822. }
  823. }
  824. // LICENSE
  825. if len(opts.License) > 0 {
  826. data, err = getRepoInitFile("license", opts.License)
  827. if err != nil {
  828. return fmt.Errorf("getRepoInitFile[%s]: %v", opts.License, err)
  829. }
  830. if err = ioutil.WriteFile(filepath.Join(tmpDir, "LICENSE"), data, 0644); err != nil {
  831. return fmt.Errorf("write LICENSE: %v", err)
  832. }
  833. }
  834. return nil
  835. }
  836. // InitRepository initializes README and .gitignore if needed.
  837. func initRepository(e Engine, repoPath string, u *User, repo *Repository, opts CreateRepoOptions) (err error) {
  838. // Somehow the directory could exist.
  839. if com.IsExist(repoPath) {
  840. return fmt.Errorf("initRepository: path already exists: %s", repoPath)
  841. }
  842. // Init bare new repository.
  843. if err = git.InitRepository(repoPath, true); err != nil {
  844. return fmt.Errorf("InitRepository: %v", err)
  845. } else if err = createUpdateHook(repoPath); err != nil {
  846. return fmt.Errorf("createUpdateHook: %v", err)
  847. }
  848. tmpDir := filepath.Join(os.TempDir(), "gogs-"+repo.Name+"-"+com.ToStr(time.Now().Nanosecond()))
  849. // Initialize repository according to user's choice.
  850. if opts.AutoInit {
  851. os.MkdirAll(tmpDir, os.ModePerm)
  852. defer os.RemoveAll(tmpDir)
  853. if err = prepareRepoCommit(repo, tmpDir, repoPath, opts); err != nil {
  854. return fmt.Errorf("prepareRepoCommit: %v", err)
  855. }
  856. // Apply changes and commit.
  857. if err = initRepoCommit(tmpDir, u.NewGitSig()); err != nil {
  858. return fmt.Errorf("initRepoCommit: %v", err)
  859. }
  860. }
  861. // Re-fetch the repository from database before updating it (else it would
  862. // override changes that were done earlier with sql)
  863. if repo, err = getRepositoryByID(e, repo.ID); err != nil {
  864. return fmt.Errorf("getRepositoryByID: %v", err)
  865. }
  866. if !opts.AutoInit {
  867. repo.IsBare = true
  868. }
  869. repo.DefaultBranch = "master"
  870. if err = updateRepository(e, repo, false); err != nil {
  871. return fmt.Errorf("updateRepository: %v", err)
  872. }
  873. return nil
  874. }
  875. var (
  876. reservedRepoNames = []string{".", ".."}
  877. reservedRepoPatterns = []string{"*.git", "*.wiki"}
  878. )
  879. func IsUsableRepoName(name string) error {
  880. return isUsableName(reservedRepoNames, reservedRepoPatterns, name)
  881. }
  882. func createRepository(e *xorm.Session, u *User, repo *Repository) (err error) {
  883. if err = IsUsableRepoName(repo.Name); err != nil {
  884. return err
  885. }
  886. has, err := isRepositoryExist(e, u, repo.Name)
  887. if err != nil {
  888. return fmt.Errorf("IsRepositoryExist: %v", err)
  889. } else if has {
  890. return ErrRepoAlreadyExist{u.Name, repo.Name}
  891. }
  892. if _, err = e.Insert(repo); err != nil {
  893. return err
  894. }
  895. u.NumRepos++
  896. // Remember visibility preference.
  897. u.LastRepoVisibility = repo.IsPrivate
  898. if err = updateUser(e, u); err != nil {
  899. return fmt.Errorf("updateUser: %v", err)
  900. }
  901. // Give access to all members in owner team.
  902. if u.IsOrganization() {
  903. t, err := u.getOwnerTeam(e)
  904. if err != nil {
  905. return fmt.Errorf("getOwnerTeam: %v", err)
  906. } else if err = t.addRepository(e, repo); err != nil {
  907. return fmt.Errorf("addRepository: %v", err)
  908. }
  909. } else {
  910. // Organization automatically called this in addRepository method.
  911. if err = repo.recalculateAccesses(e); err != nil {
  912. return fmt.Errorf("recalculateAccesses: %v", err)
  913. }
  914. }
  915. if err = watchRepo(e, u.ID, repo.ID, true); err != nil {
  916. return fmt.Errorf("watchRepo: %v", err)
  917. } else if err = newRepoAction(e, u, repo); err != nil {
  918. return fmt.Errorf("newRepoAction: %v", err)
  919. }
  920. return nil
  921. }
  922. // CreateRepository creates a repository for given user or organization.
  923. func CreateRepository(u *User, opts CreateRepoOptions) (_ *Repository, err error) {
  924. if !u.CanCreateRepo() {
  925. return nil, ErrReachLimitOfRepo{u.MaxRepoCreation}
  926. }
  927. repo := &Repository{
  928. OwnerID: u.ID,
  929. Owner: u,
  930. Name: opts.Name,
  931. LowerName: strings.ToLower(opts.Name),
  932. Description: opts.Description,
  933. IsPrivate: opts.IsPrivate,
  934. EnableWiki: true,
  935. EnableIssues: true,
  936. EnablePulls: true,
  937. }
  938. sess := x.NewSession()
  939. defer sessionRelease(sess)
  940. if err = sess.Begin(); err != nil {
  941. return nil, err
  942. }
  943. if err = createRepository(sess, u, repo); err != nil {
  944. return nil, err
  945. }
  946. // No need for init mirror.
  947. if !opts.IsMirror {
  948. repoPath := RepoPath(u.Name, repo.Name)
  949. if err = initRepository(sess, repoPath, u, repo, opts); err != nil {
  950. if err2 := os.RemoveAll(repoPath); err2 != nil {
  951. log.Error(4, "initRepository: %v", err)
  952. return nil, fmt.Errorf(
  953. "delete repo directory %s/%s failed(2): %v", u.Name, repo.Name, err2)
  954. }
  955. return nil, fmt.Errorf("initRepository: %v", err)
  956. }
  957. _, stderr, err := process.ExecDir(-1,
  958. repoPath, fmt.Sprintf("CreateRepository(git update-server-info): %s", repoPath),
  959. "git", "update-server-info")
  960. if err != nil {
  961. return nil, errors.New("CreateRepository(git update-server-info): " + stderr)
  962. }
  963. }
  964. return repo, sess.Commit()
  965. }
  966. func countRepositories(userID int64, private bool) int64 {
  967. sess := x.Where("id > 0")
  968. if userID > 0 {
  969. sess.And("owner_id = ?", userID)
  970. }
  971. if !private {
  972. sess.And("is_private=?", false)
  973. }
  974. count, err := sess.Count(new(Repository))
  975. if err != nil {
  976. log.Error(4, "countRepositories: %v", err)
  977. }
  978. return count
  979. }
  980. // CountRepositories returns number of repositories.
  981. // Argument private only takes effect when it is false,
  982. // set it true to count all repositories.
  983. func CountRepositories(private bool) int64 {
  984. return countRepositories(-1, private)
  985. }
  986. // CountUserRepositories returns number of repositories user owns.
  987. // Argument private only takes effect when it is false,
  988. // set it true to count all repositories.
  989. func CountUserRepositories(userID int64, private bool) int64 {
  990. return countRepositories(userID, private)
  991. }
  992. func Repositories(page, pageSize int) (_ []*Repository, err error) {
  993. repos := make([]*Repository, 0, pageSize)
  994. return repos, x.Limit(pageSize, (page-1)*pageSize).Asc("id").Find(&repos)
  995. }
  996. // RepositoriesWithUsers returns number of repos in given page.
  997. func RepositoriesWithUsers(page, pageSize int) (_ []*Repository, err error) {
  998. repos, err := Repositories(page, pageSize)
  999. if err != nil {
  1000. return nil, fmt.Errorf("Repositories: %v", err)
  1001. }
  1002. for i := range repos {
  1003. if err = repos[i].GetOwner(); err != nil {
  1004. return nil, err
  1005. }
  1006. }
  1007. return repos, nil
  1008. }
  1009. // RepoPath returns repository path by given user and repository name.
  1010. func RepoPath(userName, repoName string) string {
  1011. return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".git")
  1012. }
  1013. // TransferOwnership transfers all corresponding setting from old user to new one.
  1014. func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error {
  1015. newOwner, err := GetUserByName(newOwnerName)
  1016. if err != nil {
  1017. return fmt.Errorf("get new owner '%s': %v", newOwnerName, err)
  1018. }
  1019. // Check if new owner has repository with same name.
  1020. has, err := IsRepositoryExist(newOwner, repo.Name)
  1021. if err != nil {
  1022. return fmt.Errorf("IsRepositoryExist: %v", err)
  1023. } else if has {
  1024. return ErrRepoAlreadyExist{newOwnerName, repo.Name}
  1025. }
  1026. sess := x.NewSession()
  1027. defer sessionRelease(sess)
  1028. if err = sess.Begin(); err != nil {
  1029. return fmt.Errorf("sess.Begin: %v", err)
  1030. }
  1031. owner := repo.Owner
  1032. // Note: we have to set value here to make sure recalculate accesses is based on
  1033. // new owner.
  1034. repo.OwnerID = newOwner.ID
  1035. repo.Owner = newOwner
  1036. // Update repository.
  1037. if _, err := sess.Id(repo.ID).Update(repo); err != nil {
  1038. return fmt.Errorf("update owner: %v", err)
  1039. }
  1040. // Remove redundant collaborators.
  1041. collaborators, err := repo.getCollaborators(sess)
  1042. if err != nil {
  1043. return fmt.Errorf("getCollaborators: %v", err)
  1044. }
  1045. // Dummy object.
  1046. collaboration := &Collaboration{RepoID: repo.ID}
  1047. for _, c := range collaborators {
  1048. collaboration.UserID = c.ID
  1049. if c.ID == newOwner.ID || newOwner.IsOrgMember(c.ID) {
  1050. if _, err = sess.Delete(collaboration); err != nil {
  1051. return fmt.Errorf("remove collaborator '%d': %v", c.ID, err)
  1052. }
  1053. }
  1054. }
  1055. // Remove old team-repository relations.
  1056. if owner.IsOrganization() {
  1057. if err = owner.getTeams(sess); err != nil {
  1058. return fmt.Errorf("getTeams: %v", err)
  1059. }
  1060. for _, t := range owner.Teams {
  1061. if !t.hasRepository(sess, repo.ID) {
  1062. continue
  1063. }
  1064. t.NumRepos--
  1065. if _, err := sess.Id(t.ID).AllCols().Update(t); err != nil {
  1066. return fmt.Errorf("decrease team repository count '%d': %v", t.ID, err)
  1067. }
  1068. }
  1069. if err = owner.removeOrgRepo(sess, repo.ID); err != nil {
  1070. return fmt.Errorf("removeOrgRepo: %v", err)
  1071. }
  1072. }
  1073. if newOwner.IsOrganization() {
  1074. t, err := newOwner.getOwnerTeam(sess)
  1075. if err != nil {
  1076. return fmt.Errorf("getOwnerTeam: %v", err)
  1077. } else if err = t.addRepository(sess, repo); err != nil {
  1078. return fmt.Errorf("add to owner team: %v", err)
  1079. }
  1080. } else {
  1081. // Organization called this in addRepository method.
  1082. if err = repo.recalculateAccesses(sess); err != nil {
  1083. return fmt.Errorf("recalculateAccesses: %v", err)
  1084. }
  1085. }
  1086. // Update repository count.
  1087. if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos+1 WHERE id=?", newOwner.ID); err != nil {
  1088. return fmt.Errorf("increase new owner repository count: %v", err)
  1089. } else if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", owner.ID); err != nil {
  1090. return fmt.Errorf("decrease old owner repository count: %v", err)
  1091. }
  1092. if err = watchRepo(sess, newOwner.ID, repo.ID, true); err != nil {
  1093. return fmt.Errorf("watchRepo: %v", err)
  1094. } else if err = transferRepoAction(sess, doer, owner, repo); err != nil {
  1095. return fmt.Errorf("transferRepoAction: %v", err)
  1096. }
  1097. // Rename remote repository to new path and delete local copy.
  1098. os.MkdirAll(UserPath(newOwner.Name), os.ModePerm)
  1099. if err = os.Rename(RepoPath(owner.Name, repo.Name), RepoPath(newOwner.Name, repo.Name)); err != nil {
  1100. return fmt.Errorf("rename repository directory: %v", err)
  1101. }
  1102. RemoveAllWithNotice("Delete repository local copy", repo.LocalCopyPath())
  1103. // Rename remote wiki repository to new path and delete local copy.
  1104. wikiPath := WikiPath(owner.Name, repo.Name)
  1105. if com.IsExist(wikiPath) {
  1106. RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath())
  1107. if err = os.Rename(wikiPath, WikiPath(newOwner.Name, repo.Name)); err != nil {
  1108. return fmt.Errorf("rename repository wiki: %v", err)
  1109. }
  1110. }
  1111. return sess.Commit()
  1112. }
  1113. // ChangeRepositoryName changes all corresponding setting from old repository name to new one.
  1114. func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error) {
  1115. oldRepoName = strings.ToLower(oldRepoName)
  1116. newRepoName = strings.ToLower(newRepoName)
  1117. if err = IsUsableRepoName(newRepoName); err != nil {
  1118. return err
  1119. }
  1120. has, err := IsRepositoryExist(u, newRepoName)
  1121. if err != nil {
  1122. return fmt.Errorf("IsRepositoryExist: %v", err)
  1123. } else if has {
  1124. return ErrRepoAlreadyExist{u.Name, newRepoName}
  1125. }
  1126. repo, err := GetRepositoryByName(u.ID, oldRepoName)
  1127. if err != nil {
  1128. return fmt.Errorf("GetRepositoryByName: %v", err)
  1129. }
  1130. // Change repository directory name.
  1131. if err = os.Rename(repo.RepoPath(), RepoPath(u.Name, newRepoName)); err != nil {
  1132. return fmt.Errorf("rename repository directory: %v", err)
  1133. }
  1134. wikiPath := repo.WikiPath()
  1135. if com.IsExist(wikiPath) {
  1136. if err = os.Rename(wikiPath, WikiPath(u.Name, newRepoName)); err != nil {
  1137. return fmt.Errorf("rename repository wiki: %v", err)
  1138. }
  1139. RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath())
  1140. }
  1141. return nil
  1142. }
  1143. func getRepositoriesByForkID(e Engine, forkID int64) ([]*Repository, error) {
  1144. repos := make([]*Repository, 0, 10)
  1145. return repos, e.Where("fork_id=?", forkID).Find(&repos)
  1146. }
  1147. // GetRepositoriesByForkID returns all repositories with given fork ID.
  1148. func GetRepositoriesByForkID(forkID int64) ([]*Repository, error) {
  1149. return getRepositoriesByForkID(x, forkID)
  1150. }
  1151. func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err error) {
  1152. repo.LowerName = strings.ToLower(repo.Name)
  1153. if len(repo.Description) > 255 {
  1154. repo.Description = repo.Description[:255]
  1155. }
  1156. if len(repo.Website) > 255 {
  1157. repo.Website = repo.Website[:255]
  1158. }
  1159. if _, err = e.Id(repo.ID).AllCols().Update(repo); err != nil {
  1160. return fmt.Errorf("update: %v", err)
  1161. }
  1162. if visibilityChanged {
  1163. if err = repo.getOwner(e); err != nil {
  1164. return fmt.Errorf("getOwner: %v", err)
  1165. }
  1166. if repo.Owner.IsOrganization() {
  1167. // Organization repository need to recalculate access table when visivility is changed.
  1168. if err = repo.recalculateTeamAccesses(e, 0); err != nil {
  1169. return fmt.Errorf("recalculateTeamAccesses: %v", err)
  1170. }
  1171. }
  1172. // Create/Remove git-daemon-export-ok for git-daemon...
  1173. daemonExportFile := path.Join(repo.RepoPath(), `git-daemon-export-ok`)
  1174. if repo.IsPrivate && com.IsExist(daemonExportFile) {
  1175. if err = os.Remove(daemonExportFile); err != nil {
  1176. log.Error(4, "Failed to remove %s: %v", daemonExportFile, err)
  1177. }
  1178. } else if !repo.IsPrivate && !com.IsExist(daemonExportFile) {
  1179. if f, err := os.Create(daemonExportFile); err != nil {
  1180. log.Error(4, "Failed to create %s: %v", daemonExportFile, err)
  1181. } else {
  1182. f.Close()
  1183. }
  1184. }
  1185. forkRepos, err := getRepositoriesByForkID(e, repo.ID)
  1186. if err != nil {
  1187. return fmt.Errorf("getRepositoriesByForkID: %v", err)
  1188. }
  1189. for i := range forkRepos {
  1190. forkRepos[i].IsPrivate = repo.IsPrivate
  1191. if err = updateRepository(e, forkRepos[i], true); err != nil {
  1192. return fmt.Errorf("updateRepository[%d]: %v", forkRepos[i].ID, err)
  1193. }
  1194. }
  1195. }
  1196. return nil
  1197. }
  1198. func UpdateRepository(repo *Repository, visibilityChanged bool) (err error) {
  1199. sess := x.NewSession()
  1200. defer sessionRelease(sess)
  1201. if err = sess.Begin(); err != nil {
  1202. return err
  1203. }
  1204. if err = updateRepository(x, repo, visibilityChanged); err != nil {
  1205. return fmt.Errorf("updateRepository: %v", err)
  1206. }
  1207. return sess.Commit()
  1208. }
  1209. // DeleteRepository deletes a repository for a user or organization.
  1210. func DeleteRepository(uid, repoID int64) error {
  1211. repo := &Repository{ID: repoID, OwnerID: uid}
  1212. has, err := x.Get(repo)
  1213. if err != nil {
  1214. return err
  1215. } else if !has {
  1216. return ErrRepoNotExist{repoID, uid, ""}
  1217. }
  1218. // In case is a organization.
  1219. org, err := GetUserByID(uid)
  1220. if err != nil {
  1221. return err
  1222. }
  1223. if org.IsOrganization() {
  1224. if err = org.GetTeams(); err != nil {
  1225. return err
  1226. }
  1227. }
  1228. sess := x.NewSession()
  1229. defer sessionRelease(sess)
  1230. if err = sess.Begin(); err != nil {
  1231. return err
  1232. }
  1233. if org.IsOrganization() {
  1234. for _, t := range org.Teams {
  1235. if !t.hasRepository(sess, repoID) {
  1236. continue
  1237. } else if err = t.removeRepository(sess, repo, false); err != nil {
  1238. return err
  1239. }
  1240. }
  1241. }
  1242. if err = deleteBeans(sess,
  1243. &Repository{ID: repoID},
  1244. &Access{RepoID: repo.ID},
  1245. &Action{RepoID: repo.ID},
  1246. &Watch{RepoID: repoID},
  1247. &Star{RepoID: repoID},
  1248. &Mirror{RepoID: repoID},
  1249. &IssueUser{RepoID: repoID},
  1250. &Milestone{RepoID: repoID},
  1251. &Release{RepoID: repoID},
  1252. &Collaboration{RepoID: repoID},
  1253. &PullRequest{BaseRepoID: repoID},
  1254. ); err != nil {
  1255. return fmt.Errorf("deleteBeans: %v", err)
  1256. }
  1257. // Delete comments and attachments.
  1258. issues := make([]*Issue, 0, 25)
  1259. attachmentPaths := make([]string, 0, len(issues))
  1260. if err = sess.Where("repo_id=?", repoID).Find(&issues); err != nil {
  1261. return err
  1262. }
  1263. for i := range issues {
  1264. if _, err = sess.Delete(&Comment{IssueID: issues[i].ID}); err != nil {
  1265. return err
  1266. }
  1267. attachments := make([]*Attachment, 0, 5)
  1268. if err = sess.Where("issue_id=?", issues[i].ID).Find(&attachments); err != nil {
  1269. return err
  1270. }
  1271. for j := range attachments {
  1272. attachmentPaths = append(attachmentPaths, attachments[j].LocalPath())
  1273. }
  1274. if _, err = sess.Delete(&Attachment{IssueID: issues[i].ID}); err != nil {
  1275. return err
  1276. }
  1277. }
  1278. if _, err = sess.Delete(&Issue{RepoID: repoID}); err != nil {
  1279. return err
  1280. }
  1281. if repo.IsFork {
  1282. if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks-1 WHERE id=?", repo.ForkID); err != nil {
  1283. return fmt.Errorf("decrease fork count: %v", err)
  1284. }
  1285. }
  1286. if _, err = sess.Exec("UPDATE `user` SET num_repos=num_repos-1 WHERE id=?", uid); err != nil {
  1287. return err
  1288. }
  1289. // Remove repository files.
  1290. repoPath := repo.repoPath(sess)
  1291. RemoveAllWithNotice("Delete repository files", repoPath)
  1292. repo.DeleteWiki()
  1293. // Remove attachment files.
  1294. for i := range attachmentPaths {
  1295. RemoveAllWithNotice("Delete attachment", attachmentPaths[i])
  1296. }
  1297. if err = sess.Commit(); err != nil {
  1298. return fmt.Errorf("Commit: %v", err)
  1299. }
  1300. if repo.NumForks > 0 {
  1301. if _, err = x.Exec("UPDATE `repository` SET fork_id=0,is_fork=? WHERE fork_id=?", false, repo.ID); err != nil {
  1302. log.Error(4, "reset 'fork_id' and 'is_fork': %v", err)
  1303. }
  1304. }
  1305. return nil
  1306. }
  1307. // GetRepositoryByRef returns a Repository specified by a GFM reference.
  1308. // See https://help.github.com/articles/writing-on-github#references for more information on the syntax.
  1309. func GetRepositoryByRef(ref string) (*Repository, error) {
  1310. n := strings.IndexByte(ref, byte('/'))
  1311. if n < 2 {
  1312. return nil, ErrInvalidReference
  1313. }
  1314. userName, repoName := ref[:n], ref[n+1:]
  1315. user, err := GetUserByName(userName)
  1316. if err != nil {
  1317. return nil, err
  1318. }
  1319. return GetRepositoryByName(user.ID, repoName)
  1320. }
  1321. // GetRepositoryByName returns the repository by given name under user if exists.
  1322. func GetRepositoryByName(ownerID int64, name string) (*Repository, error) {
  1323. repo := &Repository{
  1324. OwnerID: ownerID,
  1325. LowerName: strings.ToLower(name),
  1326. }
  1327. has, err := x.Get(repo)
  1328. if err != nil {
  1329. return nil, err
  1330. } else if !has {
  1331. return nil, ErrRepoNotExist{0, ownerID, name}
  1332. }
  1333. return repo, err
  1334. }
  1335. func getRepositoryByID(e Engine, id int64) (*Repository, error) {
  1336. repo := new(Repository)
  1337. has, err := e.Id(id).Get(repo)
  1338. if err != nil {
  1339. return nil, err
  1340. } else if !has {
  1341. return nil, ErrRepoNotExist{id, 0, ""}
  1342. }
  1343. return repo, nil
  1344. }
  1345. // GetRepositoryByID returns the repository by given id if exists.
  1346. func GetRepositoryByID(id int64) (*Repository, error) {
  1347. return getRepositoryByID(x, id)
  1348. }
  1349. // GetUserRepositories returns a list of repositories of given user.
  1350. func GetUserRepositories(userID int64, private bool, page, pageSize int) ([]*Repository, error) {
  1351. sess := x.Where("owner_id = ?", userID).Desc("updated_unix")
  1352. if !private {
  1353. sess.And("is_private=?", false)
  1354. }
  1355. if page <= 0 {
  1356. page = 1
  1357. }
  1358. sess.Limit(pageSize, (page-1)*pageSize)
  1359. repos := make([]*Repository, 0, pageSize)
  1360. return repos, sess.Find(&repos)
  1361. }
  1362. // GetUserRepositories returns a list of mirror repositories of given user.
  1363. func GetUserMirrorRepositories(userID int64) ([]*Repository, error) {
  1364. repos := make([]*Repository, 0, 10)
  1365. return repos, x.Where("owner_id = ?", userID).And("is_mirror = ?", true).Find(&repos)
  1366. }
  1367. // GetRecentUpdatedRepositories returns the list of repositories that are recently updated.
  1368. func GetRecentUpdatedRepositories(page, pageSize int) (repos []*Repository, err error) {
  1369. return repos, x.Limit(pageSize, (page-1)*pageSize).
  1370. Where("is_private=?", false).Limit(pageSize).Desc("updated_unix").Find(&repos)
  1371. }
  1372. func getRepositoryCount(e Engine, u *User) (int64, error) {
  1373. return x.Count(&Repository{OwnerID: u.ID})
  1374. }
  1375. // GetRepositoryCount returns the total number of repositories of user.
  1376. func GetRepositoryCount(u *User) (int64, error) {
  1377. return getRepositoryCount(x, u)
  1378. }
  1379. type SearchRepoOptions struct {
  1380. Keyword string
  1381. OwnerID int64
  1382. OrderBy string
  1383. Private bool // Include private repositories in results
  1384. Page int
  1385. PageSize int // Can be smaller than or equal to setting.ExplorePagingNum
  1386. }
  1387. // SearchRepositoryByName takes keyword and part of repository name to search,
  1388. // it returns results in given range and number of total results.
  1389. func SearchRepositoryByName(opts *SearchRepoOptions) (repos []*Repository, _ int64, _ error) {
  1390. if len(opts.Keyword) == 0 {
  1391. return repos, 0, nil
  1392. }
  1393. opts.Keyword = strings.ToLower(opts.Keyword)
  1394. if opts.Page <= 0 {
  1395. opts.Page = 1
  1396. }
  1397. repos = make([]*Repository, 0, opts.PageSize)
  1398. // Append conditions
  1399. sess := x.Where("LOWER(lower_name) LIKE ?", "%"+opts.Keyword+"%")
  1400. if opts.OwnerID > 0 {
  1401. sess.And("owner_id = ?", opts.OwnerID)
  1402. }
  1403. if !opts.Private {
  1404. sess.And("is_private=?", false)
  1405. }
  1406. var countSess xorm.Session
  1407. countSess = *sess
  1408. count, err := countSess.Count(new(Repository))
  1409. if err != nil {
  1410. return nil, 0, fmt.Errorf("Count: %v", err)
  1411. }
  1412. if len(opts.OrderBy) > 0 {
  1413. sess.OrderBy(opts.OrderBy)
  1414. }
  1415. return repos, count, sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize).Find(&repos)
  1416. }
  1417. // DeleteRepositoryArchives deletes all repositories' archives.
  1418. func DeleteRepositoryArchives() error {
  1419. return x.Where("id > 0").Iterate(new(Repository),
  1420. func(idx int, bean interface{}) error {
  1421. repo := bean.(*Repository)
  1422. return os.RemoveAll(filepath.Join(repo.RepoPath(), "archives"))
  1423. })
  1424. }
  1425. func gatherMissingRepoRecords() ([]*Repository, error) {
  1426. repos := make([]*Repository, 0, 10)
  1427. if err := x.Where("id > 0").Iterate(new(Repository),
  1428. func(idx int, bean interface{}) error {
  1429. repo := bean.(*Repository)
  1430. if !com.IsDir(repo.RepoPath()) {
  1431. repos = append(repos, repo)
  1432. }
  1433. return nil
  1434. }); err != nil {
  1435. if err2 := CreateRepositoryNotice(fmt.Sprintf("gatherMissingRepoRecords: %v", err)); err2 != nil {
  1436. return nil, fmt.Errorf("CreateRepositoryNotice: %v", err)
  1437. }
  1438. }
  1439. return repos, nil
  1440. }
  1441. // DeleteMissingRepositories deletes all repository records that lost Git files.
  1442. func DeleteMissingRepositories() error {
  1443. repos, err := gatherMissingRepoRecords()
  1444. if err != nil {
  1445. return fmt.Errorf("gatherMissingRepoRecords: %v", err)
  1446. }
  1447. if len(repos) == 0 {
  1448. return nil
  1449. }
  1450. for _, repo := range repos {
  1451. log.Trace("Deleting %d/%d...", repo.OwnerID, repo.ID)
  1452. if err := DeleteRepository(repo.OwnerID, repo.ID); err != nil {
  1453. if err2 := CreateRepositoryNotice(fmt.Sprintf("DeleteRepository [%d]: %v", repo.ID, err)); err2 != nil {
  1454. return fmt.Errorf("CreateRepositoryNotice: %v", err)
  1455. }
  1456. }
  1457. }
  1458. return nil
  1459. }
  1460. // ReinitMissingRepositories reinitializes all repository records that lost Git files.
  1461. func ReinitMissingRepositories() error {
  1462. repos, err := gatherMissingRepoRecords()
  1463. if err != nil {
  1464. return fmt.Errorf("gatherMissingRepoRecords: %v", err)
  1465. }
  1466. if len(repos) == 0 {
  1467. return nil
  1468. }
  1469. for _, repo := range repos {
  1470. log.Trace("Initializing %d/%d...", repo.OwnerID, repo.ID)
  1471. if err := git.InitRepository(repo.RepoPath(), true); err != nil {
  1472. if err2 := CreateRepositoryNotice(fmt.Sprintf("InitRepository [%d]: %v", repo.ID, err)); err2 != nil {
  1473. return fmt.Errorf("CreateRepositoryNotice: %v", err)
  1474. }
  1475. }
  1476. }
  1477. return nil
  1478. }
  1479. // RewriteRepositoryUpdateHook rewrites all repositories' update hook.
  1480. func RewriteRepositoryUpdateHook() error {
  1481. return x.Where("id > 0").Iterate(new(Repository),
  1482. func(idx int, bean interface{}) error {
  1483. repo := bean.(*Repository)
  1484. return createUpdateHook(repo.RepoPath())
  1485. })
  1486. }
  1487. // Prevent duplicate running tasks.
  1488. var taskStatusTable = sync.NewStatusTable()
  1489. const (
  1490. _MIRROR_UPDATE = "mirror_update"
  1491. _GIT_FSCK = "git_fsck"
  1492. _CHECK_REPOs = "check_repos"
  1493. )
  1494. // MirrorUpdate checks and updates mirror repositories.
  1495. func MirrorUpdate() {
  1496. if taskStatusTable.IsRunning(_MIRROR_UPDATE) {
  1497. return
  1498. }
  1499. taskStatusTable.Start(_MIRROR_UPDATE)
  1500. defer taskStatusTable.Stop(_MIRROR_UPDATE)
  1501. log.Trace("Doing: MirrorUpdate")
  1502. mirrors := make([]*Mirror, 0, 10)
  1503. if err := x.Where("next_update_unix<=?", time.Now().Unix()).Iterate(new(Mirror), func(idx int, bean interface{}) error {
  1504. m := bean.(*Mirror)
  1505. if m.Repo == nil {
  1506. log.Error(4, "Disconnected mirror repository found: %d", m.ID)
  1507. return nil
  1508. }
  1509. repoPath := m.Repo.RepoPath()
  1510. wikiPath := m.Repo.WikiPath()
  1511. timeout := time.Duration(setting.Git.Timeout.Mirror) * time.Second
  1512. gitArgs := []string{"remote", "update"}
  1513. if m.EnablePrune {
  1514. gitArgs = append(gitArgs, "--prune")
  1515. }
  1516. if _, stderr, err := process.ExecDir(
  1517. timeout, repoPath, fmt.Sprintf("MirrorUpdate: %s", repoPath),
  1518. "git", gitArgs...); err != nil {
  1519. desc := fmt.Sprintf("Fail to update mirror repository(%s): %s", repoPath, stderr)
  1520. log.Error(4, desc)
  1521. if err = CreateRepositoryNotice(desc); err != nil {
  1522. log.Error(4, "CreateRepositoryNotice: %v", err)
  1523. }
  1524. return nil
  1525. }
  1526. if m.Repo.HasWiki() {
  1527. if _, stderr, err := process.ExecDir(
  1528. timeout, wikiPath, fmt.Sprintf("MirrorUpdate: %s", wikiPath),
  1529. "git", "remote", "update", "--prune"); err != nil {
  1530. desc := fmt.Sprintf("Fail to update mirror wiki repository(%s): %s", wikiPath, stderr)
  1531. log.Error(4, desc)
  1532. if err = CreateRepositoryNotice(desc); err != nil {
  1533. log.Error(4, "CreateRepositoryNotice: %v", err)
  1534. }
  1535. return nil
  1536. }
  1537. }
  1538. m.NextUpdate = time.Now().Add(time.Duration(m.Interval) * time.Hour)
  1539. mirrors = append(mirrors, m)
  1540. return nil
  1541. }); err != nil {
  1542. log.Error(4, "MirrorUpdate: %v", err)
  1543. }
  1544. for i := range mirrors {
  1545. if err := UpdateMirror(mirrors[i]); err != nil {
  1546. log.Error(4, "UpdateMirror[%d]: %v", mirrors[i].ID, err)
  1547. }
  1548. }
  1549. }
  1550. // GitFsck calls 'git fsck' to check repository health.
  1551. func GitFsck() {
  1552. if taskStatusTable.IsRunning(_GIT_FSCK) {
  1553. return
  1554. }
  1555. taskStatusTable.Start(_GIT_FSCK)
  1556. defer taskStatusTable.Stop(_GIT_FSCK)
  1557. log.Trace("Doing: GitFsck")
  1558. if err := x.Where("id>0").Iterate(new(Repository),
  1559. func(idx int, bean interface{}) error {
  1560. repo := bean.(*Repository)
  1561. repoPath := repo.RepoPath()
  1562. if err := git.Fsck(repoPath, setting.Cron.RepoHealthCheck.Timeout, setting.Cron.RepoHealthCheck.Args...); err != nil {
  1563. desc := fmt.Sprintf("Fail to health check repository (%s): %v", repoPath, err)
  1564. log.Warn(desc)
  1565. if err = CreateRepositoryNotice(desc); err != nil {
  1566. log.Error(4, "CreateRepositoryNotice: %v", err)
  1567. }
  1568. }
  1569. return nil
  1570. }); err != nil {
  1571. log.Error(4, "GitFsck: %v", err)
  1572. }
  1573. }
  1574. func GitGcRepos() error {
  1575. args := append([]string{"gc"}, setting.Git.GCArgs...)
  1576. return x.Where("id > 0").Iterate(new(Repository),
  1577. func(idx int, bean interface{}) error {
  1578. repo := bean.(*Repository)
  1579. if err := repo.GetOwner(); err != nil {
  1580. return err
  1581. }
  1582. _, stderr, err := process.ExecDir(
  1583. time.Duration(setting.Git.Timeout.GC)*time.Second,
  1584. RepoPath(repo.Owner.Name, repo.Name), "Repository garbage collection",
  1585. "git", args...)
  1586. if err != nil {
  1587. return fmt.Errorf("%v: %v", err, stderr)
  1588. }
  1589. return nil
  1590. })
  1591. }
  1592. type repoChecker struct {
  1593. querySQL, correctSQL string
  1594. desc string
  1595. }
  1596. func repoStatsCheck(checker *repoChecker) {
  1597. results, err := x.Query(checker.querySQL)
  1598. if err != nil {
  1599. log.Error(4, "Select %s: %v", checker.desc, err)
  1600. return
  1601. }
  1602. for _, result := range results {
  1603. id := com.StrTo(result["id"]).MustInt64()
  1604. log.Trace("Updating %s: %d", checker.desc, id)
  1605. _, err = x.Exec(checker.correctSQL, id, id)
  1606. if err != nil {
  1607. log.Error(4, "Update %s[%d]: %v", checker.desc, id, err)
  1608. }
  1609. }
  1610. }
  1611. func CheckRepoStats() {
  1612. if taskStatusTable.IsRunning(_CHECK_REPOs) {
  1613. return
  1614. }
  1615. taskStatusTable.Start(_CHECK_REPOs)
  1616. defer taskStatusTable.Stop(_CHECK_REPOs)
  1617. log.Trace("Doing: CheckRepoStats")
  1618. checkers := []*repoChecker{
  1619. // Repository.NumWatches
  1620. {
  1621. "SELECT repo.id FROM `repository` repo WHERE repo.num_watches!=(SELECT COUNT(*) FROM `watch` WHERE repo_id=repo.id)",
  1622. "UPDATE `repository` SET num_watches=(SELECT COUNT(*) FROM `watch` WHERE repo_id=?) WHERE id=?",
  1623. "repository count 'num_watches'",
  1624. },
  1625. // Repository.NumStars
  1626. {
  1627. "SELECT repo.id FROM `repository` repo WHERE repo.num_stars!=(SELECT COUNT(*) FROM `star` WHERE repo_id=repo.id)",
  1628. "UPDATE `repository` SET num_stars=(SELECT COUNT(*) FROM `star` WHERE repo_id=?) WHERE id=?",
  1629. "repository count 'num_stars'",
  1630. },
  1631. // Label.NumIssues
  1632. {
  1633. "SELECT label.id FROM `label` WHERE label.num_issues!=(SELECT COUNT(*) FROM `issue_label` WHERE label_id=label.id)",
  1634. "UPDATE `label` SET num_issues=(SELECT COUNT(*) FROM `issue_label` WHERE label_id=?) WHERE id=?",
  1635. "label count 'num_issues'",
  1636. },
  1637. // User.NumRepos
  1638. {
  1639. "SELECT `user`.id FROM `user` WHERE `user`.num_repos!=(SELECT COUNT(*) FROM `repository` WHERE owner_id=`user`.id)",
  1640. "UPDATE `user` SET num_repos=(SELECT COUNT(*) FROM `repository` WHERE owner_id=?) WHERE id=?",
  1641. "user count 'num_repos'",
  1642. },
  1643. // Issue.NumComments
  1644. {
  1645. "SELECT `issue`.id FROM `issue` WHERE `issue`.num_comments!=(SELECT COUNT(*) FROM `comment` WHERE issue_id=`issue`.id AND type=0)",
  1646. "UPDATE `issue` SET num_comments=(SELECT COUNT(*) FROM `comment` WHERE issue_id=? AND type=0) WHERE id=?",
  1647. "issue count 'num_comments'",
  1648. },
  1649. }
  1650. for i := range checkers {
  1651. repoStatsCheck(checkers[i])
  1652. }
  1653. // ***** START: Repository.NumClosedIssues *****
  1654. desc := "repository count 'num_closed_issues'"
  1655. results, err := x.Query("SELECT repo.id FROM `repository` repo WHERE repo.num_closed_issues!=(SELECT COUNT(*) FROM `issue` WHERE repo_id=repo.id AND is_closed=? AND is_pull=?)", true, false)
  1656. if err != nil {
  1657. log.Error(4, "Select %s: %v", desc, err)
  1658. } else {
  1659. for _, result := range results {
  1660. id := com.StrTo(result["id"]).MustInt64()
  1661. log.Trace("Updating %s: %d", desc, id)
  1662. _, err = x.Exec("UPDATE `repository` SET num_closed_issues=(SELECT COUNT(*) FROM `issue` WHERE repo_id=? AND is_closed=? AND is_pull=?) WHERE id=?", id, true, false, id)
  1663. if err != nil {
  1664. log.Error(4, "Update %s[%d]: %v", desc, id, err)
  1665. }
  1666. }
  1667. }
  1668. // ***** END: Repository.NumClosedIssues *****
  1669. // FIXME: use checker when stop supporting old fork repo format.
  1670. // ***** START: Repository.NumForks *****
  1671. results, err = x.Query("SELECT repo.id FROM `repository` repo WHERE repo.num_forks!=(SELECT COUNT(*) FROM `repository` WHERE fork_id=repo.id)")
  1672. if err != nil {
  1673. log.Error(4, "Select repository count 'num_forks': %v", err)
  1674. } else {
  1675. for _, result := range results {
  1676. id := com.StrTo(result["id"]).MustInt64()
  1677. log.Trace("Updating repository count 'num_forks': %d", id)
  1678. repo, err := GetRepositoryByID(id)
  1679. if err != nil {
  1680. log.Error(4, "GetRepositoryByID[%d]: %v", id, err)
  1681. continue
  1682. }
  1683. rawResult, err := x.Query("SELECT COUNT(*) FROM `repository` WHERE fork_id=?", repo.ID)
  1684. if err != nil {
  1685. log.Error(4, "Select count of forks[%d]: %v", repo.ID, err)
  1686. continue
  1687. }
  1688. repo.NumForks = int(parseCountResult(rawResult))
  1689. if err = UpdateRepository(repo, false); err != nil {
  1690. log.Error(4, "UpdateRepository[%d]: %v", id, err)
  1691. continue
  1692. }
  1693. }
  1694. }
  1695. // ***** END: Repository.NumForks *****
  1696. }
  1697. type RepositoryList []*Repository
  1698. func (repos RepositoryList) loadAttributes(e Engine) error {
  1699. if len(repos) == 0 {
  1700. return nil
  1701. }
  1702. // Load owners.
  1703. set := make(map[int64]*User)
  1704. for i := range repos {
  1705. set[repos[i].OwnerID] = nil
  1706. }
  1707. userIDs := make([]int64, 0, len(set))
  1708. for userID := range set {
  1709. userIDs = append(userIDs, userID)
  1710. }
  1711. users := make([]*User, 0, len(userIDs))
  1712. if err := e.Where("id > 0").In("id", userIDs).Find(&users); err != nil {
  1713. return fmt.Errorf("find users: %v", err)
  1714. }
  1715. for i := range users {
  1716. set[users[i].ID] = users[i]
  1717. }
  1718. for i := range repos {
  1719. repos[i].Owner = set[repos[i].OwnerID]
  1720. }
  1721. return nil
  1722. }
  1723. func (repos RepositoryList) LoadAttributes() error {
  1724. return repos.loadAttributes(x)
  1725. }
  1726. type MirrorRepositoryList []*Repository
  1727. func (repos MirrorRepositoryList) loadAttributes(e Engine) error {
  1728. if len(repos) == 0 {
  1729. return nil
  1730. }
  1731. // Load mirrors.
  1732. repoIDs := make([]int64, 0, len(repos))
  1733. for i := range repos {
  1734. if !repos[i].IsMirror {
  1735. continue
  1736. }
  1737. repoIDs = append(repoIDs, repos[i].ID)
  1738. }
  1739. mirrors := make([]*Mirror, 0, len(repoIDs))
  1740. if err := e.Where("id > 0").In("repo_id", repoIDs).Find(&mirrors); err != nil {
  1741. return fmt.Errorf("find mirrors: %v", err)
  1742. }
  1743. set := make(map[int64]*Mirror)
  1744. for i := range mirrors {
  1745. set[mirrors[i].RepoID] = mirrors[i]
  1746. }
  1747. for i := range repos {
  1748. repos[i].Mirror = set[repos[i].ID]
  1749. }
  1750. return nil
  1751. }
  1752. func (repos MirrorRepositoryList) LoadAttributes() error {
  1753. return repos.loadAttributes(x)
  1754. }
  1755. // __ __ __ .__
  1756. // / \ / \_____ _/ |_ ____ | |__
  1757. // \ \/\/ /\__ \\ __\/ ___\| | \
  1758. // \ / / __ \| | \ \___| Y \
  1759. // \__/\ / (____ /__| \___ >___| /
  1760. // \/ \/ \/ \/
  1761. // Watch is connection request for receiving repository notification.
  1762. type Watch struct {
  1763. ID int64 `xorm:"pk autoincr"`
  1764. UserID int64 `xorm:"UNIQUE(watch)"`
  1765. RepoID int64 `xorm:"UNIQUE(watch)"`
  1766. }
  1767. func isWatching(e Engine, userID, repoID int64) bool {
  1768. has, _ := e.Get(&Watch{0, userID, repoID})
  1769. return has
  1770. }
  1771. // IsWatching checks if user has watched given repository.
  1772. func IsWatching(userID, repoID int64) bool {
  1773. return isWatching(x, userID, repoID)
  1774. }
  1775. func watchRepo(e Engine, userID, repoID int64, watch bool) (err error) {
  1776. if watch {
  1777. if isWatching(e, userID, repoID) {
  1778. return nil
  1779. }
  1780. if _, err = e.Insert(&Watch{RepoID: repoID, UserID: userID}); err != nil {
  1781. return err
  1782. }
  1783. _, err = e.Exec("UPDATE `repository` SET num_watches = num_watches + 1 WHERE id = ?", repoID)
  1784. } else {
  1785. if !isWatching(e, userID, repoID) {
  1786. return nil
  1787. }
  1788. if _, err = e.Delete(&Watch{0, userID, repoID}); err != nil {
  1789. return err
  1790. }
  1791. _, err = e.Exec("UPDATE `repository` SET num_watches = num_watches - 1 WHERE id = ?", repoID)
  1792. }
  1793. return err
  1794. }
  1795. // Watch or unwatch repository.
  1796. func WatchRepo(userID, repoID int64, watch bool) (err error) {
  1797. return watchRepo(x, userID, repoID, watch)
  1798. }
  1799. func getWatchers(e Engine, repoID int64) ([]*Watch, error) {
  1800. watches := make([]*Watch, 0, 10)
  1801. return watches, e.Find(&watches, &Watch{RepoID: repoID})
  1802. }
  1803. // GetWatchers returns all watchers of given repository.
  1804. func GetWatchers(repoID int64) ([]*Watch, error) {
  1805. return getWatchers(x, repoID)
  1806. }
  1807. // Repository.GetWatchers returns range of users watching given repository.
  1808. func (repo *Repository) GetWatchers(page int) ([]*User, error) {
  1809. users := make([]*User, 0, ItemsPerPage)
  1810. sess := x.Limit(ItemsPerPage, (page-1)*ItemsPerPage).Where("watch.repo_id=?", repo.ID)
  1811. if setting.UsePostgreSQL {
  1812. sess = sess.Join("LEFT", "watch", `"user".id=watch.user_id`)
  1813. } else {
  1814. sess = sess.Join("LEFT", "watch", "user.id=watch.user_id")
  1815. }
  1816. return users, sess.Find(&users)
  1817. }
  1818. func notifyWatchers(e Engine, act *Action) error {
  1819. // Add feeds for user self and all watchers.
  1820. watches, err := getWatchers(e, act.RepoID)
  1821. if err != nil {
  1822. return fmt.Errorf("get watchers: %v", err)
  1823. }
  1824. // Add feed for actioner.
  1825. act.UserID = act.ActUserID
  1826. if _, err = e.InsertOne(act); err != nil {
  1827. return fmt.Errorf("insert new actioner: %v", err)
  1828. }
  1829. for i := range watches {
  1830. if act.ActUserID == watches[i].UserID {
  1831. continue
  1832. }
  1833. act.ID = 0
  1834. act.UserID = watches[i].UserID
  1835. if _, err = e.InsertOne(act); err != nil {
  1836. return fmt.Errorf("insert new action: %v", err)
  1837. }
  1838. }
  1839. return nil
  1840. }
  1841. // NotifyWatchers creates batch of actions for every watcher.
  1842. func NotifyWatchers(act *Action) error {
  1843. return notifyWatchers(x, act)
  1844. }
  1845. // _________ __
  1846. // / _____// |______ _______
  1847. // \_____ \\ __\__ \\_ __ \
  1848. // / \| | / __ \| | \/
  1849. // /_______ /|__| (____ /__|
  1850. // \/ \/
  1851. type Star struct {
  1852. ID int64 `xorm:"pk autoincr"`
  1853. UID int64 `xorm:"UNIQUE(s)"`
  1854. RepoID int64 `xorm:"UNIQUE(s)"`
  1855. }
  1856. // Star or unstar repository.
  1857. func StarRepo(userID, repoID int64, star bool) (err error) {
  1858. if star {
  1859. if IsStaring(userID, repoID) {
  1860. return nil
  1861. }
  1862. if _, err = x.Insert(&Star{UID: userID, RepoID: repoID}); err != nil {
  1863. return err
  1864. } else if _, err = x.Exec("UPDATE `repository` SET num_stars = num_stars + 1 WHERE id = ?", repoID); err != nil {
  1865. return err
  1866. }
  1867. _, err = x.Exec("UPDATE `user` SET num_stars = num_stars + 1 WHERE id = ?", userID)
  1868. } else {
  1869. if !IsStaring(userID, repoID) {
  1870. return nil
  1871. }
  1872. if _, err = x.Delete(&Star{0, userID, repoID}); err != nil {
  1873. return err
  1874. } else if _, err = x.Exec("UPDATE `repository` SET num_stars = num_stars - 1 WHERE id = ?", repoID); err != nil {
  1875. return err
  1876. }
  1877. _, err = x.Exec("UPDATE `user` SET num_stars = num_stars - 1 WHERE id = ?", userID)
  1878. }
  1879. return err
  1880. }
  1881. // IsStaring checks if user has starred given repository.
  1882. func IsStaring(userID, repoID int64) bool {
  1883. has, _ := x.Get(&Star{0, userID, repoID})
  1884. return has
  1885. }
  1886. func (repo *Repository) GetStargazers(page int) ([]*User, error) {
  1887. users := make([]*User, 0, ItemsPerPage)
  1888. sess := x.Limit(ItemsPerPage, (page-1)*ItemsPerPage).Where("star.repo_id=?", repo.ID)
  1889. if setting.UsePostgreSQL {
  1890. sess = sess.Join("LEFT", "star", `"user".id=star.uid`)
  1891. } else {
  1892. sess = sess.Join("LEFT", "star", "user.id=star.uid")
  1893. }
  1894. return users, sess.Find(&users)
  1895. }
  1896. // ___________ __
  1897. // \_ _____/__________| | __
  1898. // | __)/ _ \_ __ \ |/ /
  1899. // | \( <_> ) | \/ <
  1900. // \___ / \____/|__| |__|_ \
  1901. // \/ \/
  1902. // HasForkedRepo checks if given user has already forked a repository with given ID.
  1903. func HasForkedRepo(ownerID, repoID int64) (*Repository, bool) {
  1904. repo := new(Repository)
  1905. has, _ := x.Where("owner_id=? AND fork_id=?", ownerID, repoID).Get(repo)
  1906. return repo, has
  1907. }
  1908. func ForkRepository(u *User, oldRepo *Repository, name, desc string) (_ *Repository, err error) {
  1909. repo := &Repository{
  1910. OwnerID: u.ID,
  1911. Owner: u,
  1912. Name: name,
  1913. LowerName: strings.ToLower(name),
  1914. Description: desc,
  1915. DefaultBranch: oldRepo.DefaultBranch,
  1916. IsPrivate: oldRepo.IsPrivate,
  1917. IsFork: true,
  1918. ForkID: oldRepo.ID,
  1919. }
  1920. sess := x.NewSession()
  1921. defer sessionRelease(sess)
  1922. if err = sess.Begin(); err != nil {
  1923. return nil, err
  1924. }
  1925. if err = createRepository(sess, u, repo); err != nil {
  1926. return nil, err
  1927. }
  1928. if _, err = sess.Exec("UPDATE `repository` SET num_forks=num_forks+1 WHERE id=?", oldRepo.ID); err != nil {
  1929. return nil, err
  1930. }
  1931. repoPath := RepoPath(u.Name, repo.Name)
  1932. _, stderr, err := process.ExecTimeout(10*time.Minute,
  1933. fmt.Sprintf("ForkRepository(git clone): %s/%s", u.Name, repo.Name),
  1934. "git", "clone", "--bare", oldRepo.RepoPath(), repoPath)
  1935. if err != nil {
  1936. return nil, fmt.Errorf("git clone: %v", stderr)
  1937. }
  1938. _, stderr, err = process.ExecDir(-1,
  1939. repoPath, fmt.Sprintf("ForkRepository(git update-server-info): %s", repoPath),
  1940. "git", "update-server-info")
  1941. if err != nil {
  1942. return nil, fmt.Errorf("git update-server-info: %v", err)
  1943. }
  1944. if err = createUpdateHook(repoPath); err != nil {
  1945. return nil, fmt.Errorf("createUpdateHook: %v", err)
  1946. }
  1947. return repo, sess.Commit()
  1948. }
  1949. func (repo *Repository) GetForks() ([]*Repository, error) {
  1950. forks := make([]*Repository, 0, repo.NumForks)
  1951. return forks, x.Find(&forks, &Repository{ForkID: repo.ID})
  1952. }
  1953. // __________ .__
  1954. // \______ \____________ ____ ____ | |__
  1955. // | | _/\_ __ \__ \ / \_/ ___\| | \
  1956. // | | \ | | \// __ \| | \ \___| Y \
  1957. // |______ / |__| (____ /___| /\___ >___| /
  1958. // \/ \/ \/ \/ \/
  1959. //
  1960. func (repo *Repository) CreateNewBranch(doer *User, oldBranchName, branchName string) (err error) {
  1961. repoWorkingPool.CheckIn(com.ToStr(repo.ID))
  1962. defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))
  1963. localPath := repo.LocalCopyPath()
  1964. if err = discardLocalRepoBranchChanges(localPath, oldBranchName); err != nil {
  1965. return fmt.Errorf("discardLocalRepoChanges: %v", err)
  1966. } else if err = repo.UpdateLocalCopyBranch(oldBranchName); err != nil {
  1967. return fmt.Errorf("UpdateLocalCopyBranch: %v", err)
  1968. }
  1969. if err = repo.CheckoutNewBranch(oldBranchName, branchName); err != nil {
  1970. return fmt.Errorf("CreateNewBranch: %v", err)
  1971. }
  1972. if err = git.Push(localPath, "origin", branchName); err != nil {
  1973. return fmt.Errorf("Push: %v", err)
  1974. }
  1975. return nil
  1976. }