File: diff-view.vala

package info (click to toggle)
gitg 41-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 18,876 kB
  • sloc: ansic: 1,636; ruby: 1,445; sh: 314; python: 261; xml: 57; makefile: 15
file content (133 lines) | stat: -rw-r--r-- 2,331 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
class TestDiffView
{
	public static int main(string[] args)
	{
		Gtk.init(ref args);

		try
		{
			Gitg.init();
		}
		catch (Error e)
		{
			stderr.printf("Failed to initialize ggit: %s\n", e.message);
			return 1;
		}

		if (Environment.get_variable("GITG_GTK_DIFF_VIEW_DEBUG") != "local" && args.length > 1 && args[1] == "--local")
		{
			// Launch in local mode
			var path = File.new_for_path(args[0]);
			var gtk = path.get_parent().get_parent().get_parent().get_child("libgitg");

			var rargs = args;

			rargs[0] = "../tests/diff-view";

			for (var i = 1; i < rargs.length - 1; ++i)
			{
				rargs[i] = rargs[i + 1];
			}

			int status;

			var sliced = rargs[0:(rargs.length - 1)];

			var env = Environ.get();
			env += "GITG_GTK_DIFF_VIEW_DEBUG=local";

			try
			{
				Process.spawn_sync(gtk.get_path(),
				                   sliced,
				                   env,
				                   0,
				                   null,
				                   null,
				                   null,
				                   out status);
			}
			catch (Error err)
			{
				stderr.printf("Error while spawning local version: %s\n", err.message);
				return 1;
			}

			return status;
		}

		var inipath = ".";

		if (args.length > 1)
		{
			inipath = args[1];
		}

		File repopath;
		Ggit.Repository repo;

		try
		{
			repopath = Ggit.Repository.discover(File.new_for_commandline_arg(inipath));
			repo = Ggit.Repository.open(repopath);
		}
		catch
		{
			stderr.printf("The specified path is not a git repository: %s\n", inipath);
			return 1;
		}

		Gitg.Commit commit;

		if (args.length > 2)
		{
			try
			{
				commit = repo.revparse(args[2]) as Gitg.Commit;
			}
			catch
			{
				stderr.printf("Failed to parse `%s' as a commit.\n", args[2]);
				return 1;
			}
		}
		else
		{
			try
			{
				var head = repo.get_head();
				commit = head.lookup() as Gitg.Commit;
			}
			catch
			{
				stderr.printf("The repository does not have a current HEAD\n");
				return 1;
			}
		}

		var wnd = new Gtk.Window();
		wnd.set_default_size(800, 600);

		var sw = new Gtk.ScrolledWindow(null, null);
		sw.show();

		var v = new Gitg.DiffView();
		v.show();
		sw.add(v);

		v.commit = commit;

		wnd.delete_event.connect((w, ev) => {
			Gtk.main_quit();
			return true;
		});

		wnd.add(sw);
		wnd.show();

		Gtk.main();
		return 0;
	}
}

// vi:ts=4